Comparing version 2.0.0 to 2.0.1
/** | ||
* Get the total count of `character` in `value`. | ||
* Count how often a character (or substring) is used in a string. | ||
* | ||
* @param {any} value Content, coerced to string | ||
* @param {string} character Single character to look for | ||
* @return {number} Number of times `character` occurred in `value`. | ||
* @param {string} value | ||
* Value to search in. | ||
* @param {string} character | ||
* Character (or substring) to look for. | ||
* @return {number} | ||
* Number of times `character` occurred in `value`. | ||
*/ | ||
export function ccount(value: any, character: string): number | ||
export function ccount(value: string, character: string): number |
20
index.js
/** | ||
* Get the total count of `character` in `value`. | ||
* Count how often a character (or substring) is used in a string. | ||
* | ||
* @param {any} value Content, coerced to string | ||
* @param {string} character Single character to look for | ||
* @return {number} Number of times `character` occurred in `value`. | ||
* @param {string} value | ||
* Value to search in. | ||
* @param {string} character | ||
* Character (or substring) to look for. | ||
* @return {number} | ||
* Number of times `character` occurred in `value`. | ||
*/ | ||
export function ccount(value, character) { | ||
var source = String(value) | ||
var count = 0 | ||
var index | ||
const source = String(value) | ||
if (typeof character !== 'string') { | ||
throw new Error('Expected character') | ||
throw new TypeError('Expected character') | ||
} | ||
index = source.indexOf(character) | ||
let count = 0 | ||
let index = source.indexOf(character) | ||
@@ -19,0 +21,0 @@ while (index !== -1) { |
{ | ||
"name": "ccount", | ||
"version": "2.0.0", | ||
"description": "Count characters", | ||
"version": "2.0.1", | ||
"description": "Count how often a character (or substring) is used in a string", | ||
"license": "MIT", | ||
@@ -33,16 +33,16 @@ "keywords": [ | ||
"prettier": "^2.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"remark-cli": "^10.0.0", | ||
"remark-preset-wooorm": "^9.0.0", | ||
"rimraf": "^3.0.0", | ||
"tape": "^5.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"xo": "^0.38.0" | ||
"xo": "^0.46.0" | ||
}, | ||
"scripts": { | ||
"prepublishOnly": "npm run build && npm run format", | ||
"prebuild": "rimraf \"*.d.ts\"", | ||
"build": "tsc", | ||
"build": "rimraf \"*.d.ts\" && tsc && type-coverage", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"test-api": "node test.js", | ||
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js", | ||
"test-api": "node --conditions development test.js", | ||
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api", | ||
"test": "npm run build && npm run format && npm run test-coverage" | ||
@@ -59,8 +59,3 @@ }, | ||
"xo": { | ||
"prettier": true, | ||
"rules": { | ||
"no-var": "off", | ||
"prefer-arrow-callback": "off", | ||
"unicorn/prefer-type-error": "off" | ||
} | ||
"prettier": true | ||
}, | ||
@@ -71,3 +66,9 @@ "remarkConfig": { | ||
] | ||
}, | ||
"typeCoverage": { | ||
"atLeast": 100, | ||
"detail": true, | ||
"strict": true, | ||
"ignoreCatch": true | ||
} | ||
} |
@@ -8,11 +8,36 @@ # ccount | ||
Count characters. | ||
Count how often a character (or substring) is used in a string. | ||
## Contents | ||
* [What is this?](#what-is-this) | ||
* [When should I use this?](#when-should-i-use-this) | ||
* [Install](#install) | ||
* [Use](#use) | ||
* [API](#api) | ||
* [`ccount(value, character)`](#ccountvalue-character) | ||
* [Types](#types) | ||
* [Compatibility](#compatibility) | ||
* [Security](#security) | ||
* [Related](#related) | ||
* [Contribute](#contribute) | ||
* [License](#license) | ||
## What is this? | ||
This package is a small utility that helps you find how frequently a substring | ||
occurs in another string. | ||
## When should I use this? | ||
I find this particularly useful when generating code, for example, when building | ||
a string that can either be double or single quoted. | ||
I use this utility to choose single quotes when double quotes are used more | ||
frequently, and double quotes otherwise. | ||
## Install | ||
This package is ESM only: Node 12+ is needed to use it and it must be `import`ed | ||
instead of `require`d. | ||
This package is [ESM only][esm]. | ||
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]: | ||
[npm][]: | ||
```sh | ||
@@ -22,2 +47,16 @@ npm install ccount | ||
In Deno with [Skypack][]: | ||
```js | ||
import {ccount} from 'https://cdn.skypack.dev/ccount@2?dts' | ||
``` | ||
In browsers with [Skypack][]: | ||
```html | ||
<script type="module"> | ||
import {ccount} from 'https://cdn.skypack.dev/ccount@2?min' | ||
</script> | ||
``` | ||
## Use | ||
@@ -34,3 +73,3 @@ | ||
This package exports the following identifiers: `ccount`. | ||
This package exports the following identifier: `ccount`. | ||
There is no default export. | ||
@@ -40,13 +79,41 @@ | ||
Get the total count of `character` in `value`. | ||
Count how often a character (or substring) is used in a string. | ||
###### Parameters | ||
* `value` (`string`) — Content, coerced to string | ||
* `character` (`string`) — Single character to look for | ||
* `value` (`string`) | ||
— value to search in | ||
* `character` (`string`) | ||
— character (or substring) to look for | ||
###### Returns | ||
`number` — Number of times `character` occurred in `value`. | ||
`number` — number of times `character` occurred in `value`. | ||
## Types | ||
This package is fully typed with [TypeScript][]. | ||
## Compatibility | ||
This package is at least compatible with all maintained versions of Node.js. | ||
As of now, that is Node.js 12.20+, 14.14+, and 16.0+. | ||
It also works in Deno and modern browsers. | ||
## Security | ||
This package is safe. | ||
## Related | ||
* [`wooorm/longest-streak`](https://github.com/wooorm/longest-streak) | ||
— count of longest repeating streak of `character` in `value` | ||
* [`wooorm/direction`](https://github.com/wooorm/direction) | ||
— detect directionality: left-to-right, right-to-left, or neutral | ||
## Contribute | ||
Yes please! | ||
See [How to Contribute to Open Source][contribute]. | ||
## License | ||
@@ -76,4 +143,12 @@ | ||
[skypack]: https://www.skypack.dev | ||
[license]: license | ||
[author]: https://wooorm.com | ||
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
[typescript]: https://www.typescriptlang.org | ||
[contribute]: https://opensource.guide/how-to-contribute/ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7344
34
150
10