scripture-guide 1.0.25 → 1.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/data/scriptdetect.js +1 -0
- package/package.json +1 -1
- package/scriptures-compiled.js +22 -4
- package/scriptures.js +26 -8
- package/test-detect.js +3 -2
package/README.md
CHANGED
package/data/scriptdetect.js
CHANGED
|
@@ -12,6 +12,7 @@ const prepareBlacklist = (lang_extras) => {
|
|
|
12
12
|
blacklist.push("\\b(AC3|PS2|PS3|PS4)\\b"); //Common file extentions
|
|
13
13
|
blacklist.push("\\b(ps|PS)[1-9]\\b"); //Common file extentions'
|
|
14
14
|
|
|
15
|
+
|
|
15
16
|
var blacklist_pattern = new RegExp("(" + blacklist.join("|") + ")", 'g');
|
|
16
17
|
|
|
17
18
|
return blacklist_pattern;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scripture-guide",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"description": "A utility for biblical and scripture reference parsing that enables structured queries based on strings of traditional scripture references (e.g. John 3:16). ",
|
|
5
5
|
"main": "scriptures-compiled.js",
|
|
6
6
|
"scripts": {
|
package/scriptures-compiled.js
CHANGED
|
@@ -522,6 +522,9 @@ var detectReferences = function detectReferences(content, callBack) {
|
|
|
522
522
|
callBack = callBack ? callBack : function (i) {
|
|
523
523
|
return "[".concat(i, "]");
|
|
524
524
|
};
|
|
525
|
+
var trimExternalMatchStrings = function trimExternalMatchStrings(i) {
|
|
526
|
+
return i.trim().replace(/^[^0-9]*\(/g, '').replace(/\)[^0-9]*$/g, '').replace(/[,;!?.()]+$/ig, "").replace(/^[,;!?.()]+/ig, " ").trim();
|
|
527
|
+
};
|
|
525
528
|
var hasNoAlpha = !/[A-Za-z]/.test(content);
|
|
526
529
|
if (hasNoAlpha && wordBreak) wordBreak = "";
|
|
527
530
|
var src = raw_regex.books.map(function (i) {
|
|
@@ -538,11 +541,26 @@ var detectReferences = function detectReferences(content, callBack) {
|
|
|
538
541
|
var matches = ((_content$match = content.match(pattern)) === null || _content$match === void 0 ? void 0 : _content$match.filter(function (i) {
|
|
539
542
|
return !blacklist_pattern.test(i);
|
|
540
543
|
})) || [];
|
|
541
|
-
matches = matches.map(
|
|
542
|
-
|
|
544
|
+
matches = matches.map(trimExternalMatchStrings);
|
|
545
|
+
matches = matches.filter(function (i) {
|
|
546
|
+
return i.length <= 1000;
|
|
547
|
+
});
|
|
548
|
+
console.log({
|
|
549
|
+
matches: matches
|
|
543
550
|
});
|
|
544
|
-
|
|
545
|
-
|
|
551
|
+
|
|
552
|
+
// split by matches
|
|
553
|
+
var pieces;
|
|
554
|
+
try {
|
|
555
|
+
pieces = matches.length ? content.split(new RegExp("(".concat(matches.join("|"), ")"), "ig")) : [content];
|
|
556
|
+
} catch (error) {
|
|
557
|
+
console.error(error);
|
|
558
|
+
console.log({
|
|
559
|
+
matches: matches,
|
|
560
|
+
pattern: pattern
|
|
561
|
+
});
|
|
562
|
+
return content;
|
|
563
|
+
}
|
|
546
564
|
content = pieces.map(function (i, j) {
|
|
547
565
|
if (j % 2 == 0) return i;
|
|
548
566
|
return callBack(i);
|
package/scriptures.js
CHANGED
|
@@ -506,6 +506,13 @@ const detectReferences = (content,callBack,wordBreak="\\b") => {
|
|
|
506
506
|
|
|
507
507
|
callBack = callBack ? callBack : (i)=>{return `[${i}]`};
|
|
508
508
|
|
|
509
|
+
const trimExternalMatchStrings = (i) => i.trim().
|
|
510
|
+
replace(/^[^0-9]*\(/g, '').
|
|
511
|
+
replace(/\)[^0-9]*$/g, '').
|
|
512
|
+
replace(/[,;!?.()]+$/ig, "").
|
|
513
|
+
replace(/^[,;!?.()]+/ig, " ").
|
|
514
|
+
trim();
|
|
515
|
+
|
|
509
516
|
const hasNoAlpha = !/[A-Za-z]/.test(content);
|
|
510
517
|
if(hasNoAlpha && wordBreak) wordBreak = "";
|
|
511
518
|
|
|
@@ -514,15 +521,26 @@ const detectReferences = (content,callBack,wordBreak="\\b") => {
|
|
|
514
521
|
const bookMatchList = [...dst, ...src].map(i => [i]);
|
|
515
522
|
const pattern = preparePattern(bookMatchList,wordBreak,lang_extra);
|
|
516
523
|
const blacklist_pattern = prepareBlacklist();
|
|
517
|
-
var matches = content.match(pattern)?.filter(i
|
|
518
|
-
matches = matches.map(
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
+
var matches = content.match(pattern)?.filter(i => !blacklist_pattern.test(i)) || [];
|
|
525
|
+
matches = matches.map(trimExternalMatchStrings)
|
|
526
|
+
matches = matches.filter(i => i.length <= 1000);
|
|
527
|
+
|
|
528
|
+
console.log({matches});
|
|
529
|
+
|
|
530
|
+
// split by matches
|
|
531
|
+
let pieces;
|
|
532
|
+
try {
|
|
533
|
+
pieces = matches.length ? content.split(new RegExp(`(${matches.join("|")})`, "ig")) : [content];
|
|
534
|
+
} catch (error) {
|
|
535
|
+
console.error(error);
|
|
536
|
+
console.log({matches,pattern});
|
|
537
|
+
return content;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
content = pieces.map((i, j) => {
|
|
541
|
+
if (j % 2 == 0) return i;
|
|
524
542
|
return callBack(i);
|
|
525
|
-
}).join("").replace(/\s+/g," ").trim();
|
|
543
|
+
}).join("").replace(/\s+/g, " ").trim();
|
|
526
544
|
|
|
527
545
|
return content;
|
|
528
546
|
}
|
package/test-detect.js
CHANGED
|
@@ -5,7 +5,8 @@ const {lookup, generateReference, setLanguage, detectReferences}= require("./scr
|
|
|
5
5
|
const lines = [
|
|
6
6
|
"Please refer to Genesis 20 in the bible",
|
|
7
7
|
"Please refer to 3 Nephi 5:1-3 in the Book of Mormon",
|
|
8
|
-
"For example, in Matthew 27:51, the earth quakes and ro"
|
|
8
|
+
"For example, in Matthew 27:51, the earth quakes and ro",
|
|
9
|
+
"It aligns with other scriptures (3 Nephi 12:2, Mosiah 18:13, Moses 6:52).",
|
|
9
10
|
]
|
|
10
11
|
|
|
11
12
|
lines.forEach(l=>{
|
|
@@ -13,7 +14,7 @@ lines.forEach(l=>{
|
|
|
13
14
|
console.log({result});
|
|
14
15
|
});
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
process.exit(0);
|
|
17
18
|
|
|
18
19
|
setLanguage("ko");
|
|
19
20
|
|