-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (45 loc) · 1.2 KB
/
app.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
import {
readDir,
filterByExtension,
readFiles,
convertFilesFormat,
getKey,
removeHTMLTags,
removeEmptylines,
removeChars,
removeFolder,
splitByWords,
countWords,
sortBy,
saveAs
} from './functions.js'
import path from 'node:path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const dataDir = path.join(__dirname,'data','files');
const saveDataOutPut = path.join(__dirname,'output','files');
const chars = ['(',')','[',']','*','-',',',':','.','"','\'','?'];
const joinContent = content => content.join('\n');
const splitLines = fullText => fullText.split('\n');
try {
readDir(dataDir)
.then(filterByExtension('json'))
.then(removeFolder(dataDir))
.then(readFiles(dataDir))
.then(convertFilesFormat)
.then(getKey)
.then(joinContent)
.then(splitLines)
.then(removeEmptylines)
.then(removeHTMLTags)
.then(removeChars(chars))
.then(splitByWords)
.then(countWords)
.then(sortBy('count'))
.then(saveAs(saveDataOutPut))
.then(console.log)
.catch(err => console.log('err:',err));
} catch (err) {
console.error(err);
}