18 lines
703 B
TypeScript
18 lines
703 B
TypeScript
import dictionary from './en_eo_dict.json' assert { type: 'json' };
|
|
|
|
const wordRegex = /^[a-z]+$/;
|
|
const cleanDict = dictionary
|
|
.filter(({ word }) => wordRegex.test(word))
|
|
.filter(({ translation }) => wordRegex.test(translation))
|
|
.filter((e) => e.snc_index === null)
|
|
.reduce((acc, cur) => {
|
|
const wordExists = acc.some((item) => item.word === cur.word);
|
|
const translationExists = acc.some((item) => item.translation === cur.translation);
|
|
if (wordExists || translationExists) return acc;
|
|
|
|
return [...acc, cur];
|
|
}, [] as typeof dictionary)
|
|
.map(({ word, translation }) => ({ word, translation }));
|
|
|
|
await Bun.write('en_eo_dict_clean.json', JSON.stringify(cleanDict, null, 2));
|