summaryrefslogtreecommitdiff
path: root/ext/bg/js/dictionary.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-04-17 18:13:20 -0700
committerAlex Yatskov <alex@foosoft.net>2016-04-17 18:13:20 -0700
commitf079db0471424a873f22315c7911571d467e97ad (patch)
tree96860218da185c478e269a7c12e6210ccba7ee3f /ext/bg/js/dictionary.js
parentbcd34149ab120f4bd0b823fbd6ae4efadfb02e90 (diff)
Support switching between edict and enamdict
Diffstat (limited to 'ext/bg/js/dictionary.js')
-rw-r--r--ext/bg/js/dictionary.js39
1 files changed, 14 insertions, 25 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index 6870601e..b91e53bf 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -31,35 +31,24 @@ class Dictionary {
this.kanjiDicts[name] = dict;
}
- findTerm(term) {
- let results = [];
-
- for (const name in this.termDicts) {
- const dict = this.termDicts[name];
- const indices = dict.indices[term] || [];
-
- results = results.concat(
- indices.map(index => {
- const [e, r, t, ...g] = dict.defs[index];
- return {id: index, expression: e, reading: r, glossary: g, tags: t.split(' ')};
- })
- );
- }
-
- return results;
+ findTerm(term, dict) {
+ const db = this.termDicts[dict];
+ const indices = db.indices[term] || [];
+
+ return indices.map(index => {
+ const [e, r, t, ...g] = db.defs[index];
+ return {id: index, expression: e, reading: r, glossary: g, tags: t.split(' ')};
+ });
}
- findKanji(kanji) {
- const results = [];
+ findKanji(kanji, dict) {
+ const def = this.termDicts[dict][kanji];
- for (const name in this.termDicts) {
- const def = this.termDicts[name][kanji];
- if (def) {
- const [c, k, o, g] = def;
- results.push({id: index, character: c, kunyomi: k, onyomi: o, glossary: g});
- }
+ if (def) {
+ const [c, k, o, g] = def;
+ return {id: index, character: c, kunyomi: k, onyomi: o, glossary: g};
}
- return results;
+ return null;
}
}