-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconvert-rst.js
32 lines (28 loc) · 994 Bytes
/
convert-rst.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
const fs = require('fs');
const csv = require('csvtojson');
const bookRefs = require('./lib/en/bookRefs').bookRefs;
const bookNames = require('./lib/en/bookNames').bookNames;
const TRANSLATION = 'RST';
const HEADERS = ['book', 'chapter', 'verse', 'text'];
const USFM_FILE = 'usfm/' + TRANSLATION.toLowerCase() + '.usfm';
const JSON_FILE = 'json/' + TRANSLATION.toLowerCase() + '.json';
const csvStream = csv({ delimiter: '\t', headers: HEADERS })
.transf(json => {
json.translation_id = TRANSLATION;
json.chapter = Number(json.chapter);
json.verse = Number(json.verse);
json.book_id = bookRefs[json.book];
json.book_name = bookNames[json.book];
delete json['book'];
})
.on('done', error => {
if (error) {
console.error('Error parsing file: ', error);
}
else {
console.log('Parsing finished sucessfully.');
}
});
const readStream = fs.createReadStream(USFM_FILE);
const writeStream = fs.createWriteStream(JSON_FILE);
readStream.pipe(csvStream).pipe(writeStream);