-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
38 lines (34 loc) · 818 Bytes
/
utils.js
File metadata and controls
38 lines (34 loc) · 818 Bytes
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
const fs = require('fs');
const resultFolder = './result';
const MAX_LENGTH = 77;
const writeToFile = async (fileName, data) => {
fs.writeFile(`${resultFolder}/${fileName}`, JSON.stringify(data, null, 2), (err) =>
console.log(err),
);
};
const initResultFolder = () => {
if (!fs.existsSync(resultFolder)) {
fs.mkdirSync(resultFolder);
}
};
const processRawCards = (data, color, language) => {
let result = [];
Object.values(data)
.slice(0, 100)
.map((item, _) => {
if (item.text.length <= MAX_LENGTH) {
result.push({
color,
language,
text: item.text,
...(item.pick && item.pick <= 2 && { gaps: item.pick }),
});
}
});
return result;
};
module.exports = {
writeToFile,
initResultFolder,
processRawCards,
};