words-occurrences
v1.0.2
Published
Tool for counting words occurrences in a string
Downloads
2
Readme
Words-occurrences
words-occurrences
is a zero-dependency (except Jest for testing) tool for
counting occurrences of higher than two-letter words in strings. It supports only English,
French and some (non tested) other languages with latin alphabet.
Installation
npm install words-occurrences
or
yarn add words-occurrences
Usage
const WordsOccurrencesCounter = require('words-occurrences');
const text = 'Hello I am Brian';
// the second parameter is the case sensitivity
const wordsOccurrences = new WordsOccurrencesCounter(text, false);
const numberOfBrian = wordsOccurrences.getNumberOfOccurrencesOf('brian');
// numberOfBrian = 1 since "Brian" appears only once
const numberOfI = wordsOccurrences.getNumberOfOccurrencesOf('I');
// numberOfI = 0 since "I" is less than two-letter long
Test
You can run the test suite by cloning this repo and running :
yarn install
yarn test