CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
readme.md150 linesDownload Raw Back to ccount
1# ccount2 3[![Build][build-badge]][build]4[![Coverage][coverage-badge]][coverage]5[![Downloads][downloads-badge]][downloads]6[![Size][size-badge]][size]7 8Count how often a character (or substring) is used in a string.9 10## Contents11 12*   [What is this?](#what-is-this)13*   [When should I use this?](#when-should-i-use-this)14*   [Install](#install)15*   [Use](#use)16*   [API](#api)17    *   [`ccount(value, character)`](#ccountvalue-character)18*   [Types](#types)19*   [Compatibility](#compatibility)20*   [Security](#security)21*   [Related](#related)22*   [Contribute](#contribute)23*   [License](#license)24 25## What is this?26 27This package is a small utility that helps you find how frequently a substring28occurs in another string.29 30## When should I use this?31 32I find this particularly useful when generating code, for example, when building33a string that can either be double or single quoted.34I use this utility to choose single quotes when double quotes are used more35frequently, and double quotes otherwise.36 37## Install38 39This package is [ESM only][esm].40In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:41 42```sh43npm install ccount44```45 46In Deno with [Skypack][]:47 48```js49import {ccount} from 'https://cdn.skypack.dev/ccount@2?dts'50```51 52In browsers with [Skypack][]:53 54```html55<script type="module">56  import {ccount} from 'https://cdn.skypack.dev/ccount@2?min'57</script>58```59 60## Use61 62```js63import {ccount} from 'ccount'64 65ccount('foo(bar(baz)', '(') // => 266ccount('foo(bar(baz)', ')') // => 167```68 69## API70 71This package exports the following identifier: `ccount`.72There is no default export.73 74### `ccount(value, character)`75 76Count how often a character (or substring) is used in a string.77 78###### Parameters79 80*   `value` (`string`)81    — value to search in82*   `character` (`string`)83    — character (or substring) to look for84 85###### Returns86 87`number` — number of times `character` occurred in `value`.88 89## Types90 91This package is fully typed with [TypeScript][].92 93## Compatibility94 95This package is at least compatible with all maintained versions of Node.js.96As of now, that is Node.js 12.20+, 14.14+, and 16.0+.97It also works in Deno and modern browsers.98 99## Security100 101This package is safe.102 103## Related104 105*   [`wooorm/longest-streak`](https://github.com/wooorm/longest-streak)106    — count of longest repeating streak of `character` in `value`107*   [`wooorm/direction`](https://github.com/wooorm/direction)108    — detect directionality: left-to-right, right-to-left, or neutral109 110## Contribute111 112Yes please!113See [How to Contribute to Open Source][contribute].114 115## License116 117[MIT][license] © [Titus Wormer][author]118 119<!-- Definitions -->120 121[build-badge]: https://github.com/wooorm/ccount/workflows/main/badge.svg122 123[build]: https://github.com/wooorm/ccount/actions124 125[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/ccount.svg126 127[coverage]: https://codecov.io/github/wooorm/ccount128 129[downloads-badge]: https://img.shields.io/npm/dm/ccount.svg130 131[downloads]: https://www.npmjs.com/package/ccount132 133[size-badge]: https://img.shields.io/bundlephobia/minzip/ccount.svg134 135[size]: https://bundlephobia.com/result?p=ccount136 137[npm]: https://docs.npmjs.com/cli/install138 139[skypack]: https://www.skypack.dev140 141[license]: license142 143[author]: https://wooorm.com144 145[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c146 147[typescript]: https://www.typescriptlang.org148 149[contribute]: https://opensource.guide/how-to-contribute/150