1.0.3 • Published 5 years ago
@burntcoffee/count-substring v1.0.3
Count Substring
A small library that counts the number of occurrences of a substring in a string.
Install
$ npm i @burntcoffee/count-substringUsage
Typescript
import countSubstring from '@burntcoffee/count-substring';
countSubstring('se', 'She sells seashells by the sea shore.');
//-> 3
countSubstring('se', 'She sells seashells by the sea shore.', 0, 36, true);
//-> { count: 3, positions: [ 4, 10, 27 ] }
countSubstring('se', 'She sells seashells by the sea shore.', 9, 20);
//-> 1Javascript
const countSubstring = require('@burntcoffee/count-substring');
countSubstring('se', 'She sells seashells by the sea shore.');
//-> 3
countSubstring('se', 'She sells seashells by the sea shore.', 0, 36, true);
//-> { count: 3, positions: [ 4, 10, 27 ] }
countSubstring('se', 'She sells seashells by the sea shore.', 9, 20);
//-> 1Count String Method:
function countSubstring(subString: string, str: string, start?: number, end?: number, returnPositions?: boolean): number | PositionAndCountResult;The method returns a PositionsAndCountResult if the argument returnPosition is true. Otherwise it returns the number of matches in the string. The parameters start and end specify were the function should start and stop searching for matches.