-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-detect.js
38 lines (28 loc) · 1.11 KB
/
test-detect.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 { setLanguage, detectReferences, lookupReference}= require("./scriptures.js");
//clear console
console.clear();
const fs = require("fs");
const paramLang = process.argv[2] || "en";
const langs = fs.readdirSync(`${__dirname}/test/data`)
.filter(i=>/txt$/.test(i))
.map(i=>i.replace(".txt",""))
.filter(i=>{
if(!paramLang) return true;
if(paramLang && i===paramLang) return true
return false;
});
let callback = (string)=>{
const verse_ids = lookupReference(string);
console.log({string,verse_ids});
return `【❰ ${string} ❱】`
}
for(const lang of langs){
if(lang!=="en") setLanguage(lang);
let lines = fs.readFileSync(`${__dirname}/test/data/${lang}.txt`,"utf-8").split("\n").map(i=>i.trim()).filter(x=>!!x);
const hasAsterix = lines.some(i=>/^[*]/.test(i));
if(hasAsterix) lines = lines.filter(i=>/^[*]/.test(i)).map(i=>i.replace(/^[*]/,"").trim())
for(const line of lines){
const i = detectReferences(line,callback);
console.log([i]);
}
}