Skip to main content

Crate inputx_pinyin_wasm

Crate inputx_pinyin_wasm 

Source
Expand description

WASM bindings for inputx-pinyin. Exposes a small, JS-friendly API that browser and Node consumers can import via wasm-pack output.

Build: wasm-pack build crates/inputx-pinyin-wasm –target web –release

Default build bakes the bootstrap dict (1.7 KB) — the full 15 MB pinyin.fst is too large for typical wasm bundles. Item 33 of the workspace ROADMAP is the proper streaming-load story; until then, pass --no-default-features (which propagates to the lib crate) to bake the full dict.

Usage (JS):

import init, { PinyinEngine } from "@goliapkg/pinyin";
await init();
const eng = new PinyinEngine();
const candidates = eng.lookup("zhongguo");      // ["中国", ...]
eng.recordPick("zhongguo", "中国");              // user picked candidate
const state = eng.exportL0();                    // structured object
localStorage.setItem("pinyin-l0", JSON.stringify(state));
// later:
eng.importL0(JSON.parse(localStorage.getItem("pinyin-l0")));

Structs§

PinyinEngine
Pinyin engine wrapping the embedded FST dictionary plus a per-instance L0 layer (in-memory; persistence is up to the host via exportL0 / importL0).