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

@f3liz/sudachi-wasm

v0.1.7

Published

WebAssembly build of Sudachi Japanese tokenizer

Readme

Sudachi WASM

WebAssembly build of Sudachi Japanese tokenizer for use in browsers and Node.js.

Quick Start

Build

# Build the WASM module
cargo build --target wasm32-unknown-unknown --release
# or, if you are in macOS, run `brew install llvm` and
# CC_wasm32_unknown_unknown=/opt/homebrew/opt/llvm/bin/clang cargo build --target wasm32-unknown-unknown --release

# Install wasm-bindgen-cli (if not already installed)
cargo install wasm-bindgen-cli

# Generate JavaScript bindings for web
wasm-bindgen ../target/wasm32-unknown-unknown/release/sudachi_wasm.wasm \
    --out-dir pkg \
    --target web

# Or for Node.js
wasm-bindgen ../target/wasm32-unknown-unknown/release/sudachi_wasm.wasm \
    --out-dir pkg-node \
    --target nodejs

JavaScript API

Functions

loadDictionary(xdicBytes: Uint8Array): number

Load a dictionary from .xdic file bytes. Returns a handle ID for use with other functions.

Parameters:

  • xdicBytes: Uint8Array containing the dictionary file contents

Returns: Dictionary handle (number)

Example:

const response = await fetch("system.xdic");
const dictBytes = new Uint8Array(await response.arrayBuffer());
const handle = loadDictionary(dictBytes);

tokenize(handle: number, text: string, mode: number): TokenResult[]

Tokenize Japanese text using the loaded dictionary.

Parameters:

  • handle: Dictionary handle from loadDictionary
  • text: Japanese text to tokenize
  • mode: Tokenization mode
    • 0: Mode A (short units - finest granularity)
    • 1: Mode B (middle units)
    • 2: Mode C (long units - coarsest granularity, default)

Returns: Array of token objects with properties:

  • surface: Surface form of the token
  • reading: Reading (pronunciation) of the token
  • pos: Part of speech tag

Example:

const tokens = tokenize(handle, "選挙管理委員会", 0);
tokens.forEach((token) => {
    console.log(`${token.surface} (${token.reading}) - ${token.pos}`);
});

freeDictionary(handle: number): void

Free a dictionary handle and release its resources.

Parameters:

  • handle: Dictionary handle to free

Example:

freeDictionary(handle);

Usage Examples

Browser (ES Modules)

See demo.html for a complete interactive example.

import init, {
    freeDictionary,
    loadDictionary,
    tokenize,
} from "./pkg/sudachi_wasm.js";

// Initialize the WASM module
await init();

// Load dictionary
const response = await fetch("system.xdic");
const dictBytes = new Uint8Array(await response.arrayBuffer());
const handle = loadDictionary(dictBytes);

// Tokenize with Mode C (long units)
const tokens = tokenize(handle, "東京スカイツリー", 2);

tokens.forEach((token) => {
    console.log(`${token.surface}\t${token.reading}\t${token.pos}`);
});

// Clean up
freeDictionary(handle);

Node.js

See example-node.js for a complete example.

const { loadDictionary, tokenize, freeDictionary } = require(
    "./pkg-node/sudachi_wasm.js",
);
const fs = require("fs");

// Load dictionary
const dictBytes = new Uint8Array(fs.readFileSync("system.xdic"));
const handle = loadDictionary(dictBytes);

// Tokenize
const tokens = tokenize(handle, "東京スカイツリー", 2);

tokens.forEach((token) => {
    console.log(`${token.surface}\t${token.reading}\t${token.pos}`);
});

// Clean up
freeDictionary(handle);

Running the Demo

To test the browser demo:

# Serve the directory with a local web server (needed for ES modules)
python3 -m http.server 8000

# Or use any other static file server
# npx serve .
# or
# npx http-server .

# Then open http://localhost:8000/demo.html in your browser

Tokenization Modes

Sudachi supports three tokenization modes with different granularities:

  • Mode A (0): Short units (finest) - e.g., "選挙管理委員会" → ["選挙", "管理", "委員", "会"]
  • Mode B (1): Middle units - e.g., "選挙管理委員会" → ["選挙", "管理", "委員会"]
  • Mode C (2): Long units (coarsest) - e.g., "選挙管理委員会" → ["選挙管理委員会"]

Build Configuration

The project is configured to build for wasm32-unknown-unknown target:

  • Uses wasm-bindgen for JavaScript interoperability
  • On macOS, uses Homebrew LLVM's clang for WebAssembly support
  • Configured in .cargo/config.toml

Files

  • demo.html - Interactive browser demo
  • example-node.js - Node.js usage example
  • pkg/ - Web bindings (generated by wasm-bindgen)
  • pkg-node/ - Node.js bindings (generated by wasm-bindgen)

Notes

  • The dictionary file (.xdic) must be loaded before tokenization
  • Multiple dictionaries can be loaded simultaneously with different handles
  • Always call freeDictionary() when done to avoid memory leaks
  • The WASM module is built for wasm32-unknown-unknown target for maximum compatibility
  • For production use, consider compressing the dictionary file (it's quite large)

TypeScript Support

The generated bindings include TypeScript type definitions (.d.ts files), providing full type safety and IDE autocomplete support.