文書Documentation
JavaScript client
npm install @kotoshu/client — the typed HTTP client for Node, Deno, Bun, and browsers, plus the @kotoshu/wasm engine for offline checking in-process.
Two packages on npm: @kotoshu/client,
the typed HTTP client, and @kotoshu/wasm,
the whole engine compiled to WebAssembly. Same Suggestion
shape either way.
Install
npm install @kotoshu/client # the HTTP client (ESM + TypeScript types)
npm install @kotoshu/wasm # optional: the engine, 162 KiB gzipped (0.3.2 tarball)Node 18+, Deno, Bun, and browsers. The wasm package is deliberately not a dependency of the client — opt in explicitly.
Quick start — over HTTP
Point the client at a running kotoshu-server:
import { Client } from "@kotoshu/client";
const client = new Client("http://127.0.0.1:9292");
const result = await client.check("helo wrold", "en");
for (const err of result.errors) {
console.log(err.word, "->", err.suggestions.slice(0, 3).map((s) => s.word));
}
const suggestions = await client.suggest("recieve", { max: 3 });
console.log(suggestions.map((s) => [s.word, s.confidence]));
console.log(await client.correct("hello", "en"));helo -> [ 'hello', 'help', 'hell' ]
wrold -> [ 'world', 'wold', 'weld' ]
[ [ 'receive', 1 ], [ 'relieve', 0.91 ], [ 'recife', 0.5 ] ]
trueOffline — the wasm engine
With @kotoshu/wasm installed,
createWasmDictionary loads the engine
in-process. Dictionaries are the string contents of the .aff
and .dic files — WebAssembly has no filesystem:
import { createWasmDictionary } from "@kotoshu/client/dist/wasm.js";
const aff = await (await fetch("/dictionaries/en.aff")).text();
const dic = await (await fetch("/dictionaries/en.dic")).text();
const dict = await createWasmDictionary(aff, dic);
if (dict) {
dict.correct("hello"); // true
dict.correct("helo"); // false
dict.suggest("hlelo", 3); // ["hello", "halo", "heel"]
} else {
// backend resolved to "http" — use the Client instead
}Choosing a backend
KOTOSHU_BACKEND | Behavior |
|---|---|
auto (the default) | wasm when import("@kotoshu/wasm") resolves, else HTTP |
native | force wasm — NativeUnavailableError when missing |
http | never wasm; the factory resolves null |
The option { backend } wins over the
environment variable. Like the Python package, the offline engine is word-level — no document
checking, no language detection. Errors are typed, with
KotoshuError as the base and
ResourceNotSetupError for the 422 case.
Verified 2026-09-05 — both quick starts executed against @kotoshu/client 0.1.0 and @kotoshu/wasm 0.1.0 on Node 24. Registry: @kotoshu/client on npm · @kotoshu/wasm on npm · kotoshu-js repo