Skip to content

Commit d3af9bc

Browse files
authored
Merge pull request #27 from MarvNC:support-export-index-from-dictionary
Support Export Index from `Dictionary`
2 parents 5221fa9 + bb5c49e commit d3af9bc

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/index.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
TagOption,
3838
} from './types/yomitan/tagbank';
3939
import path from 'path';
40+
import { DictionaryIndex } from './builders/dictionaryIndex';
4041

4142
const INDEX_FILE_NAME = 'index.json';
4243
const TERM_BANK_FILE_NAME = (bankNumber: number) =>
@@ -86,11 +87,20 @@ export class Dictionary {
8687
* @param index - JSON object
8788
* @returns
8889
*/
89-
async setIndex(index: DictionaryIndexType) {
90+
async setIndex(
91+
index: DictionaryIndexType,
92+
directory: string = './',
93+
fileName: string = 'index.json',
94+
) {
9095
if (!index.format) {
9196
index.format = 3;
9297
}
9398
await this.saveJsonToZip(INDEX_FILE_NAME, index);
99+
100+
if (directory || fileName) {
101+
const indexBuilder = new DictionaryIndex(index);
102+
await indexBuilder.export(directory, fileName);
103+
}
94104
return this;
95105
}
96106

0 commit comments

Comments
 (0)