@goliapkg/nihongo (WASM)
Browser / Node bindings for inputx-nihongo —
self-contained Japanese input engine: Hepburn (with kunrei alternates)
romaji → hiragana/katakana, on-yomi single-kanji lookup, 27k jukugo
(熟語) compound lookup, mechanical compose_sentence particle/copula
glue. Pre-built into a ~1.5 MB WebAssembly module (JUKUGO_TABLE +
KANJI_TABLE embedded).
The web surface of the Inputx IME.
License: MIT OR Apache-2.0.
Install
Usage
import init from "@goliapkg/nihongo";
await ; // load + instantiate the .wasm
const eng = ;
// Drive the engine one ASCII byte at a time. `-` is also accepted as
// chōonpu (ー / long-vowel mark) when the buffer is non-empty so
// long-vowel words like コーヒー stay reachable.
console.log; // "shinjuku"
console.log;
// [
// { word: "新宿", kind: KanaKind.Kanji, freq: N,
// composed: false, proximityMilli: 1000 },
// { word: "しんじゅく", kind: KanaKind.Hiragana, freq: 0,
// composed: false, proximityMilli: 1000 },
// { word: "シンジュク", kind: KanaKind.Katakana, freq: 0,
// composed: false, proximityMilli: 1000 },
// ]
// Commit one — engine clears its buffer ready for the next word.
const committed = eng.; // "新宿"
// Backspace pops one byte; escape clears the entire buffer.
eng.;
eng.; // pops 'e'
eng.; // clears entirely
Candidate fields
Each candidates() entry carries:
| Field | Type | Meaning |
|---|---|---|
word |
string |
The displayed text (kanji / hiragana / katakana) |
kind |
KanaKind |
Enum (0=Hiragana, 1=Katakana, 2=Kanji) for the host UI's optional kana/kanji hint |
freq |
number |
0–100 frequency score. Higher = more common in modern JP. 0 for kana fallback (mechanical romaji → kana, not freq-tuned) |
composed |
boolean |
true for compose_sentence products (particle/copula glue like 私は). LOW confidence — host should rank these below real dict words |
proximityMilli |
number |
1000 = the buffer is the full reading (exact match). < 1000 = prefix-prediction candidate whose reading the buffer is only a prefix of (shinjuk → 新宿 at 875) |
What ships
inputx_nihongo_wasm_bg.wasm— engine + 27,380 jukugo + 1,666 kanji-reading pairs (~1.5 MB)inputx_nihongo_wasm.js— ES-module wrapperinputx_nihongo_wasm.d.ts— TypeScript types
Build from source
# output in core/crates/inputx-nihongo-wasm/pkg/
For Node-target bundles: wasm-pack build --target nodejs.
API stability
The 1.x line follows semver:
JapaneseEngineconstructor + method set — no breaking changes within 1.x. New methods may be added as minor bumps.KanaKindenum discriminants — fixed (0=Hiragana, 1=Katakana, 2=Kanji); matches the native facade'sKanaKindenum.candidates()object shape — the 5 fields above are stable across 1.x; additional fields may be added as minor bumps.commitIndexreturn — string for in-range,nullfor out-of-range index; out-of-range never mutates state.
See also
- Native Rust crate:
inputx-nihongo - Parent IME repo: Inputx
- Sibling engines:
@goliapkg/wubi·@goliapkg/pinyin