Skip to content

Commit

Permalink
Merge pull request #27 from MarvNC:support-export-index-from-dictionary
Browse files Browse the repository at this point in the history
Support Export Index from `Dictionary`
  • Loading branch information
MarvNC authored Jul 24, 2024
2 parents 5221fa9 + bb5c49e commit d3af9bc
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit d3af9bc

Please sign in to comment.