@chonkiejs/chunk

中文文档
0.10.1发布于 2026/03/30MIT OR Apache-2.0ES Module零依赖近 30 天下载 10万

The fastest semantic text chunking library

原始使用文档
文档目录4 节
  1. 📦 installation
  2. 🚀 usage
  3. 📝 citation
  4. 📄 license

@chonkiejs/chunk

@chonkiejs/chunk

the fastest text chunking library — up to 1 TB/s throughput

crates.io PyPI npm GitHub License


you know how every chunking library claims to be fast? yeah, we actually meant it.

@chonkiejs/chunk splits text at semantic boundaries (periods, newlines, the usual suspects) and does it stupid fast. we're talking "chunk the entire english wikipedia in 120ms" fast.

want to know how? read the blog post where we nerd out about SIMD instructions and lookup tables.

📦 installation

npm install @chonkiejs/chunk

looking for rust or python?

🚀 usage

import { init, chunk } from '@chonkiejs/chunk';

// initialize wasm (required once)
await init();

const text = "Hello world. How are you? I'm fine.\nThanks for asking.";

// with defaults (4KB chunks, split at \n . ?)
for (const slice of chunk(text)) {
    console.log(slice);
}

// with custom size
for (const slice of chunk(text, { size: 1024 })) {
    console.log(slice);
}

// with custom delimiters
for (const slice of chunk(text, { delimiters: ".?!\n" })) {
    console.log(slice);
}

// with multi-byte pattern (e.g., metaspace ▁ for SentencePiece tokenizers)
for (const slice of chunk(text, { pattern: "▁", prefix: true })) {
    console.log(slice);
}

// with consecutive pattern handling (split at START of runs, not middle)
for (const slice of chunk("word   next", { pattern: " ", consecutive: true })) {
    console.log(slice);
}

// with forward fallback (search forward if no pattern in backward window)
for (const slice of chunk(text, { pattern: " ", forwardFallback: true })) {
    console.log(slice);
}

// collect all chunks
const chunks = [...chunk(text)];

pass strings and get strings back. for zero-copy performance with binary data, pass Uint8Array and you'll get Uint8Array views back.

📝 citation

if you use @chonkiejs/chunk in your research, please cite it as follows:

@software{chunk2025,
  author = {Minhas, Bhavnick},
  title = {chunk: The fastest text chunking library},
  year = {2025},
  publisher = {GitHub},
  howpublished = {\url{https://github.com/chonkie-inc/chunk}},
}

📄 license

licensed under either of Apache License, Version 2.0 or MIT license at your option.

版本与发布记录

@chonkiejs/chunk 共发布 10 个版本,首次发布于 2026/01/21;过去 12 个月发布了 10 个版本。

版本发布日期距今
0.10.1latest2026/03/307 个月前
0.10.02026/03/307 个月前
0.9.32026/01/219 个月前
0.9.22026/01/219 个月前
0.9.12026/01/219 个月前
0.9.02026/01/219 个月前

关于 @chonkiejs/chunk 的常见问题

@chonkiejs/chunk 是什么?

The fastest semantic text chunking library

如何安装 @chonkiejs/chunk?

在项目目录运行 npm install @chonkiejs/chunk,或使用 pnpm add / yarn add / bun add。

@chonkiejs/chunk 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/chonkiejs__chunk 是否存在。

@chonkiejs/chunk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@chonkiejs/chunk 可以商用吗?

@chonkiejs/chunk 使用 MIT OR Apache-2.0 许可。可在 MIT、Apache-2.0 中任选其一遵守。选择 MIT 时,宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@chonkiejs/chunk 的下载量有多少?

根据 npm 官方下载统计,@chonkiejs/chunk 在 2026/10/10 – 2026/11/08 这 30 天内被下载 99,778 次,日均约 3,326 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@chonkiejs/chunk 还在维护吗?

最新版本 0.10.1 发布于 2026/03/30(7 个月前);至今共发布 10 个版本,其中过去 12 个月发布了 10 个;首次发布于 2026/01/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。