Registry / data / ngraminator

ngraminator

JSON →
library3.0.2jsnpmunverified

Ngraminator is a lightweight JavaScript utility designed to generate ngrams from arrays of words. It supports various module environments, including Node.js (CommonJS and ES Modules) and browsers (UMD), making it versatile for both backend and frontend text processing tasks. The current stable version is 3.0.2. The package underwent a significant architectural change in v3.0.1, migrating from webpack to Rollup for bundling, which introduced breaking changes in how the library is imported via CommonJS and accessed globally in UMD environments. Its primary differentiator is its small footprint and broad environment compatibility for generating n-grams of specified lengths from input arrays, without additional complex dependencies. It maintains a moderate release cadence, with recent updates focusing on build system improvements and module compatibility.

npm install ngraminator
INSTALL
IMPORT
SIG · NGRAMINATOR
N
ngraminator
datajavascriptv3.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ngraminator
import { ngraminator } from 'ngraminator'
import ngraminator from 'ngraminator'
ESM modules correctly export `ngraminator` as a named export since v3.0.1.
ngraminator
const { ngraminator } = require('ngraminator')
const ngraminator = require('ngraminator')
Since v3.0.1, CommonJS imports require destructuring as `ngraminator` is a named export, not a default export.
ngrm.ngraminator
// In browser script tag: ngrm.ngraminator(wordArray, ngramLengthArray)
// In browser script tag: ngraminator(wordArray, ngramLengthArray)
For UMD builds (e.g., via script tag), the global object has changed from `ngraminator` to `ngrm.ngraminator` since v3.0.1.

Demonstrates how to import `ngraminator` and generate various n-gram lengths from a string.

import { ngraminator } from 'ngraminator'; const text = "The quick brown fox jumps over the lazy dog"; const words = text.split(' '); // Get unigrams (n=1), bigrams (n=2), and trigrams (n=3) const ngrams = ngraminator(words, [1, 2, 3]); console.log('Generated N-grams:'); ngrams.forEach(ngram => console.log(ngram.join(' '))); // Example of specific ngram lengths and transformations const str = "mary had a little lamb it's fleece"; const result = ngraminator(str.split(' '), [1, 2, 5]).map(item => item.join(' ')); console.log('\nSpecific N-grams and stringified output:'); console.log(result);
Debug
Known issues
breakingThe CommonJS `require()` syntax changed from a default import to a named import. Previously `const ngraminator = require('ngraminator')` worked, but now it requires destructuring.
fix
Update your CommonJS import statements to `const { ngraminator } = require('ngraminator')`.
affects: >=3.0.1
breakingFor browser environments using the UMD build via a script tag, the global object has changed. The `ngraminator()` function is no longer directly accessible; it's now nested under a new global variable.
fix
Access the function via `ngrm.ngraminator()` instead of `ngraminator()` in your browser scripts.
affects: >=3.0.1
gotchaVersion 3.0.1 and later changed the internal bundler from webpack to Rollup and the test framework from Tape to Ava/Playwright. While not directly affecting API usage, it signifies a major internal refactor that could lead to subtle behavioral differences or impact bundling toolchains.
fix
Review your existing build processes if they interact with `ngraminator`'s internals or expect specific bundle structures (e.g., source maps, tree-shaking behavior).
affects: >=3.0.1
deprecatedA security update was released in version 2.0.3. Users on older v2.x versions should upgrade to at least 2.0.3 or preferably to the latest v3.x branch to ensure security patches are applied.
fix
Upgrade to `npm install ngraminator@latest` or specifically `npm install ngraminator@^2.0.3` for v2.x series.
affects: <2.0.3
Errors
Common errors & fixes
TypeError: ngraminator is not a function
Attempting to use `require('ngraminator')` as a direct function call in CommonJS environments since v3.0.1, where it's now a named export.
fix
Change your import from `const ngraminator = require('ngraminator')` to `const { ngraminator } = require('ngraminator')`.
ReferenceError: ngraminator is not defined
Accessing the `ngraminator` function directly in a browser environment after loading the UMD build (e.g., via `<script>`) for versions 3.0.1 and later.
fix
Access the function via the `ngrm` global object: `ngrm.ngraminator(...)`.
Upgrade
Version history
3.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
ngraminator — npm install ngraminator · libregistry