mdict (*.mdd *.mdx) file reader based on jeka-kiselyov/mdict .
Very thanks to fengdh and jeka-kiselyov.
v6.0.0-alpha-2
NOTE: Not Support Browser!
npm install js-mdict@v6.0.0-alpha-2
file: demo.mjs
import { Mdict } from "js-mdict";
const mdict = new Mdict("resources/oald7.mdx");
const def = mdict.lookup("ask");
console.log(def.definition);
/*
<head><link rel="stylesheet" type="text/css" href="https://github.com/terasum/js-mdict/blob/master/O7.css"/></head><body><span class="hw"> ask </span hw><span class="i_g"> <img src="https://github.com/terasum/js-mdict/raw/master/key.gif"/> /<a class="i_phon" href="https://github.com/terasum/js-mdict/blob/master/sound://aask_ggv_r1_oa013910.spx">ɑ:sk</a i_phon><span class="z">; </span z><i>NAmE</i> <a class="y_phon" href="https://github.com/terasum/js-mdict/blob/master/sound://aask_ggx_r1_wpu01057.spx">æsk</a y_phon>/ </span i_g><span class="cls"> verb</span cls><br><span class="sd">QUESTION<span class="chn"> 问题</span chn></span sd>
<div class="define"><span class="numb">1</span numb><span class="cf"> ~ <span class="bra">(</span bra>sb<span class="bra">)</span bra> <span class="bra">(</span bra>about sb/ sth<span class="bra">)</span bra> </span cf><span class="d">to say or write sth in the form of a question, in order to get information<span class="chn"> 问;询问</span chn></span d></div define>
<span class="phrase"><span class="pt"> [<span class="pt_inside">V <span class="pt_bold">speech</span></span><span>]</span> </span pt></span phrase>
<span class="sentence_eng">'Where are you going?' she asked. </span sentence_eng>
<span class="sentence_chi">"你去哪里?"她问道。</span sentence_chi>
<span class="phrase"><span class="pt"> [<span class="pt_inside">VN <span class="pt_bold">speech</span></span><span>]</span> </span pt></span phrase>
<span class="sentence_eng">'Are you sure?' he asked her. </span sentence_eng>
...
</body>
*/
file: demo.mjs
const { Mdict } = require('js-mdict');
const mdict = new Mdict('resources/oald7.mdx');
const def = mdict.lookup('ask');
console.log(def.definition);
/*
<head><link rel="stylesheet" type="text/css" href="https://github.com/terasum/js-mdict/blob/master/O7.css"/></head><body><span class="hw"> ask </span hw><span class="i_g"> <img src="https://github.com/terasum/js-mdict/raw/master/key.gif"/> /<a class="i_phon" href="https://github.com/terasum/js-mdict/blob/master/sound://aask_ggv_r1_oa013910.spx">ɑ:sk</a i_phon><span class="z">; </span z><i>NAmE</i> <a class="y_phon" href="https://github.com/terasum/js-mdict/blob/master/sound://aask_ggx_r1_wpu01057.spx">æsk</a y_phon>/ </span i_g><span class="cls"> verb</span cls><br><span class="sd">QUESTION<span class="chn"> 问题</span chn></span sd>
<div class="define"><span class="numb">1</span numb><span class="cf"> ~ <span class="bra">(</span bra>sb<span class="bra">)</span bra> <span class="bra">(</span bra>about sb/ sth<span class="bra">)</span bra> </span cf><span class="d">to say or write sth in the form of a question, in order to get information<span class="chn"> 问;询问</span chn></span d></div define>
<span class="phrase"><span class="pt"> [<span class="pt_inside">V <span class="pt_bold">speech</span></span><span>]</span> </span pt></span phrase>
<span class="sentence_eng">'Where are you going?' she asked. </span sentence_eng>
<span class="sentence_chi">"你去哪里?"她问道。</span sentence_chi>
<span class="phrase"><span class="pt"> [<span class="pt_inside">VN <span class="pt_bold">speech</span></span><span>]</span> </span pt></span phrase>
<span class="sentence_eng">'Are you sure?' he asked her. </span sentence_eng>
...
</body>
*/
use oale8.mdx as an example:
Mdict#loading time: 0 sec
Mdict#lookup x 1,967 ops/sec ±0.95% (97 runs sampled)
Mdict#prefix x 1,800 ops/sec ±0.70% (96 runs sampled)
Mdict#fuzzy_search x 285 ops/sec ±14.03% (77 runs sampled)
Mdict#associate x 2,059 ops/sec ±4.53% (89 runs sampled)
Fastest is Mdict#associate
depreciate if you use js-mdict @2.0.3, you can use api shown below:
Note: 2.0.3 not supports mdd file, and record info encrypted file
import path from 'path';
import Mdict from 'js-mdict';
const dictPath = path.join(__dirname, '../resource/Collins.mdx');
const mdict = new Mdict(dictPath);
mdict
.build()
.then((_mdict) => {
console.log('hello', _mdict.lookup('hello'));
console.log('world', _mdict.lookup('world'));
console.log(_mdict.attr());
})
.catch((err) => {
console.error(err);
});
BREAKING CHANGES:
NOTE: This version has a lot of changes, please read the example code example carefully!
注意: 本版本改动了多个 API, 请仔细阅读上方的示例代码。
BREAKING CHANGES:
suggest
method has been deprecated.parse_definition
method has been deprecated, use fetch_definition
insteadnspell
and en-dictionary-us
dependencieskeyInfoBlock.firstKey/lastKey
to locate recordBlock
TextDecoder
and zlib
, instead of third party TextDecoder
and pako
.findList
return undefined
will crash the associate
and prefix
method bugvery thanks to @songxiaocheng
.mdd
file reading issues, and if you search mdd file, use lookup
method, and it will return base64 datatypings/mdict.d.ts
typings/Mdict.d.ts
to typings/mdict.d.ts
out of index error
when cannot locate word offsetundefined
associate
(the phrase as the words' prefix, not the phrase's prefix as search token just like prefix
function)very thanks to @Danjame
fuzzy_search
method, which supports fuzzy word searchthis picture is from @ikey4u/wikit
code by terasum with ❤️