@runer-hq/mdict
v0.1.0
Published
Rust-powered MDict (*.mdx, *.mdd) reader — napi-rs binding
Downloads
112
Readme
MDict Node.js Binding (Rust)
Native Node.js binding for reading MDict dictionary files (*.mdx, *.mdd). Built with napi-rs for near-zero overhead Rust interop. A drop-in Rust-powered replacement for js-mdict.
Install
npm install @runer-hq/mdictQuick Start
const { Mdx, Mdd } = require('@runer-hq/mdict');
// Open a dictionary
const mdx = new Mdx('/path/to/dict.mdx');
// Look up a word
const result = mdx.lookup('apple');
console.log(result.keyText); // "apple"
console.log(result.definition); // HTML definition string
// Prefix search (autocomplete)
const suggestions = mdx.prefix('app', 10);
// [{ keyText: "app" }, { keyText: "apple" }, { keyText: "apply" }, ...]
// Fuzzy search (spell correction)
const fuzzy = mdx.fuzzySearch('aple', 5, 2);
// [{ keyText: "apple", ed: 1 }, { keyText: "aple", ed: 0 }, ...]
// Read resources from .mdd
const mdd = new Mdd('/path/to/dict.mdd');
const css = mdd.readMedia('\\style.css');
console.log(css.mimeType); // "text/css; charset=utf-8"
console.log(css.data); // BufferCLI
# Install globally
npm install -g @runer-hq/mdict
# Look up a word
mdict /path/to/dict.mdx apple
# Read a resource
mdict /path/to/dict.mdd \style.cssDocumentation
Full API reference, data structures, and usage examples: USAGE.md.
Build
cargo build --release -p mdict-node
cp target/release/libmdict_node.* crates/mdict-node/mdict.<platform>-<arch>.node
node node/test.jsRequirements
- Rust ≥ 1.74 (edition 2021)
- Node.js ≥ 18 (LTS recommended)
TypeScript Types
Full TypeScript type definitions in index.d.ts.
Architecture
src/lib.rs— napi-rs Rust binding (Mdx, Mdd classes + standalone functions)index.js— JS wrapper (loads platform-specific.nodebinary)index.d.ts— TypeScript type declarationscli.js— Command-line interface
Performance
Compared to the original js-mdict (TypeScript):
| Operation | js-mdict | Rust binding | Speedup | |-----------|----------|--------------|---------| | Load | 299 ms | 223 ms | 1.3× | | lookup | 4,536 ops/s | 4,973 ops/s | 1.1× | | prefix | 18 ops/s | 134 ops/s | 7.4× | | contains | 10,782 ops/s | 28,342 ops/s | 2.6× |
Low-memory mode loads in 2 ms (vs 223 ms eager) by deferring key block decoding.
