-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtextCleaner.js
31 lines (25 loc) · 872 Bytes
/
textCleaner.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
const path = require('path');
const fs = require('fs');
const filePath = path.join(__dirname, './text.txt');
const text = fs.readFileSync(filePath, 'utf8');
// ([a-zA-Z0-9()]{1,}){1,}\.(ru|com|net|org|eu)
const MARKER = '~^@~';
const format = (text) => {
const text1 = text
.replaceAll(/(\n|\r\n)\s/gm, MARKER)
.replaceAll(/(\n|\r\n)/gm, ' ')
.replaceAll(MARKER, '\n\n')
.replaceAll(/(\n).( )+/gm, '\n\t')
.replaceAll(/\-\-/gm, '—')
.replaceAll(/\.—/gm, '. —')
.replaceAll(/\,—/gm, ', —')
.replaceAll(/\!—/gm, ', —')
.replaceAll(/( )+/gm, ' ')
.replaceAll(/(\n){2,}/gm, '\n\n');
// .replaceAll(
// /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&\/=]*)/gm,
// '<a href="$&" target="_blank">$&</a>'
// );
return text1;
};
console.log(format(text));