scripture-guide 1.0.43 → 1.0.45

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.
@@ -20,7 +20,6 @@ const findMatches = (content,books,lang_extra) => {
20
20
  return stringMatch;
21
21
  }).filter(x=>!!x);
22
22
 
23
-
24
23
  const bookSubStrings = fullBookMatches.map(bookMatch=>{
25
24
  const substrings = content.match(new RegExp(bookMatch,"ig")).flat();
26
25
  return substrings;
@@ -48,7 +47,12 @@ const findMatches = (content,books,lang_extra) => {
48
47
 
49
48
  const possiblyOverlappingMatches = bookSubStrings.map(([substring,positions])=>{
50
49
  return positions.map(i=>{
51
- const pattern = new RegExp(substring+postBookMatch,"ig");
50
+ let pattern = null;
51
+ try{
52
+ pattern = new RegExp(substring+postBookMatch,"ig");
53
+ }catch(e){
54
+ return null;
55
+ }
52
56
  const match = content.slice(i).match(pattern)?.[0]?.replace(tail,"").trim();
53
57
  if(!match) return null;
54
58
  const len = match.length;
@@ -88,8 +92,9 @@ const findMatches = (content,books,lang_extra) => {
88
92
 
89
93
 
90
94
  function findMatchIndexes(content, matches,lookupReference, lang_extra) {
91
- const tail = lang_extra.tail ? new RegExp(lang_extra.tail,"ig") : /[^0-9]+$/;
92
- const indexes = matches.map(i=>{
95
+ const tail = lang_extra.tail ? new RegExp(lang_extra.tail,"ig") : /[^,; 0-9]+$/;
96
+ const indexes = matches
97
+ .map(i=>{
93
98
  const length = i.length;
94
99
  let positions = [];
95
100
  let strPos = content.indexOf(i);
@@ -103,8 +108,9 @@ function findMatchIndexes(content, matches,lookupReference, lang_extra) {
103
108
  .map(a=>{
104
109
 
105
110
  const substring = content.substring(a[0],a[1]).replace(tail,"").trim();
111
+ if(!substring) return false;
106
112
  const verse_ids = lookupReference(substring).verse_ids;
107
- //console.log({a,substring,verse_ids});
113
+ console.log({a,substring,verse_ids});
108
114
  if(verse_ids.length > 0) return [a[0],a[0]+substring.length];
109
115
 
110
116
  return false;
@@ -168,6 +174,7 @@ function findMatchIndexes(content, matches,lookupReference, lang_extra) {
168
174
 
169
175
  const processReferenceDetection = (content,books,lang_extra,lookupReference,callback) =>
170
176
  {
177
+ try{
171
178
  lang_extra = lang_extra || {};
172
179
  const matches = findMatches(content,books,lang_extra);
173
180
 
@@ -258,7 +265,9 @@ const processReferenceDetection = (content,books,lang_extra,lookupReference,call
258
265
 
259
266
  return merged.join("");
260
267
 
261
-
268
+ }catch(e){
269
+ return content;
270
+ }
262
271
  }
263
272
 
264
273
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scripture-guide",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
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": {
@@ -188,7 +188,6 @@ var cleanReference = function cleanReference(messyReference) {
188
188
  //Turn dots into colons
189
189
  ref = ref.replace(/[.]/g, ":");
190
190
  //Treat commas as semicolons in the absence of verses
191
- if (!ref.match(/:/)) ref = ref.replace(/,/, "; ");
192
191
  //add spaces after semicolons
193
192
  ref = ref.replace(/;/g, "; ");
194
193
  //add space before numbers
@@ -233,10 +232,26 @@ var cleanReference = function cleanReference(messyReference) {
233
232
  ref = ref.replace(/\s+/g, " "); //remove double spaces
234
233
  ref = ref.replace(/\s*[~–-]\s*/g, "-"); //remove spaces around dashes
235
234
  ref = ref.replace(/;(\S+)/g, "; $1"); //add space after semicolons
236
-
235
+ console.log({
236
+ ref: ref
237
+ });
237
238
  var cleanReference = ref.trim();
239
+ cleanReference = handleSingleChapterBookRefs(cleanReference);
240
+ if (!cleanReference.match(/:/)) cleanReference = cleanReference.replace(/,/, "; ");
238
241
  return cleanReference;
239
242
  };
243
+ var handleSingleChapterBookRefs = function handleSingleChapterBookRefs(ref) {
244
+ var singleChapterBooks = Object.keys(raw_index).filter(function (book) {
245
+ return loadMaxChapter(book) == 1;
246
+ });
247
+ var matchingBooks = singleChapterBooks.filter(function (book) {
248
+ return ref.match(new RegExp("^".concat(book, " \\d+")));
249
+ });
250
+ ref = matchingBooks.reduce(function (ref, book) {
251
+ return ref.replace(new RegExp("^".concat(book, " (\\d+)")), "".concat(book, " 1:$1"));
252
+ }, ref);
253
+ return ref;
254
+ };
240
255
  var splitReferences = function splitReferences(compoundReference) {
241
256
  var refs = compoundReference.split(/\s*;\s*/);
242
257
  var runningBook = null;
package/scriptures.js CHANGED
@@ -185,7 +185,6 @@ const cleanReference = function(messyReference) {
185
185
  //Turn dots into colons
186
186
  ref = ref.replace(/[.]/g, ":");
187
187
  //Treat commas as semicolons in the absence of verses
188
- if (!ref.match(/:/)) ref = ref.replace(/,/, "; ");
189
188
  //add spaces after semicolons
190
189
  ref = ref.replace(/;/g, "; ");
191
190
  //add space before numbers
@@ -228,10 +227,25 @@ const cleanReference = function(messyReference) {
228
227
  ref = ref.replace(/\s+/g, " "); //remove double spaces
229
228
  ref = ref.replace(/\s*[~–-]\s*/g, "-"); //remove spaces around dashes
230
229
  ref = ref.replace(/;(\S+)/g, "; $1"); //add space after semicolons
230
+ console.log({ref});
231
231
 
232
232
  let cleanReference = ref.trim();
233
+
234
+ cleanReference = handleSingleChapterBookRefs(cleanReference);
235
+ if (!cleanReference.match(/:/)) cleanReference = cleanReference.replace(/,/, "; ");
236
+
233
237
  return cleanReference;
234
238
  }
239
+
240
+ const handleSingleChapterBookRefs = function(ref) {
241
+
242
+ const singleChapterBooks = Object.keys(raw_index).filter(book => loadMaxChapter(book) == 1);
243
+ const matchingBooks = singleChapterBooks.filter(book => ref.match(new RegExp(`^${book} \\d+`)));
244
+ ref = matchingBooks.reduce((ref,book) => ref.replace(new RegExp(`^${book} (\\d+)`),`${book} 1:$1`),ref);
245
+
246
+ return ref;
247
+ }
248
+
235
249
  const splitReferences = function(compoundReference) {
236
250
  let refs = compoundReference.split(/\s*;\s*/);
237
251
  let runningBook = null;
package/test/data/en.txt CHANGED
@@ -24,4 +24,6 @@ There is a difference between being reconciled to the will of God (accepting the
24
24
  Note Source
25
25
  WB includes “hindrance, opposition,” though both Jacob and Nephi knew of Jesus’s future crucifixion; see 2 Nephi 6.9;1 Ne 11.33;19.10.
26
26
  “Everlasting death” • Here and in 2 Nephi 10:23, can be contrasted with the temporary death that everyone will experience and then be rescued from by the Resurrection. Elsewhere the BoM uses the term “second death” to describe the post-resurrection, post-judgment separation from God that will never end (e.g., Alma 12.32: “a second death, which was an everlasting death”).
27
- The combination of repentance, baptism, faith, and enduring to the end (along with the Holy Ghost) is identified as the doctrine of Christ at 2 Nephi 31.2–21, and the essence of the gospel at 3 Ne 27.13–22. Although Jacob in these two verses, and later Nephi (in ch. 31), speaks in general, abstract terms about baptism, there are no recorded baptisms in the BoM until Alma baptizes at Mos 18, nearly four hundred years later, where the practice appears to be something new.
27
+ The combination of repentance, baptism, faith, and enduring to the end (along with the Holy Ghost) is identified as the doctrine of Christ at 2 Nephi 31.2–21, and the essence of the gospel at 3 Ne 27.13–22. Although Jacob in these two verses, and later Nephi (in ch. 31), speaks in general, abstract terms about baptism, there are no recorded baptisms in the BoM until Alma baptizes at Mos 18, nearly four hundred years later, where the practice appears to be something new.
28
+ <p>In the Joseph Smith Translation of the Bible, we read that “the Lord hath visited” Joseph, the son of Jacob spoken of in the Old Testament, and that Joseph was given great promises concerning his posterity (JST, Genesis 50:24). As Lehi testified, “Joseph truly saw our day” (2 Nephi 3:5), meaning the day of Lehi and his posterity, and knew that in the future God would raise up “a choice seer” (verse 7), namely the great prophet who was his namesake (see verse 15). Joseph knew also that it would be primarily his descendants whom the Lord would call upon first in these last days to carry the gospel to additional lost members of the house of Israel scattered among the nations of the earth, in compliance with the covenant God made with Abraham (see Bible Dictionary, “Joseph,” 716–17; Guide to the Scriptures, “Joseph, Son of Jacob”). Obviously, since the Lord kept His covenant with Joseph, He will also keep His covenants with us if we are righteous as well.</p><p>Lehi’s teaching is a great example of how Heavenly Father honored the covenant He made with Joseph. We can have the confidence that God will always honor His covenants.</p>
29
+ *It is well to remember that the word Nephite apparently had a different meaning near the close of the Book of Mormon than it did before A.D. 231. (See 4 Nephi 20, 36-39.) From approximately 544 B.C. to A.D. 34 (Jacob 1:13-14) the term Nephite referred either to the descendants of Nephi and those who went with him into the wilderness (2 Nephi 5:5-8) or to those who joined with this group. From about A.D. 34 to nearly A.D. 194, there were not “any manner of -ites” among the descendants of Lehi. (4 Nephi 17.) By A.D. 194, however, a group of people revolted from the church and took upon themselves the name of Lamanites (4 Nephi 20), and by A.D. 231 those who had remained true to the church became known as Nephites (4 Nephi 36). For the remainder of the Book of Mormon, the term Nephite apparently refers to the descendants of those who had been faithful in A.D. 231.