-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (29 loc) · 1.12 KB
/
index.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
const fs = require('fs');
module.exports = { findwordpronounce: findWordPronounce };
function findWordPronounce(word) {
//read word list
let words = JSON.parse(fs.readFileSync('./library/words.json').toString());
//get word id
let worddata = Object.entries(words).filter(([key, value]) => value === word);
//check to see if word exists
if (typeof worddata[0] != 'undefined') {
words = null; //free memory
//load pronunciation map
let pronunciations = JSON.parse(fs.readFileSync('./library/pronunciation.json').toString());
let wordpronunciations = [];
worddata.map((item) => {
if (typeof pronunciations[item[0]] != 'undefined')
wordpronunciations = [...wordpronunciations, ...pronunciations[item[0]]];
});
wordpronunciations = [...new Set(wordpronunciations)];
pronunciations = null; //free memory
//pronunciation exists
if (typeof wordpronunciations != 'undefined') {
return wordpronunciations;
} else {
return undefined;
}
} else {
return undefined;
}
};