npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

kh-tokenizer

v0.2.2

Published

Fast, dependency-free Khmer word segmentation (Rust core compiled to WebAssembly)

Readme

kh-tokenizer

Fast, dependency-free Khmer word segmentation for JavaScript — the khmer-tokenizer-core Rust engine compiled to WebAssembly. Runs in Node and browsers; ships its own TypeScript definitions.

(Named kh-tokenizer on npm because khmer-tokenizer — the project's PyPI/crates.io name — is blocked by npm's similar-name rule. Same engine, same API.)

Written Khmer has no spaces between words, so before you can search, index, or feed Khmer text to a model, you have to split it into words. General-purpose tokenizers either ignore Khmer or shatter it into meaningless character fragments; this package segments it correctly.

// npm install kh-tokenizer
import { KhmerTokenizer, splitKcc, normalize, isKhmer } from "kh-tokenizer";

const tk = new KhmerTokenizer(); // embedded 59k-word dictionary, forward max-match
tk.segment("សួស្តីអ្នកទាំងអស់គ្នា");
// ["សួស្តី", "អ្នក", "ទាំងអស់គ្នា"]

Options

Everything is configured at construction time:

new KhmerTokenizer({ strategy: "bimm" });          // bidirectional max-match
new KhmerTokenizer({ words: ["ភាសា", "ខ្មែរ"] }); // your own word list
new KhmerTokenizer({                                // frequency-scored DP
  strategy: "unigram",
  frequencies: { "ភាសា": 500, "ខ្មែរ": 800 },
});
new KhmerTokenizer({ normalization: false });       // skip orthographic repair
  • segment(text)string[] — segment Khmer text into words. Runs of non-Khmer text (Latin, digits) become their own tokens; whitespace and U+200B ZERO WIDTH SPACE act as hard word boundaries.
  • contains(word)boolean, sizenumber — dictionary lookups.
  • splitKcc(text)string[] — split into Khmer Character Clusters (orthographic syllables; the segmenter never splits inside one).
  • normalize(text) — repair common mark-ordering corruptions, including the damage Unicode NFC itself inflicts on Khmer.
  • isKhmer(char)boolean.

Normalization is on by default because any NFC step upstream of you silently corrupts Khmer subscript ordering (see the project's RESEARCH-3.md).

Use as an LLM pre-tokenizer

Segment your corpus, join with spaces (or ZWSP), then train BPE/SentencePiece on the result so learned subwords respect real Khmer word structure.

Links

License

MIT OR Apache-2.0. Bundled dictionary derived from chamkho's khmerdict.txt (MIT, © SIL NRSI — see ATTRIBUTION.md).