You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{bigram,trigram,nGram}from'n-gram'bigram('n-gram')// ['n-', '-g', 'gr', 'ra', 'am']nGram(2)('n-gram')// ['n-', '-g', 'gr', 'ra', 'am']trigram('n-gram')// ['n-g', '-gr', 'gra', 'ram']nGram(6)('n-gram')// ['n-gram']nGram(7)('n-gram')// []// Anything with a `.length` and `.slice` works: arrays too.bigram(['alpha','bravo','charlie'])// [['alpha', 'bravo'], ['bravo', 'charlie']]
API
This package exports the identifiers nGram, bigram, and trigram.
There is no default export.
nGram(n)
Create a function that converts a given value to n-grams.
Want padding (to include partial matches)?
Use something like the following: nGram(2)(' ' + value + ' ')
bigram(value)
Shortcut for nGram(2).
trigram(value)
Shortcut for nGram(3).
Types
This package is fully typed with TypeScript.
It exports no additional types.
Compatibility
This package is at least compatible with all maintained versions of Node.js.
As of now, that is Node.js 14.14+, 16.0+, and 18.0+.
It also works in Deno and modern browsers.