What is ccount?
The ccount npm package is a simple utility that counts the occurrences of a character or substring within a string. It is useful for various string analysis tasks where you need to quantify the presence of certain characters or sequences.
What are ccount's main functionalities?
Character Count
Counts the number of times a specific character appears in a string. In this example, it counts the occurrences of the character '(' in the given string.
"const ccount = require('ccount');
const count = ccount('foo(bar(baz)', '(');
console.log(count); // 2"
Substring Count
Counts the number of times a substring appears in a string. In this example, it counts the occurrences of the substring 'foo' in the given string.
"const ccount = require('ccount');
const count = ccount('foofoofoo', 'foo');
console.log(count); // 3"
Other packages similar to ccount
string-occurrence
This package offers similar functionality to ccount, allowing users to count the occurrences of a substring within a string. It differs in that it provides additional options for case sensitivity and overlapping occurrences.
occurrences
Another package that provides functionality to count the occurrences of a substring in a string. It is similar to ccount but also includes the ability to count occurrences in arrays and objects, not just strings.
ccount
Count characters.
Installation
npm:
npm install ccount
ccount is also available for bower,
component, duo,
and for AMD, CommonJS, and globals (uncompressed and
compressed).
Usage
var ccount = require('ccount');
ccount('foo(bar(baz)', '(')
ccount('foo(bar(baz)', ')')
API
ccount(value, character)
Get the total count of character
in value
.
Parameters:
value
(string
) — Content, coerced to string.character
(string
) — Single character to look for.
Returns: number
— Number of times character
occurred in value
.
Throws:
Error
— when character
is not a single character string.
License
MIT @ Titus Wormer