0.4.5 • Published 10 years ago

word-cataloguer v0.4.5

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

word-cataloguer

accepts a string and returns an array containing objects corresponding to each unique word

Build Status

Install

$ npm install --save word-cataloguer

Usage

const wordCataloguer = require('word-cataloguer');

wordCataloguer('This module is really, really cool.');
/*
[{word: 'really', count: 2},
{word: 'this', count: 1},
{word: 'module', count: 1},
{word: 'is', count: 1},
{word: 'cool', count: 1}
]
*/

Options

case-sensitive {caseSensitive: true}

By default all words are returned lower-case. Implement case-sensitive sorting with the following syntax:

wordCataloguer('Keep tHese biG, bIg GUY!', {caseSensitive: true});
/*
[
{word: 'Keep', count: 1},
{word: 'tHese', count: 1},
{word: 'biG', count: 1},
{word: 'bIg', count: 1},
{word: 'GUY', count: 1}
]
*/

{order: 'asc' || 'alpha'}

By default the array returned contains objects sorted by word-frequency in descending order. Return the objects in ascending order with the following syntax:

wordCataloguer('BOB SALLY JOE JOE JOHN JOE BOB!!!', {order: 'asc'});
/*
[
{word: 'sally', count: 1},
{word: 'john', count: 1},
{word: 'bob', count: 2},
{word: 'joe', count: 3}
]
*/

Alphabetical sorting is also supported:

wordCataloguer('d a b l f e'), {order: 'alpha'};
/*
[
{word: a, count 1},
{word: b, count 1},
{word: d, count 1},
{word: e, count 1},
{word: f, count 1},
{word: l, count 1},
]
*/

{compact: true}

A more compact output is also available:

wordCataloguer('This is much, much smaller.', {order: 'asc', compact: true});
/*
[{w: 'This', c: '1'},
{w: 'is', c: '1'},
{w: 'smaller', c: 1},
{w: 'much', c: 2}]
*/

notes:

Strings accepted by this module are stripped of punctuation and only a handful of symbols. Reference remove-punctuation for a list of symbols included in the removal process.

License

MIT © Christopher Howard

0.4.5

10 years ago

0.4.4

10 years ago

0.4.3

10 years ago

0.4.2

10 years ago

0.4.1

10 years ago

0.4.0

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.0.1

10 years ago

0.0.0

10 years ago