28 lines
923 B
JavaScript
28 lines
923 B
JavaScript
'use strict';
|
|
|
|
const fs = require('fs').promises;
|
|
|
|
const words = require('./words.json');
|
|
const dictionary = require('./dictionary_old.json');
|
|
|
|
async function init() {
|
|
const notNameWords = words.filter((word) => word.charAt(0) === word.charAt(0).toLowerCase()); // don't include names for places, products, people, etc.
|
|
|
|
const definitions = Object.fromEntries(notNameWords.map((word) => {
|
|
const normalizedWord = word.normalize('NFD').replace(/\p{Diacritic}/ug, '').toLowerCase().trim();
|
|
const definition = dictionary[normalizedWord];
|
|
const singular = normalizedWord.replace(/s$/, '');
|
|
const singularDefinition = dictionary[singular];
|
|
|
|
return [normalizedWord, definition || singularDefinition || null];
|
|
}));
|
|
|
|
const string = JSON.stringify(definitions, null, 4);
|
|
|
|
await fs.writeFile('./dictionary.json', string);
|
|
|
|
console.log(`Wrote ${Object.keys(definitions).length} words to ./dictionary.json`);
|
|
}
|
|
|
|
init();
|