{"_id":"@node-rs/jieba@2.0.4","bugs":{"url":"https://github.com/napi-rs/node-rs/issues"},"dist":{"shasum":"569b0a66d33474fbbd821e4b72ed69c483904926","tarball":"http://registry-npm.ywwl.com/@node-rs/jieba/download/@node-rs/jieba-2.0.4.tgz","fileCount":10,"integrity":"sha512-/dTk3vV/v8+RIEUP7XOCkqRCVU0tqL3Ia9VTzHt38IDysGQmX7T56tM2IpwCLAWXubH7TyrcY54Stjsvcrbjqw==","signatures":[{"sig":"MEUCIQCVRVWSNMc6Fgh70O+HhjH0emy3q+B0Hx4tFjKoBgSULQIgUM0m08B1T+jOJnTo5/Xc1PAPWud5pupDVWFMMGx+HqQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQClsSETsfdblXslgt1mi3SBZfB33lcSyU9mJwHWO2pkOAIhAKS6F9fgkVAPnn9gXTqKOxiIyvWpgY+XkXmh8CqwMI77"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@node-rs%2fjieba@2.0.4","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":11318646,"size":4164363,"noattachment":false,"key":"/@node-rs/jieba/-/@node-rs/jieba-2.0.4.tgz"},"main":"index.js","name":"@node-rs/jieba","napi":{"targets":["x86_64-apple-darwin","aarch64-apple-darwin","x86_64-pc-windows-msvc","x86_64-unknown-linux-gnu","aarch64-linux-android","aarch64-unknown-linux-gnu","aarch64-unknown-linux-musl","aarch64-pc-windows-msvc","armv7-unknown-linux-gnueabihf","x86_64-unknown-linux-musl","x86_64-unknown-freebsd","i686-pc-windows-msvc","armv7-linux-androideabi","wasm32-wasip1-threads"],"binaryName":"jieba"},"author":{"name":"LongYinan","email":"lynweklm@gmail.com"},"browser":"browser.js","engines":{"node":">= 10"},"funding":{"url":"https://github.com/sponsors/Brooooooklyn","type":"github"},"gitHead":"b706e3035f5d4d487ae66ea0549a041cd509e5d4","license":"MIT","scripts":{"bench":"cross-env NODE_ENV=production node --import @oxc-node/core/register benchmark/jieba.ts","build":"napi build --platform --release","version":"napi version","artifacts":"napi artifacts -d ../../artifacts","build:debug":"napi build --platform","prepublishOnly":"napi prepublish"},"typings":"index.d.ts","version":"2.0.4","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"ebb7c383-0e42-4ee4-89bf-d9f5a85181a0"}},"homepage":"https://github.com/napi-rs/node-rs","keywords":["Jieba","N-API","Rust","napi","napi-rs","node-rs"],"repository":{"url":"git+https://github.com/napi-rs/node-rs.git","type":"git"},"_npmVersion":"lerna/10.0.1/node@v24.21.0+x64 (linux)","description":"Fastest Chinese word segmentation in Node.js","directories":{},"maintainers":[{"name":"broooooklyn","email":"lynweklm@gmail.com"}],"_nodeVersion":"24.21.0","publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"cross-env":"^10.1.0","tinybench":"^6.1.3","@napi-rs/cli":"^3.10.8"},"optionalDependencies":{"@node-rs/jieba-darwin-x64":"2.0.4","@node-rs/jieba-freebsd-x64":"2.0.4","@node-rs/jieba-darwin-arm64":"2.0.4","@node-rs/jieba-android-arm64":"2.0.4","@node-rs/jieba-linux-x64-gnu":"2.0.4","@node-rs/jieba-linux-x64-musl":"2.0.4","@node-rs/jieba-win32-x64-msvc":"2.0.4","@node-rs/jieba-linux-arm64-gnu":"2.0.4","@node-rs/jieba-win32-ia32-msvc":"2.0.4","@node-rs/jieba-android-arm-eabi":"2.0.4","@node-rs/jieba-linux-arm64-musl":"2.0.4","@node-rs/jieba-win32-arm64-msvc":"2.0.4","@node-rs/jieba-linux-arm-gnueabihf":"2.0.4"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/jieba_2.0.4_1791281496680_0.3162847501124235"},"readme":"# `@node-rs/jieba`\n\n![](https://github.com/napi-rs/node-rs/workflows/CI/badge.svg)\n![](https://img.shields.io/npm/dm/@node-rs/jieba.svg?sanitize=true)\n\n[jieba-rs](https://github.com/messense/jieba-rs) binding to Node.js\n\n## Without node-gyp\n\n`node-rs/jieba` was prebuilt into binary already, so you don't need fighting with `node-gyp` and c++ toolchain.\n\n## Performance\n\nDue to [jieba-rs is 33% faster than cppjieba](https://blog.paulme.ng/posts/2019-06-30-optimizing-jieba-rs-to-be-33percents-faster-than-cppjieba.html), and N-API is faster than `v8` C++ API, `@node-rs/jieba` is faster than `nodejieba`.\n\nBenchmarked with `jieba-rs@0.11.0` vs `nodejieba@3.5.8` on Apple M4 Max, Node.js v26.8.2:\n\n```bash\nBenchmark Cut 1184 words result\n┌─────────┬──────────────────┬──────────────────┬───────────────────┬────────────────────────┬────────────────────────┬─────────┐\n│ (index) │ Task name        │ Latency avg (ns) │ Latency med (ns)  │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │\n├─────────┼──────────────────┼──────────────────┼───────────────────┼────────────────────────┼────────────────────────┼─────────┤\n│ 0       │ '@node-rs/jieba' │ '61311 ± 0.08%'  │ '61041 ± 416.00'  │ '16342 ± 0.06%'        │ '16382 ± 111'          │ 16311   │\n│ 1       │ 'nodejieba'      │ '133632 ± 0.11%' │ '133875 ± 1667.0' │ '7497 ± 0.09%'         │ '7470 ± 92'            │ 7484    │\n└─────────┴──────────────────┴──────────────────┴───────────────────┴────────────────────────┴────────────────────────┴─────────┘\nBenchmark Cut 246568 words result\n┌─────────┬──────────────────┬────────────────────┬─────────────────────┬────────────────────────┬────────────────────────┬─────────┐\n│ (index) │ Task name        │ Latency avg (ns)   │ Latency med (ns)    │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │\n├─────────┼──────────────────┼────────────────────┼─────────────────────┼────────────────────────┼────────────────────────┼─────────┤\n│ 0       │ '@node-rs/jieba' │ '17941189 ± 1.06%' │ '17739146 ± 215874' │ '56 ± 0.98%'           │ '56 ± 1'               │ 64      │\n│ 1       │ 'nodejieba'      │ '39167640 ± 1.22%' │ '38399145 ± 888271' │ '26 ± 1.15%'           │ '26 ± 1'               │ 64      │\n└─────────┴──────────────────┴────────────────────┴─────────────────────┴────────────────────────┴────────────────────────┴─────────┘\nBenchmark Tag 1184 words result\n┌─────────┬──────────────────┬──────────────────┬───────────────────┬────────────────────────┬────────────────────────┬─────────┐\n│ (index) │ Task name        │ Latency avg (ns) │ Latency med (ns)  │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │\n├─────────┼──────────────────┼──────────────────┼───────────────────┼────────────────────────┼────────────────────────┼─────────┤\n│ 0       │ '@node-rs/jieba' │ '158515 ± 0.09%' │ '157416 ± 1249.0' │ '6315 ± 0.07%'         │ '6353 ± 51'            │ 6309    │\n│ 1       │ 'nodejieba'      │ '305060 ± 0.12%' │ '303375 ± 2541.0' │ '3281 ± 0.10%'         │ '3296 ± 27'            │ 3279    │\n└─────────┴──────────────────┴──────────────────┴───────────────────┴────────────────────────┴────────────────────────┴─────────┘\nBenchmark Tag 246568 words result\n┌─────────┬──────────────────┬────────────────────┬──────────────────────┬────────────────────────┬────────────────────────┬─────────┐\n│ (index) │ Task name        │ Latency avg (ns)   │ Latency med (ns)     │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │\n├─────────┼──────────────────┼────────────────────┼──────────────────────┼────────────────────────┼────────────────────────┼─────────┤\n│ 0       │ '@node-rs/jieba' │ '42167642 ± 1.49%' │ '41271917 ± 769729'  │ '24 ± 1.36%'           │ '24 ± 0'               │ 64      │\n│ 1       │ 'nodejieba'      │ '86278741 ± 0.86%' │ '85348500 ± 1364291' │ '12 ± 0.83%'           │ '12 ± 0'               │ 64      │\n└─────────┴──────────────────┴────────────────────┴──────────────────────┴────────────────────────┴────────────────────────┴─────────┘\n```\n\n## Usage\n\n```javascript\nimport { Jieba } from '@node-rs/jieba'\nimport { dict } from '@node-rs/jieba/dict'\n\n// load jieba with the default dict\nconst jieba = Jieba.withDict(dict)\n\nconsole.info(jieba.cut('我们中出了一个叛徒', false))\n\n// [\"我们\", \"中\", \"出\", \"了\", \"一个\", \"叛徒\"]\n```\n\n```javascript\nimport { Jieba, TfIdf } from '@node-rs/jieba'\nimport { dict, idf } from '@node-rs/jieba/dict'\n\nconst jieba = Jieba.withDict(dict)\nconst tfIdf = TfIdf.withDict(idf)\n\ntfIdf.extractKeywords(\n  jieba,\n  '今天纽约的天气真好啊，京华大酒店的张尧经理吃了一只北京烤鸭。后天纽约的天气不好，昨天纽约的天气也不好，北京烤鸭真好吃',\n  3,\n)\n\n// [\n//   { keyword: '北京烤鸭', weight: 1.3904870323222223 },\n//   { keyword: '纽约', weight: 1.121759684755 },\n//   { keyword: '天气', weight: 1.0766573240983333 }\n// ]\n```\n\n### Load custom dictionaries\n\n```javascript\nimport { Jieba } from '@node-rs/jieba'\nconst customDict = ['哪行 50', '干一行 51', '行一行 52', '行行 53']\n\nconst dictBuffer = Buffer.from(customDict.join('\\n'), 'utf-8')\nconst jieba = Jieba.withDict(dictBuffer)\n\nconst text = '人要是行干一行行一行，一行行行行行，行行行干哪行都行'\nconst output = jieba.cut(text, false)\nconsole.log('分词结果⤵️\\n', output.join('/'))\n// Before: 人/要是/行/干/一行行/一行/，/一行行/行/行/行/，/行/行/行/干/哪/行/都行\n// After:  人/要是/行/干一行/行一行/，/一行行/行行/行/，/行行/行/干/哪行/都行\n// Pinyin: rén yào shi xíng gàn yì háng xíng yì háng ， yì háng xíng háng háng xíng ， háng háng xíng gàn nǎ háng dōu xíng\n```\n","publish_time":1791281496873,"_cnpm_publish_time":1791281496873,"dist-tags":{"alpha":"0.4.0-alpha.1","deprecated":"1.5.3","latest":"2.0.4"}}