jmdict.js
v0.2.4
Published
jmdict.js is a library for working with JMdict
Downloads
12
Readme
jmdict.js
jmdict.js is a library for working with JMdict Japanese dictionary files and KanjiDic2 kanji dictionary files
Installation
You can install jmdict.js via npm:
npm install jmdict.js
Features
- Parse JMdict files and XML strings into typesafe objects
- Write JMdict objects to JSON files
- Parse KanjiDic2 files and XML strings into typesafe objects
- Write KanjiDic2 objects to JSON files
- CLI for converting JMdict files to JSON
Usage
Parsing a JMdict from an XML string
import { readFileSync } from 'fs';
import { JMdictParser } from 'jmdict.js';
const xmlString = readFileSync('pathToJMdictFile.xml', 'utf8');
const jmdict = await JMdictParser.fromXmlString(xmlString);
const entries = jmdict.entries;
Parsing a JMdict from a file
import { JMdictParser } from 'jmdict.js';
const jmdict = await JMdictParser.fromXmlFile('pathToJMdictFile.xml');
const entries = jmdict.entries;
Writing to a JSON file
import { JMdictParser } from 'jmdict.js';
const jmdict = await JMdictParser.fromXmlFile('pathToJMdictFile.xml');
jmdict.writeToJsonFile('pathToOutputFile.json');
KanjiDic2
The KanjiDic2 parser works just like the JMdict parser, but with the KanjiDicParser
class
Using the CLI
To convert a JMdict file to JSON, you can use the CLI:
jmdictjs convert -i pathToJMdictFile.xml -o pathToOutputFile.json
Converting KanjiDic2 files is not yet supported in the CLI