From bb5c49e1aaa22f34f1a38075416adf20177a73d3 Mon Sep 17 00:00:00 2001 From: MarvNC Date: Tue, 23 Jul 2024 21:12:09 -0700 Subject: [PATCH] Support Export Index from `Dictionary` --- src/index.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index bdb705c..85fdff4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,6 +37,7 @@ import { TagOption, } from './types/yomitan/tagbank'; import path from 'path'; +import { DictionaryIndex } from './builders/dictionaryIndex'; const INDEX_FILE_NAME = 'index.json'; const TERM_BANK_FILE_NAME = (bankNumber: number) => @@ -86,11 +87,20 @@ export class Dictionary { * @param index - JSON object * @returns */ - async setIndex(index: DictionaryIndexType) { + async setIndex( + index: DictionaryIndexType, + directory: string = './', + fileName: string = 'index.json', + ) { if (!index.format) { index.format = 3; } await this.saveJsonToZip(INDEX_FILE_NAME, index); + + if (directory || fileName) { + const indexBuilder = new DictionaryIndex(index); + await indexBuilder.export(directory, fileName); + } return this; }