Skip to content

Commit

Permalink
Typed add kanji
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvNC committed Mar 10, 2024
1 parent 396498e commit 6ff5517
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
14 changes: 14 additions & 0 deletions examples/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ const {
{ jis213: '2-04-06', skip: '1-3-8', strokes: '11', ucs: '35A8' },
]);

dictionary.addKanji({
kanji: '読',
kunyomi: 'あ',
onyomi: 'ア',
meanings: ['Asia'],
stats: {
strokes: '7',
grade: '8',
},
});
dictionary.addKanji({
kanji: '詠',
});

const kanjiEntry = new KanjiEntry('亜')
.setKunyomi('あ')
.setOnyomi('ア')
Expand Down
28 changes: 26 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
import {
DictionaryKanjiBankV3,
KanjiInformation,
KanjiStats,
} from './types/yomitan/kanjibank';
import {
DictionaryKanjiMetaBankV3,
Expand Down Expand Up @@ -170,8 +171,31 @@ export class Dictionary {
* Adds a kanji to the dictionary
* @param kanji - The kanji to add
*/
async addKanji(kanji: KanjiInformation) {
this.kanjiBank.push(kanji);
async addKanji(
kanji:
| KanjiInformation
| {
kanji: string;
onyomi?: string;
kunyomi?: string;
tags?: string;
meanings?: string[];
stats?: KanjiStats;
},
) {
let array: KanjiInformation = Array.isArray(kanji)
? kanji
: [
kanji.kanji,
kanji.onyomi ?? '',
kanji.kunyomi ?? '',
kanji.tags ?? '',
kanji.meanings ?? [],
kanji.stats ?? {},
];
// If kanji is KanjiInformation array

this.kanjiBank.push(array);
this.stats.kanjiCount++;
if (this.kanjiBank.length >= this.options.termBankMaxSize) {
await this.saveKanjiBank();
Expand Down

0 comments on commit 6ff5517

Please sign in to comment.