scripture-guide 1.0.91 → 1.0.92

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.
@@ -1,4 +1,4 @@
1
- /* scripture-guide v1.0.91 */
1
+ /* scripture-guide v1.0.92 */
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -31610,7 +31610,9 @@ var findMatches = (content, books, lang_extra) => {
31610
31610
  const tail = lang_extra.tail ? new RegExp(lang_extra.tail, "ig") : /[^0-9]+$/;
31611
31611
  const preBookMatch = lang_extra.book || `(First|I|1|1st|Second|II|2|2nd|Third|III|3|3rd|Fourth|IV|4|4th)*\\s*(books* of)*\\s*`;
31612
31612
  const matchingBooks = findMatchingBooks(normalizedContent, books);
31613
- const postBookMatch = lang_extra.chapter || "([0-9:.;,~ \u2014\u2013-]|cf)*[0-9]+";
31613
+ const gap = "[ \\t]*(?:\\n(?![ \\t]*\\n)[ \\t]*)?(?:,[ \\t]*sec(?:tion)?\\.?[ \\t]*)?\\(?[ \\t]*(?=[0-9])";
31614
+ const core = "(?:[0-9:.;,~\u2014\u2013-]|[ \\t]|\\n(?![ \\t]*\\n)|and\\b|cf\\b|\\()*[0-9]";
31615
+ const postBookMatch = lang_extra.chapter || gap + core;
31614
31616
  const fullBookMatches = matchingBooks.map((bookMatch) => {
31615
31617
  const patternString = preBookMatch + bookMatch;
31616
31618
  const pattern = new RegExp(patternString, "ig");
@@ -31668,7 +31670,7 @@ var findMatches = (content, books, lang_extra) => {
31668
31670
  return newString.replace(tail, "").trim();
31669
31671
  }).filter((i) => !!i);
31670
31672
  const matches = matchesWithReferences.map((string) => {
31671
- const pattern = new RegExp(string, "ig");
31673
+ const pattern = new RegExp(string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "ig");
31672
31674
  const matches2 = normalizedContent.match(pattern)?.map((i) => i.trim().replace(tail, ""));
31673
31675
  return matches2;
31674
31676
  }).flat().reduce((prev, current) => {
@@ -32244,6 +32246,9 @@ var strToHash = function(str) {
32244
32246
  };
32245
32247
  var cleanReference = function(messyReference, config) {
32246
32248
  let ref = messyReference.replace(/[\s]+/g, " ").trim();
32249
+ ref = ref.replace(/(\d)\s+and\s+(\d)/g, "$1,$2");
32250
+ ref = ref.replace(/[()]/g, " ");
32251
+ ref = ref.replace(/\bsec(?:tion)?\b\.?/ig, " ");
32247
32252
  let regex = config.raw_regex.pre_rules;
32248
32253
  for (let i in regex) {
32249
32254
  var re = new RegExp(regex[i].pattern ?? regex[i][0], "ig");
@@ -32617,15 +32622,78 @@ var findReferences = (content, options = null) => {
32617
32622
  const books = [...dst, ...src];
32618
32623
  const lookup = (query) => lookupReference(query, effectiveLanguage);
32619
32624
  const found = finalOptions.contextAware ? collectReferencesWithContext(content, books, config.lang_extra, lookup, finalOptions) : collectReferences(content, books, config.lang_extra, lookup);
32620
- const records = found.filter((m) => m.verse_ids.length > 0).map(({ start, end, text, verse_ids }) => ({
32625
+ let records = found.filter((m) => m.verse_ids.length > 0).map(({ start, end, text, verse_ids }) => ({
32621
32626
  start,
32622
32627
  end,
32623
32628
  text,
32624
32629
  verse_ids,
32625
32630
  ref: generateReference(verse_ids, effectiveLanguage)
32626
32631
  }));
32632
+ const spelled = collectSpelledOut(content, lookup, effectiveLanguage).filter((sp) => !records.some((r) => sp.start < r.end && r.start < sp.end));
32633
+ if (spelled.length) {
32634
+ records = [...records, ...spelled].sort((a, b) => a.start - b.start);
32635
+ }
32627
32636
  return applyDetectionFlags(records, finalOptions);
32628
32637
  };
32638
+ var ORDINAL_ONES = ["zeroth", "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth"];
32639
+ var ORDINAL_TEENS = { tenth: 10, eleventh: 11, twelfth: 12, thirteenth: 13, fourteenth: 14, fifteenth: 15, sixteenth: 16, seventeenth: 17, eighteenth: 18, nineteenth: 19 };
32640
+ var ORDINAL_TENS = { twentieth: 20, thirtieth: 30 };
32641
+ var CARDINAL_TENS = { twenty: 20, thirty: 30 };
32642
+ var ORDINAL_WORD_RE = "(?:twenty-(?:first|second|third|fourth|fifth|sixth|seventh|eighth|ninth)|thirty-(?:first|second|third|fourth|fifth|sixth|seventh|eighth|ninth)|" + Object.keys(ORDINAL_TENS).join("|") + "|" + Object.keys(ORDINAL_TEENS).join("|") + "|" + ORDINAL_ONES.slice(1).join("|") + ")";
32643
+ var ordinalToNumber = (word) => {
32644
+ const digit = word.match(/^(\d+)(?:st|nd|rd|th)?$/i);
32645
+ if (digit) return parseInt(digit[1], 10);
32646
+ const w = word.toLowerCase();
32647
+ if (ORDINAL_TEENS[w] != null) return ORDINAL_TEENS[w];
32648
+ if (ORDINAL_TENS[w] != null) return ORDINAL_TENS[w];
32649
+ const dash = w.split("-");
32650
+ if (dash.length === 2 && CARDINAL_TENS[dash[0]] != null) {
32651
+ const one2 = ORDINAL_ONES.indexOf(dash[1]);
32652
+ if (one2 > 0) return CARDINAL_TENS[dash[0]] + one2;
32653
+ }
32654
+ const one = ORDINAL_ONES.indexOf(w);
32655
+ return one > 0 ? one : null;
32656
+ };
32657
+ var ANY_ORDINAL = "(\\d+(?:st|nd|rd|th)|" + ORDINAL_WORD_RE + ")";
32658
+ var BOOK_TAIL = "(?:the\\s+)?(?:book\\s+of\\s+)?((?:(?:First|Second|Third|Fourth|1st|2nd|3rd|4th|I{1,3}|IV)\\s+)?[A-Z][a-zA-Z]+)";
32659
+ var isCapitalized = (s) => /^[A-Z]/.test(s);
32660
+ var followsAsName = (content, end) => /^(?:['’]s\b|\s+[A-Z][a-z])/.test(content.slice(end));
32661
+ var collectSpelledOut = (content, lookup, effectiveLanguage) => {
32662
+ const out = [];
32663
+ const push = (start, end, query) => {
32664
+ const result = lookup(query);
32665
+ if (!result.verse_ids || !result.verse_ids.length) return;
32666
+ out.push({
32667
+ start,
32668
+ end,
32669
+ text: content.substring(start, end),
32670
+ verse_ids: result.verse_ids,
32671
+ ref: generateReference(result.verse_ids, effectiveLanguage)
32672
+ });
32673
+ };
32674
+ const verseRe = new RegExp("\\b(?:the\\s+)?" + ANY_ORDINAL + "\\s+verse\\s+of\\s+the\\s+" + ANY_ORDINAL + "\\s+chapter\\s+of\\s+" + BOOK_TAIL, "ig");
32675
+ const claimed = [];
32676
+ let m;
32677
+ while ((m = verseRe.exec(content)) !== null) {
32678
+ const verse = ordinalToNumber(m[1]);
32679
+ const chapter = ordinalToNumber(m[2]);
32680
+ const e0 = m.index + m[0].length;
32681
+ if (verse == null || chapter == null || !isCapitalized(m[3]) || followsAsName(content, e0)) continue;
32682
+ const s = m.index + m[0].indexOf(m[1]);
32683
+ claimed.push([s, e0]);
32684
+ push(s, e0, `${m[3]} ${chapter}:${verse}`);
32685
+ }
32686
+ const chapRe = new RegExp("\\b(?:the\\s+)?" + ANY_ORDINAL + "\\s+chapter\\s+of\\s+" + BOOK_TAIL, "ig");
32687
+ while ((m = chapRe.exec(content)) !== null) {
32688
+ const chapter = ordinalToNumber(m[1]);
32689
+ const e = m.index + m[0].length;
32690
+ if (chapter == null || !isCapitalized(m[2]) || followsAsName(content, e)) continue;
32691
+ const s = m.index + m[0].indexOf(m[1]);
32692
+ if (claimed.some(([cs, ce]) => s < ce && cs < e)) continue;
32693
+ push(s, e, `${m[2]} ${chapter}`);
32694
+ }
32695
+ return out.sort((a, b) => a.start - b.start);
32696
+ };
32629
32697
  var bookPortion = (s) => {
32630
32698
  const m = s.match(/^\s*(.*?)\s+\d/);
32631
32699
  return (m ? m[1] : s).trim().toLowerCase();
@@ -1,4 +1,4 @@
1
- /* scripture-guide v1.0.91 */
1
+ /* scripture-guide v1.0.92 */
2
2
 
3
3
  // src/data/canons/bible/structure.mjs
4
4
  var structure_default = {
@@ -31561,7 +31561,9 @@ var findMatches = (content, books, lang_extra) => {
31561
31561
  const tail = lang_extra.tail ? new RegExp(lang_extra.tail, "ig") : /[^0-9]+$/;
31562
31562
  const preBookMatch = lang_extra.book || `(First|I|1|1st|Second|II|2|2nd|Third|III|3|3rd|Fourth|IV|4|4th)*\\s*(books* of)*\\s*`;
31563
31563
  const matchingBooks = findMatchingBooks(normalizedContent, books);
31564
- const postBookMatch = lang_extra.chapter || "([0-9:.;,~ \u2014\u2013-]|cf)*[0-9]+";
31564
+ const gap = "[ \\t]*(?:\\n(?![ \\t]*\\n)[ \\t]*)?(?:,[ \\t]*sec(?:tion)?\\.?[ \\t]*)?\\(?[ \\t]*(?=[0-9])";
31565
+ const core = "(?:[0-9:.;,~\u2014\u2013-]|[ \\t]|\\n(?![ \\t]*\\n)|and\\b|cf\\b|\\()*[0-9]";
31566
+ const postBookMatch = lang_extra.chapter || gap + core;
31565
31567
  const fullBookMatches = matchingBooks.map((bookMatch) => {
31566
31568
  const patternString = preBookMatch + bookMatch;
31567
31569
  const pattern = new RegExp(patternString, "ig");
@@ -31619,7 +31621,7 @@ var findMatches = (content, books, lang_extra) => {
31619
31621
  return newString.replace(tail, "").trim();
31620
31622
  }).filter((i) => !!i);
31621
31623
  const matches = matchesWithReferences.map((string) => {
31622
- const pattern = new RegExp(string, "ig");
31624
+ const pattern = new RegExp(string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "ig");
31623
31625
  const matches2 = normalizedContent.match(pattern)?.map((i) => i.trim().replace(tail, ""));
31624
31626
  return matches2;
31625
31627
  }).flat().reduce((prev, current) => {
@@ -32195,6 +32197,9 @@ var strToHash = function(str) {
32195
32197
  };
32196
32198
  var cleanReference = function(messyReference, config) {
32197
32199
  let ref = messyReference.replace(/[\s]+/g, " ").trim();
32200
+ ref = ref.replace(/(\d)\s+and\s+(\d)/g, "$1,$2");
32201
+ ref = ref.replace(/[()]/g, " ");
32202
+ ref = ref.replace(/\bsec(?:tion)?\b\.?/ig, " ");
32198
32203
  let regex = config.raw_regex.pre_rules;
32199
32204
  for (let i in regex) {
32200
32205
  var re = new RegExp(regex[i].pattern ?? regex[i][0], "ig");
@@ -32568,15 +32573,78 @@ var findReferences = (content, options = null) => {
32568
32573
  const books = [...dst, ...src];
32569
32574
  const lookup = (query) => lookupReference(query, effectiveLanguage);
32570
32575
  const found = finalOptions.contextAware ? collectReferencesWithContext(content, books, config.lang_extra, lookup, finalOptions) : collectReferences(content, books, config.lang_extra, lookup);
32571
- const records = found.filter((m) => m.verse_ids.length > 0).map(({ start, end, text, verse_ids }) => ({
32576
+ let records = found.filter((m) => m.verse_ids.length > 0).map(({ start, end, text, verse_ids }) => ({
32572
32577
  start,
32573
32578
  end,
32574
32579
  text,
32575
32580
  verse_ids,
32576
32581
  ref: generateReference(verse_ids, effectiveLanguage)
32577
32582
  }));
32583
+ const spelled = collectSpelledOut(content, lookup, effectiveLanguage).filter((sp) => !records.some((r) => sp.start < r.end && r.start < sp.end));
32584
+ if (spelled.length) {
32585
+ records = [...records, ...spelled].sort((a, b) => a.start - b.start);
32586
+ }
32578
32587
  return applyDetectionFlags(records, finalOptions);
32579
32588
  };
32589
+ var ORDINAL_ONES = ["zeroth", "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth"];
32590
+ var ORDINAL_TEENS = { tenth: 10, eleventh: 11, twelfth: 12, thirteenth: 13, fourteenth: 14, fifteenth: 15, sixteenth: 16, seventeenth: 17, eighteenth: 18, nineteenth: 19 };
32591
+ var ORDINAL_TENS = { twentieth: 20, thirtieth: 30 };
32592
+ var CARDINAL_TENS = { twenty: 20, thirty: 30 };
32593
+ var ORDINAL_WORD_RE = "(?:twenty-(?:first|second|third|fourth|fifth|sixth|seventh|eighth|ninth)|thirty-(?:first|second|third|fourth|fifth|sixth|seventh|eighth|ninth)|" + Object.keys(ORDINAL_TENS).join("|") + "|" + Object.keys(ORDINAL_TEENS).join("|") + "|" + ORDINAL_ONES.slice(1).join("|") + ")";
32594
+ var ordinalToNumber = (word) => {
32595
+ const digit = word.match(/^(\d+)(?:st|nd|rd|th)?$/i);
32596
+ if (digit) return parseInt(digit[1], 10);
32597
+ const w = word.toLowerCase();
32598
+ if (ORDINAL_TEENS[w] != null) return ORDINAL_TEENS[w];
32599
+ if (ORDINAL_TENS[w] != null) return ORDINAL_TENS[w];
32600
+ const dash = w.split("-");
32601
+ if (dash.length === 2 && CARDINAL_TENS[dash[0]] != null) {
32602
+ const one2 = ORDINAL_ONES.indexOf(dash[1]);
32603
+ if (one2 > 0) return CARDINAL_TENS[dash[0]] + one2;
32604
+ }
32605
+ const one = ORDINAL_ONES.indexOf(w);
32606
+ return one > 0 ? one : null;
32607
+ };
32608
+ var ANY_ORDINAL = "(\\d+(?:st|nd|rd|th)|" + ORDINAL_WORD_RE + ")";
32609
+ var BOOK_TAIL = "(?:the\\s+)?(?:book\\s+of\\s+)?((?:(?:First|Second|Third|Fourth|1st|2nd|3rd|4th|I{1,3}|IV)\\s+)?[A-Z][a-zA-Z]+)";
32610
+ var isCapitalized = (s) => /^[A-Z]/.test(s);
32611
+ var followsAsName = (content, end) => /^(?:['’]s\b|\s+[A-Z][a-z])/.test(content.slice(end));
32612
+ var collectSpelledOut = (content, lookup, effectiveLanguage) => {
32613
+ const out = [];
32614
+ const push = (start, end, query) => {
32615
+ const result = lookup(query);
32616
+ if (!result.verse_ids || !result.verse_ids.length) return;
32617
+ out.push({
32618
+ start,
32619
+ end,
32620
+ text: content.substring(start, end),
32621
+ verse_ids: result.verse_ids,
32622
+ ref: generateReference(result.verse_ids, effectiveLanguage)
32623
+ });
32624
+ };
32625
+ const verseRe = new RegExp("\\b(?:the\\s+)?" + ANY_ORDINAL + "\\s+verse\\s+of\\s+the\\s+" + ANY_ORDINAL + "\\s+chapter\\s+of\\s+" + BOOK_TAIL, "ig");
32626
+ const claimed = [];
32627
+ let m;
32628
+ while ((m = verseRe.exec(content)) !== null) {
32629
+ const verse = ordinalToNumber(m[1]);
32630
+ const chapter = ordinalToNumber(m[2]);
32631
+ const e0 = m.index + m[0].length;
32632
+ if (verse == null || chapter == null || !isCapitalized(m[3]) || followsAsName(content, e0)) continue;
32633
+ const s = m.index + m[0].indexOf(m[1]);
32634
+ claimed.push([s, e0]);
32635
+ push(s, e0, `${m[3]} ${chapter}:${verse}`);
32636
+ }
32637
+ const chapRe = new RegExp("\\b(?:the\\s+)?" + ANY_ORDINAL + "\\s+chapter\\s+of\\s+" + BOOK_TAIL, "ig");
32638
+ while ((m = chapRe.exec(content)) !== null) {
32639
+ const chapter = ordinalToNumber(m[1]);
32640
+ const e = m.index + m[0].length;
32641
+ if (chapter == null || !isCapitalized(m[2]) || followsAsName(content, e)) continue;
32642
+ const s = m.index + m[0].indexOf(m[1]);
32643
+ if (claimed.some(([cs, ce]) => s < ce && cs < e)) continue;
32644
+ push(s, e, `${m[2]} ${chapter}`);
32645
+ }
32646
+ return out.sort((a, b) => a.start - b.start);
32647
+ };
32580
32648
  var bookPortion = (s) => {
32581
32649
  const m = s.match(/^\s*(.*?)\s+\d/);
32582
32650
  return (m ? m[1] : s).trim().toLowerCase();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scripture-guide",
3
- "version": "1.0.91",
3
+ "version": "1.0.92",
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": "dist/scriptures.cjs",
6
6
  "module": "dist/scriptures.mjs",