-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonUtils.js
39 lines (32 loc) · 905 Bytes
/
jsonUtils.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
let fs = require("fs");
const FILE = "dictionary.json";
const loadDictionary = () => {
const file_content = fs.readFileSync(FILE);
const json = JSON.parse(file_content);
return json;
};
const savedCommands = () => {
const file_content = fs.readFileSync(FILE);
const json = JSON.parse(file_content);
return json.saved;
};
const commandsRegex = () => {
const file_content = fs.readFileSync(FILE);
const json = JSON.parse(file_content);
return json.regex;
};
const saveNewSuggestedCommand = (suggested, realCommand) => {
const file_content = fs.readFileSync(FILE);
const json = JSON.parse(file_content);
json.saved[suggested] = realCommand;
const newDictionary = JSON.stringify(json, null, 2);
fs.writeFile(FILE, newDictionary, (err) => {
if (err) throw err;
});
};
module.exports = {
loadDictionary,
savedCommands,
commandsRegex,
saveNewSuggestedCommand,
};