{"_id":"wordsninja","_rev":"5-45fb69e71dd6d86147f7c0936db6b621","name":"wordsninja","dist-tags":{"latest":"2.0.1"},"versions":{"1.0.0":{"name":"wordsninja","version":"1.0.0","keywords":["split","text","sentence","english","ninja","words","word","splitter","capitalize","camel case"],"author":{"url":"http://parsa.ws","name":"Parsa Kafi","email":"parselearn@gmail.com"},"license":"MIT","_id":"wordsninja@1.0.0","maintainers":[{"name":"parsakafi","email":"parselearn@gmail.com"}],"homepage":"https://github.com/parsakafi/wordsninja","bugs":{"url":"https://github.com/parsakafi/wordsninja/issues"},"dist":{"shasum":"526e5b293ea1fb740b747675570e8fcdc0860272","tarball":"https://registry.npmjs.org/wordsninja/-/wordsninja-1.0.0.tgz","fileCount":5,"integrity":"sha512-f9aKDZ01xCjBEVxqQ4+fbSw+Jksi0OlvWV4QeqFzX78FjwREk/7ARgk0PuKlOkxGPg1ylkTYMTcKpReMVi2z4A==","signatures":[{"sig":"MEUCIBd9p0ALu097jVDIi8SIQNhHXykUXzkegyR8XlIobq5qAiEAvH3sdOl6fzzadg8aJxbnu/4Z+87gBlBoA2ycoAsGyB8=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1111605,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdC4aJCRA9TVsSAnZWagAAseYQAIXBromwA2Ollk1mDidQ\nudNHz6CDl9iccOZyMT4QhgkMG57GFmaJkl0BhB7+iGzTPgQr4MKH4tV8rG2C\nOACN2HbdAqzW0/p04LMXeRwVHlBzBUz9DJV/CNUV3TT3WN55r8BZIbqPJkM/\n3zfq+AFmxpqGr1AVskn99yj77QHn8cMbXlQvWqXNNFQxOCVarj0a9R/pXQgy\nyEaAyh++a9iPbStwIEwfsrNn7wiVodvDNXqsXz4H4hDDjYtPsHbBm9ULlWxg\n1p2Qkdm6XHOxq3sAQkfGpc+NqX33VLzlAO9qqnrsl1TmMf1xwTndnPmP42Ls\ndAMe6lM/0xQB1g7S08HNKN9tq73f3GgKDeDhvClPkNNXu9KAYO7b/O7VMnmq\nAhT3h60K6n/sYr5GzMEeOQ9Zi7lQ/wmKjvUXIy+FRZQEIDx8hr3eTDcEfEBN\n9W3tQYwAeXd5ZXLzm4EUiTXZng0HA9zx27hkSckTirRFMVnnsdSF18iFNX3B\nQnTtC9ruGC+YqZIku7HWHUar+gEEmqEPxB3m8jfsJ7uEqRh6tYT+r/PvHpEX\nW6XPknceuTd2TX9gXwN3H4WZLARpq93Jp1nbUwOOquKabGhHkKceRSQmrgZo\nnDGrvfChrdudHr7295U1J2EVdfShx3Lcaw+WsvyHUNVC0SkGE/mXyZ9q6bca\n8t3X\r\n=yziI\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","gitHead":"d0d2cba75437527fc47c21c7a887c8b1350874a0","scripts":{},"_npmUser":{"name":"parsakafi","email":"parselearn@gmail.com"},"repository":{"url":"git+https://github.com/parsakafi/wordsninja.git","type":"git"},"_npmVersion":"6.9.0","description":"Split a English sentence without any spaces nor accents, into words.","directories":{},"_nodeVersion":"12.1.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/wordsninja_1.0.0_1561036425382_0.5326145638517168","host":"s3://npm-registry-packages"}},"1.1.0":{"name":"wordsninja","version":"1.1.0","keywords":["split","text","sentence","english","ninja","words","word","splitter","capitalize","camel case"],"author":{"url":"https://parsa.ws","name":"Parsa Kafi","email":"parselearn@gmail.com"},"license":"MIT","_id":"wordsninja@1.1.0","maintainers":[{"name":"parsakafi","email":"parselearn@gmail.com"}],"homepage":"https://parsa.ws/projects/wordsninja-js-package","bugs":{"url":"https://github.com/parsakafi/wordsninja/issues"},"dist":{"shasum":"2f50cf0647e4f24f0ce7f8bc6530819251c43113","tarball":"https://registry.npmjs.org/wordsninja/-/wordsninja-1.1.0.tgz","fileCount":6,"integrity":"sha512-cxhLZHK21P3URD+F4HNeyd4Bizqyqcrh++p/oJ7fYasCMrQhwKrmCVcasUr6UuTv6YaiZ8tESxgbzZE4yf3mfA==","signatures":[{"sig":"MEYCIQCmRZEd1RCEVgSd3fqK6U1m2Tz23n/52WSQW3+bhszgNwIhAMG28349WYxYr5oXqH8sR61FMk3XvFx8iP8OGBVTYEnT","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":1868804},"main":"index.js","gitHead":"20be9098da5418518bbde07fdf3c358e8222de0c","scripts":{},"_npmUser":{"name":"parsakafi","email":"parselearn@gmail.com"},"repository":{"url":"git+https://github.com/parsakafi/wordsninja.git","type":"git"},"_npmVersion":"11.5.2","description":"Split a English sentence without any spaces nor accents, into words.","directories":{},"_nodeVersion":"22.18.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/wordsninja_1.1.0_1755966655735_0.7865442216223777","host":"s3://npm-registry-packages-npm-production"}},"2.0.0":{"name":"wordsninja","version":"2.0.0","keywords":["split","text","sentence","english","ninja","words","word","splitter","tokenizer","tokenize","segmentation","text-segmentation","word-segmentation","wordninja","no-spaces","capitalize","camelcase","camel-case"],"author":{"url":"https://parsa.ws","name":"Parsa Kafi","email":"parselearn@gmail.com"},"license":"MIT","_id":"wordsninja@2.0.0","maintainers":[{"name":"parsakafi","email":"parselearn@gmail.com"}],"homepage":"https://parsa.ws/projects/wordsninja-js-package","bugs":{"url":"https://github.com/parsakafi/wordsninja/issues"},"dist":{"shasum":"41ee49ba5fa08323f5cd672f6463734708e45dc6","tarball":"https://registry.npmjs.org/wordsninja/-/wordsninja-2.0.0.tgz","fileCount":9,"integrity":"sha512-wY3J83tQexsw3Nc35ex9myDPDsG/ihvEZLZ1GWc8w3SiGciPphGYGd0QAmtLCqyr+WU4FgIYRBWYwp5RwtFWBA==","signatures":[{"sig":"MEUCIGhgPpqaJwWDdBXqt/h5EGDbdY8cVwBDU5+l58SbZmXcAiEAtaXX8pLMyf7ryvAJJe4PPKm8kfQTjn1D3wh03uqywIM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIQCLU1p+3W6ILlzs5sKdkPYG1MVgJitU618rPCV0j2dedgIgDIV3fyxgISkBuFjXhMf5tWoie/Z3kSLUdXedOYd1kyg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":1772101},"main":"index.js","types":"index.d.ts","module":"index.mjs","engines":{"node":">=18"},"exports":{".":{"import":{"types":"./index.d.mts","default":"./index.mjs"},"default":"./index.js","require":{"types":"./index.d.ts","default":"./index.js"}},"./package.json":"./package.json"},"gitHead":"2d905d878c58e56ffe98c8d798b4525ed4cc7d09","scripts":{"test":"node --test test/wordsninja.test.js test/robustness.test.js","bench":"node bench/bench.js","test:watch":"node --test --watch test/wordsninja.test.js test/robustness.test.js","prepublishOnly":"npm test","build:dictionary":"node scripts/build-dictionary.js"},"_npmUser":{"name":"parsakafi","email":"parselearn@gmail.com"},"repository":{"url":"git+https://github.com/parsakafi/wordsninja.git","type":"git"},"_npmVersion":"12.2.0","description":"Split an English string that has no spaces into words. Zero dependencies, offset-aware, with custom dictionaries and TypeScript types.","directories":{},"sideEffects":false,"_nodeVersion":"22.23.5","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/wordsninja_2.0.0_1795042278320_0.49705540319092567","host":"s3://npm-registry-packages-npm-production"}},"2.0.1":{"_id":"wordsninja@2.0.1","bugs":{"url":"https://github.com/parsakafi/wordsninja/issues"},"dist":{"shasum":"6fc7d50b33e05320eec5878b0ed631edb97fa588","tarball":"https://registry.npmjs.org/wordsninja/-/wordsninja-2.0.1.tgz","fileCount":10,"integrity":"sha512-bj6G6sMZIc16wZaKl5QPQvGHyK9kUCwRtzmItsDV9AYJMP3NHaAfatnKb9xBs7nnUPhV0G80dn+armeOG1nEKw==","signatures":[{"sig":"MEYCIQD/husXohrSIiD747AmuZ8tLCS7UT8Fwgz+PIT60/eyKAIhANUwkky/mffHcwTy9i9WQppbCW6AeDeTi0+ZoT7NRbbo","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIHSXuJC6o4cZaPxkID8JuQpmAGQOfuxpqQ18c+ZlLah8AiEAtH4J4mPEniLd8f0x+9xrTBKhNmyKxxqEhza1TAjfg/I="}],"unpackedSize":1905652},"main":"index.js","name":"wordsninja","types":"index.d.ts","author":{"url":"https://parsa.ws","name":"Parsa Kafi","email":"parselearn@gmail.com"},"module":"index.mjs","engines":{"node":">=18"},"exports":{".":{"import":{"types":"./index.d.mts","default":"./index.mjs"},"default":"./index.js","require":{"types":"./index.d.ts","default":"./index.js"}},"./package.json":"./package.json"},"gitHead":"58d0da85ed3dfea8ea3308f38908113652f9490b","license":"MIT","scripts":{"test":"node --test test/wordsninja.test.js test/robustness.test.js","bench":"node bench/bench.js","test:watch":"node --test --watch test/wordsninja.test.js test/robustness.test.js","bench:accuracy":"node bench/accuracy.js","prepublishOnly":"npm test","build:dictionary":"node scripts/build-dictionary.js"},"version":"2.0.1","_npmUser":{"name":"parsakafi","email":"parselearn@gmail.com"},"homepage":"https://parsa.ws/projects/wordsninja-js-package","keywords":["split","text","sentence","english","ninja","words","word","splitter","tokenizer","tokenize","segmentation","text-segmentation","word-segmentation","wordninja","no-spaces","capitalize","camelcase","camel-case"],"repository":{"url":"git+https://github.com/parsakafi/wordsninja.git","type":"git"},"_npmVersion":"12.2.0","description":"Split an English string that has no spaces into words. Zero dependencies, offset-aware, with custom dictionaries and TypeScript types.","directories":{},"maintainers":[{"name":"parsakafi","email":"parselearn@gmail.com"}],"sideEffects":false,"_nodeVersion":"22.23.5","_hasShrinkwrap":false,"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/wordsninja_2.0.1_1795051493291_0.2895690580064638"}}},"time":{"created":"2019-06-20T13:13:45.381Z","modified":"2026-11-19T01:24:53.642Z","1.0.0":"2019-06-20T13:13:45.534Z","1.1.0":"2025-08-23T16:30:56.048Z","2.0.0":"2026-11-18T22:51:18.467Z","2.0.1":"2026-11-19T01:24:53.386Z"},"bugs":{"url":"https://github.com/parsakafi/wordsninja/issues"},"author":{"url":"https://parsa.ws","name":"Parsa Kafi","email":"parselearn@gmail.com"},"license":"MIT","homepage":"https://parsa.ws/projects/wordsninja-js-package","keywords":["split","text","sentence","english","ninja","words","word","splitter","tokenizer","tokenize","segmentation","text-segmentation","word-segmentation","wordninja","no-spaces","capitalize","camelcase","camel-case"],"repository":{"url":"git+https://github.com/parsakafi/wordsninja.git","type":"git"},"description":"Split an English string that has no spaces into words. Zero dependencies, offset-aware, with custom dictionaries and TypeScript types.","maintainers":[{"name":"parsakafi","email":"parselearn@gmail.com"}],"readme":"# WordsNinja\n\nSplit English text that has no spaces into words.\n\n```js\nimport WordsNinja from 'wordsninja';\n\nconst ninja = new WordsNinja();\nninja.splitSentence('youneedtolearnfromyourmistakes');\n// → ['you', 'need', 'to', 'learn', 'from', 'your', 'mistakes']\n```\n\n[![npm version](https://img.shields.io/npm/v/wordsninja.svg)](https://www.npmjs.com/package/wordsninja)\n[![npm downloads](https://img.shields.io/npm/dm/wordsninja.svg)](https://www.npmjs.com/package/wordsninja)\n[![CI](https://github.com/parsakafi/wordsninja/actions/workflows/ci.yml/badge.svg)](https://github.com/parsakafi/wordsninja/actions/workflows/ci.yml)\n[![license](https://img.shields.io/npm/l/wordsninja.svg)](./LICENSE)\n\n## Why WordsNinja\n\n- **Zero dependencies** and a small API surface.\n- **~2.8× faster than v1** — a dynamic-programming search over a frequency-ordered dictionary, backed by a `Map` and typed\n  arrays.\n- **Keeps your text** — case is preserved and characters the dictionary cannot cover are returned instead of silently\n  dropped.\n- **Offset-aware** — get `{ word, start, end }` tokens so you can highlight matches in the original string.\n- **Custom dictionaries** — pass an array of words or point at a `.json` / `.txt` file.\n- **TypeScript types and ESM + CommonJS** entry points.\n- **Lazy dictionary load** — importing the package no longer parses the 1.8 MB word list.\n\n## Install\n\n```bash\nnpm install wordsninja\n```\n\nRequires Node.js 18 or newer.\n\n## Quick start\n\nCommonJS:\n\n```js\nconst WordsNinja = require('wordsninja');\nconst ninja = new WordsNinja();\n\nconsole.log(ninja.splitSentence('youneedtolearnfromyourmistakes'));\n// [ 'you', 'need', 'to', 'learn', 'from', 'your', 'mistakes' ]\n```\n\nESM:\n\n```js\nimport WordsNinja from 'wordsninja';\n\nconst ninja = new WordsNinja();\n```\n\nTypeScript:\n\n```ts\nimport WordsNinja from 'wordsninja';\n\nconst ninja = new WordsNinja();\nconst words: string[] = ninja.splitSentence('ilovewordsninja');\n```\n\nThe dictionary is loaded on first use. `await ninja.loadDictionary()` still works and is kept for backwards\ncompatibility with v1:\n\n```js\nconst ninja = new WordsNinja();\nawait ninja.loadDictionary(); // optional\nninja.splitSentence('helloworld');\n```\n\n## API\n\n### `new WordsNinja(options?)`\n\n| Option       | Type                 | Description                                                                                                                                |\n|--------------|----------------------|--------------------------------------------------------------------------------------------------------------------------------------------|\n| `dictionary` | `string[] \\| string` | Custom dictionary. An array of words, or a path to a `.json` array or newline separated `.txt` file. Defaults to the bundled English list. |\n\n```js\nconst ninja = new WordsNinja({dictionary: ['code', 'ninja']});\nninja.splitSentence('codeninja'); // ['code', 'ninja']\n```\n\nThe `dictionary` option is validated eagerly; the file is read (and the bundled list parsed) on first use.\n\n### `ninja.loadDictionary(): Promise<this>`\n\nLoads the dictionary and resolves with the instance. Optional — the dictionary is loaded lazily — but useful for warming\nup in a serverless handler.\n\n### `ninja.addWords(words): this`\n\nAdds one word or an array of words to **this instance's** dictionary. Added words get the lowest possible cost, so they\noutrank bundled words. Matching is case-insensitive and accent-insensitive.\n\n```js\nconst ninja = new WordsNinja();\nninja.addWords('parsa').addWords(['kafi', 'wordsninja']);\n\nninja.splitSentence('parsayouneedtolearnfromyourmistakes');\n// [ 'parsa', 'you', 'need', 'to', 'learn', 'from', 'your', 'mistakes' ]\n```\n\nInstances do not share added words.\n\n### `ninja.splitSentence(input, options?): string[] | string | WordToken[]`\n\nSplits `input` into words. Throws a `TypeError` if `input` is not a string.\n\n| Option                  | Type             | Default | Description                                                                                                                       |\n|-------------------------|------------------|---------|-----------------------------------------------------------------------------------------------------------------------------------|\n| `camelCaseSplitter`     | `boolean`        | `false` | Split camelCase / PascalCase boundaries. `XMLHttpRequest` → `XML Http Request`, `Note12` → `Note 12`.                             |\n| `capitalizeFirstLetter` | `boolean`        | `false` | Capitalize the first letter of every word.                                                                                        |\n| `joinWords`             | `boolean`        | `false` | Return a space separated string instead of an array. Takes precedence over `withOffsets`.                                         |\n| `withOffsets`           | `boolean`        | `false` | Return `{ word, start, end }` objects. Offsets are UTF-16 indices into `input`.                                                   |\n| `normalizeAccents`      | `boolean`        | `true`  | Strip diacritics before matching (`café` matches `cafe`) while returning the original text.                                       |\n| `mergeNumbers`          | `boolean`        | `true`  | Merge adjacent digit tokens: `call116116now` → `['call', '116116', 'now']`. Merging never crosses a separator, so `1 2 3` stays three tokens. |\n| `mergeContractions`     | `boolean`        | `true`  | Attach `'s`, `'re`, `'ll`, `'ve`, `'d`, `'m`, `'t` to the preceding word: `wang'sbook` → `[\"wang's\", 'book']`. Merging never crosses a separator, so `wang 's` stays two tokens. |\n| `maxWordLength`         | `number`         | `64`    | Maximum length of a dictionary word considered at each position. Lower values are faster; longer words are treated as unknown.    |\n| `unknownWordPenalty`    | `number \\| null` | `10`    | Cost per unmatched character. Unmatched characters are kept as tokens. Set to `null` to drop characters that cannot be segmented. In the bundled dictionary, a lone letter other than `a` or `i` counts as unmatched text. |\n\n#### Offsets\n\n```js\nconst input = 'Ihave2cats';\nninja.splitSentence(input, {withOffsets: true});\n// [\n//   { word: 'I',    start: 0, end: 1 },\n//   { word: 'have', start: 1, end: 5 },\n//   { word: '2',    start: 5, end: 6 },\n//   { word: 'cats', start: 6, end: 10 }\n// ]\n```\n\nEvery offset pair slices back to its word:\n\n```js\nfor (const token of tokens) {\n    input.slice(token.start, token.end) === token.word; // always true\n}\n```\n\n`capitalizeFirstLetter` changes `word` but not the offsets. When `joinWords` is `true`, a string is returned and offsets\nare ignored.\n\n#### All options together\n\n```js\nninja.splitSentence('helloWorldHowAreYou', {\n    camelCaseSplitter: true,\n    capitalizeFirstLetter: true,\n    joinWords: true,\n});\n// 'Hello World How Are You'\n```\n\n## Behavior details\n\n- **Case is preserved.** Only the dictionary lookup is case-insensitive.\n- **Separators are removed.** Spaces, punctuation, emoji and other characters outside `letters`, `digits` and `'` are\n  not part of the result. They become boundaries between words.\n- **Accents are normalized by default.** `cafélatte` → `['café', 'latte']`. Disable with `normalizeAccents: false`; the\n  accented character is then treated as unknown text.\n- **Text the dictionary cannot cover is kept.** Non-English scripts, brand names and typos come back as tokens instead\n  of disappearing: `سلامدنیا` → `['سلامدنیا']`. Adjacent unknown characters are grouped into one token. Use\n  `unknownWordPenalty: null` if you would rather drop them.\n- **Numbers and possessives are merged by default.** `call123now` → `['call', '123', 'now']`, `wang'sbook` →\n  `[\"wang's\", 'book']`. Disable with `mergeNumbers: false` / `mergeContractions: false`.\n- **Whole words win over cheap fragments.** The bundled word list contains every letter as an entry, so a run could be\n  split into pieces cheaper than the word they spell (`sand` → `s and`). The bundled dictionary ignores one-letter\n  entries other than `a` and `i`; those letters are treated as unmatched text, so `sand` stays `sand`. Custom\n  dictionaries keep their one-letter entries.\n- **Ambiguous input is a guess.** `thequickbrownfox` can only be segmented by cost; some strings have more than one\n  plausible split.\n- **Long words are capped.** `maxWordLength` bounds the candidate window per position. Words longer than the cap are\n  treated as unknown.\n\n## Custom dictionaries\n\n```js\n// Array\nconst code = new WordsNinja({dictionary: ['code', 'ninja']});\n\n// JSON file: [\"code\", \"ninja\"]\nconst fromJson = new WordsNinja({dictionary: './words.json'});\n\n// Text file: one word per line\nconst fromText = new WordsNinja({dictionary: './words.txt'});\n```\n\nPaths are resolved from the current working directory. An empty dictionary is valid: every run of text is returned as\nunknown tokens (or dropped when `unknownWordPenalty` is `null`).\n\n## Bundlers and browsers\n\nThe package resolves no Node built-ins at import time, so it bundles cleanly for browsers and edge runtimes:\n\n```js\nimport WordsNinja from 'wordsninja';\n\nconst ninja = new WordsNinja();\nninja.splitSentence('youneedtolearnfromyourmistakes');\n```\n\nThe bundled word list is included in the bundle (about 610 KB gzipped) and parsed on first use. File-path dictionaries\nare Node.js only; in the browser, fetch the words and pass an array instead:\n\n```js\nconst words = await (await fetch('/words.json')).json();\nconst ninja = new WordsNinja({dictionary: words});\n```\n\nOffsets, custom words and every option work the same way in the browser.\n\n## Migrating from v1\n\nv2 is a breaking release compared with v1:\n\n- **`loadDictionary()` is optional.** The dictionary loads on first use. It still exists, now resolves with the\n  instance, and is idempotent.\n- **Instances are isolated.** `addWords()` no longer changes a module-global dictionary shared by every instance.\n- **The possessive/merge code actually runs.** v1 stored merged tokens at `out[-1]`, so the branch never executed.\n  Possessives and digit runs are now merged by default.\n- **Unknown text is no longer dropped silently.** v1 returned `[]` for non-Latin input and removed accents as\n  separators; v2 keeps unmatched text as tokens.\n- **Accents are normalized by default.** `cafélatte` now yields `['café', 'latte']` instead of `['caf', 'latte']`.\n- **`addWords()` returns the instance** for chaining, ignores empty entries, and rejects non-strings or words\n  containing whitespace.\n- **Clear errors instead of hangs.** Using the API before the dictionary was loaded used to loop until\n  `RangeError: Invalid array length`; it now initializes lazily and validates input.\n- **Node.js 18+**, TypeScript types, and ESM are supported.\n- **New options:** `withOffsets`, `normalizeAccents`, `mergeNumbers`, `mergeContractions`, `maxWordLength`,\n  `unknownWordPenalty`, plus a `dictionary` constructor option.\n\n## Performance\n\nMeasured on a desktop machine (Node 22); split workloads are best of five, dictionary load is a cold start:\n\n| Workload          | v1                      | v2                        |\n|-------------------|-------------------------|---------------------------|\n| 4,500 characters  | ~85 ms                  | **~30 ms**                |\n| 21,000 characters | ~388 ms                 | **~137 ms**               |\n| Dictionary load   | ~83 ms (import + build) | **~46 ms** (first use)    |\n\nv2 also supports `withOffsets` at no measurable extra cost. Numbers vary by machine; run the benchmark on your hardware.\n\n### Accuracy\n\n`npm run bench:accuracy` removes the spaces from two corpora and scores the result against the intended words:\n\n| Corpus                       | Sentences | Exact       | Precision | Recall | F1    |\n|------------------------------|-----------|-------------|-----------|--------|-------|\n| `bench/corpus.txt` (tuned)   | 202       | 176 (87.1%) | 96.8%     | 95.6%  | 96.2% |\n| `bench/prose.txt` (held out) | 600       | 474 (79.0%) | 97.4%     | 96.6%  | 97.0% |\n\n`prose.txt` holds 600 sentences from six public-domain novels; it is kept apart from the corpus used while tuning, so a\nchange cannot raise the tuned score by over-fitting. CI enforces a floor on both. Against 2.0.0, 13 more sentences are\nexact (3 tuned and 10 prose) and none regressed.\n\nMost remaining misses are cost ties a unigram model cannot resolve without context: a longer dictionary word wins over\ntwo shorter ones (`every day` → `everyday`, `me an` → `mean`), or two two-word splits compete (`i slept` → `is lept`).\n\n## Development\n\n```bash\nnpm test                 # node:test suite\nnpm run test:watch       # watch mode\nnpm run bench            # segmentation speed benchmark\nnpm run bench:accuracy   # accuracy against bench/corpus.txt and bench/prose.txt\nnpm run build:dictionary # validate/de-duplicate words-en.json\n```\n\nCI runs the test suite on Node.js 18, 20, 22 and 24, verifies the published artifact with `npm pack --dry-run`, and\nfails if the accuracy benchmark drops below its floor.\n\n## Releasing\n\n1. Update the version and the changelog/README notes.\n2. `npm test`\n3. Tag and push: `git tag v2.0.1 && git push origin v2.0.1`\n\nThe `Release` workflow checks that the tag matches `package.json`, runs the tests, and publishes with provenance through\nnpm trusted publishing. If you publish manually, use `npm publish --provenance`.\n\n## Limitations\n\nWordsNinja is a dictionary-based segmenter, not a language model:\n\n- The bundled list is English-focused. Non-English text is preserved as unknown tokens, not segmented.\n- Segmentation is a best guess for ambiguous input.\n- Punctuation is treated as a boundary, not preserved.\n- The dictionary costs ~30 MB of heap once loaded; it is shared by all instances in a process.\n\n## License\n\n[MIT](./LICENSE) © Parsa Kafi\n\n## Acknowledgements\n\n- Algorithm\n  from [How to split text without spaces into list of words?](https://stackoverflow.com/questions/8870261/how-to-split-text-without-spaces-into-list-of-words).\n- Word list from the [wordninja](https://pypi.org/project/wordninja) Python package (MIT). See [NOTICE](./NOTICE).\n- v1 camelCase splitting was based\n  on [split-camelcase-to-words](https://www.npmjs.com/package/split-camelcase-to-words).\n","readmeFilename":"README.md"}