UNPKG

js-mdict

Version:

mdict (*.mdx, *.mdd) file reader. Licensed under AGPL-3.0 for better community cooperation and commercial value protection.

36 lines 1.09 kB
import { Mdict } from './mdict.js'; const BASE64ENCODER = function (arrayBuffer) { return Buffer.from(arrayBuffer).toString('base64'); }; export class MDD extends Mdict { /** * locate the resource key * @param resourceKey resource key * @returns the keyText and definition */ locate(resourceKey) { let normalizedKey = resourceKey.replace(/\//g, '\\'); if (normalizedKey.length > 0 && !normalizedKey.startsWith('\\')) { normalizedKey = '\\' + normalizedKey; } const item = this.lookupKeyBlockByWord(normalizedKey); if (!item) { return { keyText: resourceKey, definition: null }; } const meaningBuff = this.lookupRecordByKeyBlock(item); if (!meaningBuff) { return { keyText: resourceKey, definition: null }; } return { keyText: resourceKey, definition: BASE64ENCODER(meaningBuff) }; } } //# sourceMappingURL=mdd.js.map