-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle-dictionaries.js
54 lines (45 loc) · 1.79 KB
/
bundle-dictionaries.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import {animals as animals1} from "./dictionaries/animals1.js";
import {animals as animals2} from "./dictionaries/animals2.js";
import {animals as animals3} from "./dictionaries/animals3.js";
import {adjectives as adjectives1} from "./dictionaries/adjectives1.js";
import {adjectives as adjectives2} from "./dictionaries/adjectives2.js";
import {adjectives as adjectives3} from "./dictionaries/adjectives3.js";
import fs from "fs/promises";
import path from "path";
await bundleJsons();
function getWords() {
const animals = new Set([
...handle(animals1),
...handle(animals2),
...handle(animals3),
]);
const adjectives = new Set([
...handle(adjectives1),
...handle(adjectives2),
...handle(adjectives3),
]);
return {animals: [...animals].sort(), adjectives: [...adjectives].sort()};
function handle(array) {
return array.map(el => el.toLowerCase().replaceAll(/[^a-z]/g, ""));
}
}
async function bundleJsons() {
const {animals, adjectives} = getWords();
logInfo({animals, adjectives});
const animalsJson = JSON.stringify(animals, null," ");
const adjectivesJson = JSON.stringify(adjectives, null," ");
const animalsWritten = fs.writeFile(path.join("dictionaries", "animals.json"), animalsJson);
const adjectivesWritten = fs.writeFile(path.join("dictionaries", "adjectives.json"), adjectivesJson);
return Promise.all([animalsWritten, adjectivesWritten]);
}
function logInfo({animals, adjectives}) {
console.log(animals1.length);
console.log(animals2.length);
console.log(animals3.length);
console.log(animals.length);
console.log();
console.log(adjectives1.length);
console.log(adjectives2.length);
console.log(adjectives3.length);
console.log(adjectives.length);
}