Package Exports
- ngraminator
- ngraminator/dist/ngraminator.cjs.js
- ngraminator/dist/ngraminator.esm.mjs
- ngraminator/dist/ngraminator.umd.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ngraminator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ngraminator
A really small ngram generator for Node.js and the browser. Check out the interactive demo.
Breaking change
How the library is now required is slightly different. For CommonJS it used to be const ngraminator = require('ngraminator'), but now it is const { ngraminator } = require('ngraminator')
And UMD used to be ngraminator(), but is now ngrm.ngraminator()
Initiation
CJS - CommonJS
const { ngraminator } = require('ngraminator')
// ngraminator(wordArray, ngramLenghtArray) availableESM - Ecmascript Modules
import { ngraminator } from 'ngraminator'
// ngraminator(wordArray, ngramLenghtArray) availableScript tag
<script src="ngraminator.umd.js"></script>
<script>
// ngrm.ngraminator(wordArray, ngramLenghtArray) available
</script>Usage
const str = "mary had a little lamb it's fleece"
// get ngrams of length 3
ngraminator(str.split(' '), [3])
// [
// ['mary', 'had', 'a'],
// ['had', 'a', 'little'],
// ['a', 'little', 'lamb'],
// ['little', 'lamb', 'it\'s'],
// ['lamb', 'it\'s', 'fleece']
// ]
// get ngrams of lengths 1 and 2
ngraminator(str.split(' '), [1, 2])
// [
// [ 'mary' ],
// [ 'had' ],
// [ 'a' ],
// [ 'little' ],
// [ 'lamb' ],
// [ 'it\'s' ],
// [ 'fleece' ],
// [ 'mary', 'had' ],
// [ 'had', 'a' ],
// [ 'a', 'little' ],
// [ 'little', 'lamb' ],
// [ 'lamb', 'it\'s' ],
// [ 'it\'s', 'fleece' ]
// ]
// get ngrams of lengths 1, 2, and 5
ngraminator(str.split(' '), [1, 2, 5])
// [
// [ 'a' ],
// [ 'a', 'little' ],
// [ 'a', 'little', 'lamb', 'it\'s', 'fleece' ],
// [ 'fleece' ],
// [ 'had' ],
// [ 'had', 'a' ],
// [ 'had', 'a', 'little', 'lamb', 'it\'s' ],
// [ 'it\'s' ],
// [ 'it\'s', 'fleece' ],
// [ 'lamb' ],
// [ 'lamb', 'it\'s' ],
// [ 'little' ],
// [ 'little', 'lamb' ],
// [ 'mary' ],
// [ 'mary', 'had' ],
// [ 'mary', 'had', 'a', 'little', 'lamb' ]
// ]
//
// get ngrams of lengths 1, 2, and 5 stringified
ngraminator(str.split(' '), [1, 2, 5]).map(item => item.join(' '))
// [
// "a",
// "a little",
// "a little lamb it's fleece",
// "fleece",
// "had",
// "had a",
// "had a little lamb it's",
// "it's",
// "it's fleece",
// "lamb",
// "lamb it's",
// "little",
// "little lamb",
// "mary",
// "mary had",
// "mary had a little lamb"
// ]
//