{"name":"@node-rs/jieba","version":"2.0.3","keywords":["Jieba","N-API","Rust","napi","napi-rs","node-rs"],"author":{"name":"LongYinan","email":"lynweklm@gmail.com"},"license":"MIT","_id":"@node-rs/jieba@2.0.3","maintainers":[{"name":"broooooklyn","email":"lynweklm@gmail.com"}],"homepage":"https://github.com/napi-rs/node-rs","bugs":{"url":"https://github.com/napi-rs/node-rs/issues"},"dist":{"shasum":"bce9c0c2ccb4661ebe0d5e69b2675aeb39b6bf6b","tarball":"http://registry-npm.ywwl.com/@node-rs/jieba/download/@node-rs/jieba-2.0.3.tgz","fileCount":10,"integrity":"sha512-WfTweEAbwHNPV4BvbhyQfG5E4wUQWnjy7x9Li4yYgwm+c4hlkuREkMcpCS0tTo+eTyDIBZ/kFVylns2blPBZxg==","signatures":[{"sig":"MEUCIQDC0fuB2QWVywUMhYbr9eVumOmuYS6W9RoFDowO+jieNgIgL21htrQtxOq2RGzZBlu5gokQusJ3keR18URjatByUxw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@node-rs%2fjieba@2.0.3","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":11316129,"size":4164150,"noattachment":false,"key":"/@node-rs/jieba/-/@node-rs/jieba-2.0.3.tgz"},"main":"index.js","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"},"browser":"browser.js","engines":{"node":">= 10"},"funding":{"url":"https://github.com/sponsors/Brooooooklyn","type":"github"},"gitHead":"56c64a1f875d9568b0a6a79b6c658ce5996d25a2","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","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:ebb7c383-0e42-4ee4-89bf-d9f5a85181a0"}},"repository":{"url":"git+https://github.com/napi-rs/node-rs.git","type":"git"},"_npmVersion":"lerna/10.0.1/node@v24.20.0+x64 (linux)","description":"Fastest Chinese word segmentation in Node.js","directories":{},"_nodeVersion":"24.20.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.8.6"},"optionalDependencies":{"@node-rs/jieba-darwin-x64":"2.0.3","@node-rs/jieba-freebsd-x64":"2.0.3","@node-rs/jieba-darwin-arm64":"2.0.3","@node-rs/jieba-android-arm64":"2.0.3","@node-rs/jieba-linux-x64-gnu":"2.0.3","@node-rs/jieba-linux-x64-musl":"2.0.3","@node-rs/jieba-win32-x64-msvc":"2.0.3","@node-rs/jieba-linux-arm64-gnu":"2.0.3","@node-rs/jieba-win32-ia32-msvc":"2.0.3","@node-rs/jieba-android-arm-eabi":"2.0.3","@node-rs/jieba-linux-arm64-musl":"2.0.3","@node-rs/jieba-win32-arm64-msvc":"2.0.3","@node-rs/jieba-linux-arm-gnueabihf":"2.0.3"},"_npmOperationalInternal":{"tmp":"tmp/jieba_2.0.3_1789019983586_0.29111165539227635","host":"s3://npm-registry-packages-npm-production"},"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":1789019983847,"_cnpm_publish_time":1789019983847,"dist-tags":{"alpha":"0.4.0-alpha.1","deprecated":"1.5.3","latest":"2.0.4"}}