/OcuCount.JS

A tiny ( 3 KB ) NodeJS module to perform word counts on single or arrays of strings.

Primary LanguageJavaScriptMIT LicenseMIT

OcuCount

A tiny NodeJS module to perform wordcounts on single or arrays of strings.

npm npm

#Installation Installation is very simple due to OcuCount being on NPM. Simply type: npm install ocucount from a console in the project directory then add var ocucount = require('ocucount'); to the top of your project file.

#Usage Usage of OcuCount is fairly simple. It has as few functions as possible to keep the size down and ease of use high.

##For a single strings For single strings simply use the following function:

var wordcount = ocucount.count('What are you doing my friend? you are a good friend');

Simply replace the test string with the string you want to perform the wordcount on. In this example, wordcount would be the following:

[
    word { word: 'what', count: 1 },
    word { word: 'are', count: 2 },
    word { word: 'you', count: 2 },
    word { word: 'doing', count: 1 },
    word { word: 'my', count: 1 },
    word { word: 'friend', count: 2 },
    word { word: 'a', count: 1 },
    word { word: 'good', count: 1 } 
]

##For multiple strings OcuCount can also be used on arrays of stings. For example:

var wordcount = ocucount.count(['What are you doing my friend?','You are a good friend.','But I love you!']);

In this example, wordcount would be:

[
    word { word: 'what', count: 1 },
    word { word: 'are', count: 2 },
    word { word: 'you', count: 3 },
    word { word: 'doing', count: 1 },
    word { word: 'my', count: 1 },
    word { word: 'friend', count: 2 },
    word { word: 'a', count: 1 },
    word { word: 'good', count: 1 },
    word { word: 'but', count: 1 },
    word { word: 'i', count: 1 },
    word { word: 'love', count: 1 }
]

##Sorting Ocucount word lists Ocucount does not default to sorting your lists of words. To do that, simply call the following:

//create an OcuCount word list
var wordcount = ocucount.count(['What are you doing my friend?','You are a good friend.','But I love you!']);
//sort it
wordcount = ocucount.sortWords(wordcount);

This will return the list generated by the other main Ocucount function but sorted from lowest to highest usage.


license


Follow me on twitter (@MVD_Vandie) or on github in order to keep track of my projects and releases.

Twitter Follow GitHub followers

Enjoy. :D