{"id":11394,"library":"ngraminator","title":"Ngraminator","description":"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.","status":"active","version":"3.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/fergiemcdowall/ngraminator","tags":["javascript"],"install":[{"cmd":"npm install ngraminator","lang":"bash","label":"npm"},{"cmd":"yarn add ngraminator","lang":"bash","label":"yarn"},{"cmd":"pnpm add ngraminator","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM modules correctly export `ngraminator` as a named export since v3.0.1.","wrong":"import ngraminator from 'ngraminator'","symbol":"ngraminator","correct":"import { ngraminator } from 'ngraminator'"},{"note":"Since v3.0.1, CommonJS imports require destructuring as `ngraminator` is a named export, not a default export.","wrong":"const ngraminator = require('ngraminator')","symbol":"ngraminator","correct":"const { ngraminator } = require('ngraminator')"},{"note":"For UMD builds (e.g., via script tag), the global object has changed from `ngraminator` to `ngrm.ngraminator` since v3.0.1.","wrong":"// In browser script tag: ngraminator(wordArray, ngramLengthArray)","symbol":"ngrm.ngraminator","correct":"// In browser script tag: ngrm.ngraminator(wordArray, ngramLengthArray)"}],"quickstart":{"code":"import { ngraminator } from 'ngraminator';\n\nconst text = \"The quick brown fox jumps over the lazy dog\";\nconst words = text.split(' ');\n\n// Get unigrams (n=1), bigrams (n=2), and trigrams (n=3)\nconst ngrams = ngraminator(words, [1, 2, 3]);\n\nconsole.log('Generated N-grams:');\nngrams.forEach(ngram => console.log(ngram.join(' ')));\n\n// Example of specific ngram lengths and transformations\nconst str = \"mary had a little lamb it's fleece\";\nconst result = ngraminator(str.split(' '), [1, 2, 5]).map(item => item.join(' '));\n\nconsole.log('\\nSpecific N-grams and stringified output:');\nconsole.log(result);\n","lang":"javascript","description":"Demonstrates how to import `ngraminator` and generate various n-gram lengths from a string."},"warnings":[{"fix":"Update your CommonJS import statements to `const { ngraminator } = require('ngraminator')`.","message":"The CommonJS `require()` syntax changed from a default import to a named import. Previously `const ngraminator = require('ngraminator')` worked, but now it requires destructuring.","severity":"breaking","affected_versions":">=3.0.1"},{"fix":"Access the function via `ngrm.ngraminator()` instead of `ngraminator()` in your browser scripts.","message":"For 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.","severity":"breaking","affected_versions":">=3.0.1"},{"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).","message":"Version 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.","severity":"gotcha","affected_versions":">=3.0.1"},{"fix":"Upgrade to `npm install ngraminator@latest` or specifically `npm install ngraminator@^2.0.3` for v2.x series.","message":"A 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.","severity":"deprecated","affected_versions":"<2.0.3"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change your import from `const ngraminator = require('ngraminator')` to `const { ngraminator } = require('ngraminator')`.","cause":"Attempting to use `require('ngraminator')` as a direct function call in CommonJS environments since v3.0.1, where it's now a named export.","error":"TypeError: ngraminator is not a function"},{"fix":"Access the function via the `ngrm` global object: `ngrm.ngraminator(...)`.","cause":"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.","error":"ReferenceError: ngraminator is not defined"}],"ecosystem":"npm"}