-
Notifications
You must be signed in to change notification settings - Fork 1
/
sortBkmk.js
33 lines (24 loc) · 1.01 KB
/
sortBkmk.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
const fs = require('fs');
const path = require('path');
const { getIndentLevel, removeLeadingNumbers, checkIndentErrors, checkDuplicateLines } = require('./util');
async function sortBkmk(inputFile) {
const file = fs.readFileSync(inputFile, 'utf8');
const lines = file.split('\r\n');
let outLines = [];
for (let line of lines) {
if (line.trim() === '') continue;
const [_, pageNum] = line.trim().split('\t');
outLines.push([line, Number(pageNum)]);
}
outLines = outLines.sort((a, b) => a[1] - b[1]).map(x => x[0]);
const outputFile = path.parse(inputFile).name + '_sorted.txt';
await fs.promises.writeFile(outputFile, outLines.join('\n'));
return outputFile;
}
(async () => {
const outputFile = await sortBkmk('FreePic2Pdf_bkmk.txt');
checkIndentErrors(outputFile);
checkDuplicateLines(outputFile);
})();
// checkIndentErrors('FreePic2Pdf_bkmk_sorted.txt', true);
// checkDuplicateLines('FreePic2Pdf_bkmk_sorted.txt');