
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
Get n-grams.
This package gets you bigrams (or any n-gram, really).
You’re probably dealing with natural language, and know you need this, if you’re here!
This package is ESM only. In Node.js (version 12.20+, 14.14+, 16.0+), install with npm:
npm install n-gram
In Deno with esm.sh:
import {nGram} from 'https://esm.sh/n-gram@2'
In browsers with esm.sh:
<script type="module">
import {nGram} from 'https://esm.sh/n-gram@2?bundle'
</script>
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']]
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).
This package is fully typed with TypeScript. It exports no additional types.
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.
wooorm/franc
— natural language detectionYes please! See How to Contribute to Open Source.
This package is safe.
The 'natural' package is a general natural language processing library for Node.js. It includes a variety of NLP tools, including n-gram generation. Compared to n-gram, 'natural' offers a broader range of NLP functionalities, making it suitable for more comprehensive text processing tasks.
FAQs
Get n-grams from text
The npm package n-gram receives a total of 394,854 weekly downloads. As such, n-gram popularity was classified as popular.
We found that n-gram demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.