Files
kpl20/clean.ts
Joey Eamigh be3a13eee1 happy bday!
2024-05-26 22:45:45 -04:00

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));