scripture-guide 1.0.93 → 1.0.97

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 CHANGED
@@ -126,6 +126,7 @@ detectReferences('In John 3, Jesus explains (v. 16) that God loved the world.');
126
126
  | `options.language` | string | Language code |
127
127
  | `options.contextAware` | boolean | Enable context detection (default: true) |
128
128
  | `options.enableImpliedBooks` | boolean | Detect bare verse numbers (default: true) |
129
+ | `options.chainAcrossMarkers` | boolean | Merge references joined by prose markers — `see also`, `cf.`, `compare`, `cited at` — into a single reference (default: true). Set `false` to keep the marker words outside the link: `'A; see also B'` yields two links instead of one. Structural joiners (`;` `,` `&` `and`) still merge either way. |
129
130
 
130
131
  ### setLanguage(language)
131
132
 
@@ -1,4 +1,4 @@
1
- /* scripture-guide v1.0.93 */
1
+ /* scripture-guide v1.0.97 */
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -3249,6 +3249,16 @@ var en_default3 = {
3249
3249
  "cited at",
3250
3250
  "also"
3251
3251
  ],
3252
+ "capitalized_only": [
3253
+ "is",
3254
+ "am",
3255
+ "he",
3256
+ "re",
3257
+ "la",
3258
+ "co",
3259
+ "col",
3260
+ "act"
3261
+ ],
3252
3262
  "pre_rules": [
3253
3263
  [
3254
3264
  "\\bgospel\\s+(?:of|according\\s+to)\\s+",
@@ -3310,6 +3320,10 @@ var en_default3 = {
3310
3320
  "\\bfourth\\s+(?=[A-Za-z])",
3311
3321
  "4 "
3312
3322
  ],
3323
+ [
3324
+ "(\\d)\\s+&\\s+",
3325
+ "$1; "
3326
+ ],
3313
3327
  [
3314
3328
  "[.]{2,}",
3315
3329
  ";"
@@ -31294,7 +31308,8 @@ function buildRegexData() {
31294
31308
  books,
31295
31309
  pre_rules: en_default3.pre_rules || [],
31296
31310
  post_rules: en_default3.post_rules || [],
31297
- joiners: en_default3.joiners || []
31311
+ joiners: en_default3.joiners || [],
31312
+ capitalized_only: en_default3.capitalized_only || []
31298
31313
  };
31299
31314
  }
31300
31315
  function transformBooks(bibleBooks, ldsBooks) {
@@ -31543,7 +31558,7 @@ var mergeAdjacentMatches = (matches, gapMergeFlags, compatibilityCheck = null) =
31543
31558
  if (prevIndex.length > 2 && current.length > 2) {
31544
31559
  const startPos = prevIndex[0];
31545
31560
  const endPos = current[1];
31546
- const combinedText = prevIndex[2] + ";" + current[2];
31561
+ const combinedText = prevIndex[2] + "; " + current[2];
31547
31562
  const combinedVerseIds = [...prevIndex[3] || [], ...current[3] || []];
31548
31563
  const merged = [startPos, endPos, combinedText, combinedVerseIds];
31549
31564
  prev[prev.length - 1] = merged;
@@ -31621,6 +31636,9 @@ var findMatches = (content, books, lang_extra) => {
31621
31636
  const gap = "[ \\t]*(?:\\n(?![ \\t]*\\n)[ \\t]*)?(?:,[ \\t]*sec(?:tion)?\\.?[ \\t]*)?\\(?[ \\t]*(?=[0-9])";
31622
31637
  const core = "(?:[0-9:.;,~\u2014\u2013-]|[ \\t]|\\n(?![ \\t]*\\n)|and\\b|cf\\b|\\()*[0-9]";
31623
31638
  const postBookMatch = lang_extra.chapter || gap + core;
31639
+ const capitalizedOnlyAbbreviations = new Set(
31640
+ (lang_extra.capitalizedOnly || []).map((i) => String(i).toLowerCase())
31641
+ );
31624
31642
  const fullBookMatches = matchingBooks.map((bookMatch) => {
31625
31643
  const patternString = preBookMatch + bookMatch;
31626
31644
  const pattern = new RegExp(patternString, "ig");
@@ -31633,7 +31651,11 @@ var findMatches = (content, books, lang_extra) => {
31633
31651
  }).flat().reduce((prev, current) => {
31634
31652
  if (prev.includes(current)) return prev;
31635
31653
  return [...prev, current];
31636
- }, []).filter((i) => !!i).map((substring) => {
31654
+ }, []).filter((i) => !!i).filter((substring) => {
31655
+ const token = substring.trim();
31656
+ if (!capitalizedOnlyAbbreviations.has(token.toLowerCase())) return true;
31657
+ return token !== token.toLowerCase();
31658
+ }).map((substring) => {
31637
31659
  substring = substring.trim();
31638
31660
  let positions = [];
31639
31661
  let index = normalizedContent.indexOf(substring);
@@ -31666,6 +31688,7 @@ var findMatches = (content, books, lang_extra) => {
31666
31688
  const len = match.length;
31667
31689
  const pos = i;
31668
31690
  const [posIn, posOut] = [pos, pos + len];
31691
+ if (/[0-9]$/.test(match) && /[A-Z]/.test(normalizedContent[posOut] || "")) return null;
31669
31692
  return [match, posIn, posOut];
31670
31693
  }
31671
31694
  );
@@ -31708,6 +31731,7 @@ function findMatchIndexes(content, matches, lookupReference2, lang_extra) {
31708
31731
  const next = array[index + 1];
31709
31732
  if (next && next[0] < end && next[1] > end) {
31710
31733
  end = next[0];
31734
+ end = start + content.slice(start, end).replace(tail, "").length;
31711
31735
  }
31712
31736
  return [start, end];
31713
31737
  });
@@ -32581,6 +32605,23 @@ var loadMaxVerse = function(book, chapter, config) {
32581
32605
  if (!bookExists(book, config)) return 0;
32582
32606
  return config.raw_index[book][parseInt(chapter) - 1];
32583
32607
  };
32608
+ var STRUCTURAL_JOINERS = [";", ",", "&", "and"];
32609
+ var isStructuralJoiner = (token) => typeof token === "string" && (!/[a-z]/i.test(token) || token.trim().toLowerCase() === "and");
32610
+ var restrictJoinersToStructural = (lang_extra) => {
32611
+ const src = lang_extra || {};
32612
+ const j = src.joiners;
32613
+ let joiners;
32614
+ if (Array.isArray(j)) {
32615
+ joiners = j.filter(isStructuralJoiner);
32616
+ if (!joiners.length) joiners = [...STRUCTURAL_JOINERS];
32617
+ } else if (j && Array.isArray(j.patterns)) {
32618
+ const patterns = j.patterns.filter(isStructuralJoiner);
32619
+ joiners = patterns.length ? { ...j, patterns } : [...STRUCTURAL_JOINERS];
32620
+ } else {
32621
+ joiners = [...STRUCTURAL_JOINERS];
32622
+ }
32623
+ return { ...src, joiners };
32624
+ };
32584
32625
  var detectReferences = (content, callBack, options = null) => {
32585
32626
  if (typeof options === "string" || options === null) {
32586
32627
  const language = options;
@@ -32592,7 +32633,8 @@ var detectReferences = (content, callBack, options = null) => {
32592
32633
  contextScope: "sentence",
32593
32634
  maxContextDistance: 500,
32594
32635
  enableImpliedBooks: true,
32595
- enableVerseAbbrev: true
32636
+ enableVerseAbbrev: true,
32637
+ chainAcrossMarkers: true
32596
32638
  };
32597
32639
  const finalOptions = { ...defaultOptions, ...options };
32598
32640
  callBack = callBack ? callBack : (i) => {
@@ -32603,10 +32645,11 @@ var detectReferences = (content, callBack, options = null) => {
32603
32645
  const src = config.raw_regex.books.map((i) => i[0]);
32604
32646
  const dst = [...new Set(config.raw_regex.books.map((i) => i[1]))];
32605
32647
  const books = [...dst, ...src];
32648
+ const langExtra = finalOptions.chainAcrossMarkers === false ? restrictJoinersToStructural(config.lang_extra) : config.lang_extra;
32606
32649
  if (finalOptions.contextAware) {
32607
- return detectReferencesWithContext(content, books, config.lang_extra, (query) => lookupReference(query, effectiveLanguage), callBack, finalOptions, generateReference);
32650
+ return detectReferencesWithContext(content, books, langExtra, (query) => lookupReference(query, effectiveLanguage), callBack, finalOptions, generateReference);
32608
32651
  }
32609
- return processReferenceDetection(content, books, config.lang_extra, (query) => lookupReference(query, effectiveLanguage), callBack);
32652
+ return processReferenceDetection(content, books, langExtra, (query) => lookupReference(query, effectiveLanguage), callBack);
32610
32653
  };
32611
32654
  var findReferences = (content, options = null) => {
32612
32655
  if (typeof options === "string" || options === null) {
@@ -32620,7 +32663,8 @@ var findReferences = (content, options = null) => {
32620
32663
  enableImpliedBooks: true,
32621
32664
  enableVerseAbbrev: true,
32622
32665
  abbreviations: true,
32623
- chapterOnly: true
32666
+ chapterOnly: true,
32667
+ chainAcrossMarkers: true
32624
32668
  };
32625
32669
  const finalOptions = { ...defaultOptions, ...options };
32626
32670
  const effectiveLanguage = getEffectiveLanguage(finalOptions.language);
@@ -32629,7 +32673,8 @@ var findReferences = (content, options = null) => {
32629
32673
  const dst = [...new Set(config.raw_regex.books.map((i) => i[1]))];
32630
32674
  const books = [...dst, ...src];
32631
32675
  const lookup = (query) => lookupReference(query, effectiveLanguage);
32632
- const found = finalOptions.contextAware ? collectReferencesWithContext(content, books, config.lang_extra, lookup, finalOptions) : collectReferences(content, books, config.lang_extra, lookup);
32676
+ const langExtra = finalOptions.chainAcrossMarkers === false ? restrictJoinersToStructural(config.lang_extra) : config.lang_extra;
32677
+ const found = finalOptions.contextAware ? collectReferencesWithContext(content, books, langExtra, lookup, finalOptions) : collectReferences(content, books, langExtra, lookup);
32633
32678
  let records = found.filter((m) => m.verse_ids.length > 0).map(({ start, end, text, verse_ids }) => ({
32634
32679
  start,
32635
32680
  end,
@@ -32731,6 +32776,7 @@ var getLanguageConfig = function(language, canon = null) {
32731
32776
  };
32732
32777
  if (effectiveLanguage === "en" || !raw_lang[effectiveLanguage]) {
32733
32778
  config.lang_extra.joiners = config.raw_regex.joiners;
32779
+ config.lang_extra.capitalizedOnly = config.raw_regex.capitalized_only || [];
32734
32780
  return applyCanonOverride(config, effectiveCanon);
32735
32781
  }
32736
32782
  const langData2 = raw_lang[effectiveLanguage];
@@ -1,4 +1,4 @@
1
- /* scripture-guide v1.0.93 */
1
+ /* scripture-guide v1.0.97 */
2
2
 
3
3
  // src/data/canons/bible/structure.mjs
4
4
  var structure_default = {
@@ -3200,6 +3200,16 @@ var en_default3 = {
3200
3200
  "cited at",
3201
3201
  "also"
3202
3202
  ],
3203
+ "capitalized_only": [
3204
+ "is",
3205
+ "am",
3206
+ "he",
3207
+ "re",
3208
+ "la",
3209
+ "co",
3210
+ "col",
3211
+ "act"
3212
+ ],
3203
3213
  "pre_rules": [
3204
3214
  [
3205
3215
  "\\bgospel\\s+(?:of|according\\s+to)\\s+",
@@ -3261,6 +3271,10 @@ var en_default3 = {
3261
3271
  "\\bfourth\\s+(?=[A-Za-z])",
3262
3272
  "4 "
3263
3273
  ],
3274
+ [
3275
+ "(\\d)\\s+&\\s+",
3276
+ "$1; "
3277
+ ],
3264
3278
  [
3265
3279
  "[.]{2,}",
3266
3280
  ";"
@@ -31245,7 +31259,8 @@ function buildRegexData() {
31245
31259
  books,
31246
31260
  pre_rules: en_default3.pre_rules || [],
31247
31261
  post_rules: en_default3.post_rules || [],
31248
- joiners: en_default3.joiners || []
31262
+ joiners: en_default3.joiners || [],
31263
+ capitalized_only: en_default3.capitalized_only || []
31249
31264
  };
31250
31265
  }
31251
31266
  function transformBooks(bibleBooks, ldsBooks) {
@@ -31494,7 +31509,7 @@ var mergeAdjacentMatches = (matches, gapMergeFlags, compatibilityCheck = null) =
31494
31509
  if (prevIndex.length > 2 && current.length > 2) {
31495
31510
  const startPos = prevIndex[0];
31496
31511
  const endPos = current[1];
31497
- const combinedText = prevIndex[2] + ";" + current[2];
31512
+ const combinedText = prevIndex[2] + "; " + current[2];
31498
31513
  const combinedVerseIds = [...prevIndex[3] || [], ...current[3] || []];
31499
31514
  const merged = [startPos, endPos, combinedText, combinedVerseIds];
31500
31515
  prev[prev.length - 1] = merged;
@@ -31572,6 +31587,9 @@ var findMatches = (content, books, lang_extra) => {
31572
31587
  const gap = "[ \\t]*(?:\\n(?![ \\t]*\\n)[ \\t]*)?(?:,[ \\t]*sec(?:tion)?\\.?[ \\t]*)?\\(?[ \\t]*(?=[0-9])";
31573
31588
  const core = "(?:[0-9:.;,~\u2014\u2013-]|[ \\t]|\\n(?![ \\t]*\\n)|and\\b|cf\\b|\\()*[0-9]";
31574
31589
  const postBookMatch = lang_extra.chapter || gap + core;
31590
+ const capitalizedOnlyAbbreviations = new Set(
31591
+ (lang_extra.capitalizedOnly || []).map((i) => String(i).toLowerCase())
31592
+ );
31575
31593
  const fullBookMatches = matchingBooks.map((bookMatch) => {
31576
31594
  const patternString = preBookMatch + bookMatch;
31577
31595
  const pattern = new RegExp(patternString, "ig");
@@ -31584,7 +31602,11 @@ var findMatches = (content, books, lang_extra) => {
31584
31602
  }).flat().reduce((prev, current) => {
31585
31603
  if (prev.includes(current)) return prev;
31586
31604
  return [...prev, current];
31587
- }, []).filter((i) => !!i).map((substring) => {
31605
+ }, []).filter((i) => !!i).filter((substring) => {
31606
+ const token = substring.trim();
31607
+ if (!capitalizedOnlyAbbreviations.has(token.toLowerCase())) return true;
31608
+ return token !== token.toLowerCase();
31609
+ }).map((substring) => {
31588
31610
  substring = substring.trim();
31589
31611
  let positions = [];
31590
31612
  let index = normalizedContent.indexOf(substring);
@@ -31617,6 +31639,7 @@ var findMatches = (content, books, lang_extra) => {
31617
31639
  const len = match.length;
31618
31640
  const pos = i;
31619
31641
  const [posIn, posOut] = [pos, pos + len];
31642
+ if (/[0-9]$/.test(match) && /[A-Z]/.test(normalizedContent[posOut] || "")) return null;
31620
31643
  return [match, posIn, posOut];
31621
31644
  }
31622
31645
  );
@@ -31659,6 +31682,7 @@ function findMatchIndexes(content, matches, lookupReference2, lang_extra) {
31659
31682
  const next = array[index + 1];
31660
31683
  if (next && next[0] < end && next[1] > end) {
31661
31684
  end = next[0];
31685
+ end = start + content.slice(start, end).replace(tail, "").length;
31662
31686
  }
31663
31687
  return [start, end];
31664
31688
  });
@@ -32532,6 +32556,23 @@ var loadMaxVerse = function(book, chapter, config) {
32532
32556
  if (!bookExists(book, config)) return 0;
32533
32557
  return config.raw_index[book][parseInt(chapter) - 1];
32534
32558
  };
32559
+ var STRUCTURAL_JOINERS = [";", ",", "&", "and"];
32560
+ var isStructuralJoiner = (token) => typeof token === "string" && (!/[a-z]/i.test(token) || token.trim().toLowerCase() === "and");
32561
+ var restrictJoinersToStructural = (lang_extra) => {
32562
+ const src = lang_extra || {};
32563
+ const j = src.joiners;
32564
+ let joiners;
32565
+ if (Array.isArray(j)) {
32566
+ joiners = j.filter(isStructuralJoiner);
32567
+ if (!joiners.length) joiners = [...STRUCTURAL_JOINERS];
32568
+ } else if (j && Array.isArray(j.patterns)) {
32569
+ const patterns = j.patterns.filter(isStructuralJoiner);
32570
+ joiners = patterns.length ? { ...j, patterns } : [...STRUCTURAL_JOINERS];
32571
+ } else {
32572
+ joiners = [...STRUCTURAL_JOINERS];
32573
+ }
32574
+ return { ...src, joiners };
32575
+ };
32535
32576
  var detectReferences = (content, callBack, options = null) => {
32536
32577
  if (typeof options === "string" || options === null) {
32537
32578
  const language = options;
@@ -32543,7 +32584,8 @@ var detectReferences = (content, callBack, options = null) => {
32543
32584
  contextScope: "sentence",
32544
32585
  maxContextDistance: 500,
32545
32586
  enableImpliedBooks: true,
32546
- enableVerseAbbrev: true
32587
+ enableVerseAbbrev: true,
32588
+ chainAcrossMarkers: true
32547
32589
  };
32548
32590
  const finalOptions = { ...defaultOptions, ...options };
32549
32591
  callBack = callBack ? callBack : (i) => {
@@ -32554,10 +32596,11 @@ var detectReferences = (content, callBack, options = null) => {
32554
32596
  const src = config.raw_regex.books.map((i) => i[0]);
32555
32597
  const dst = [...new Set(config.raw_regex.books.map((i) => i[1]))];
32556
32598
  const books = [...dst, ...src];
32599
+ const langExtra = finalOptions.chainAcrossMarkers === false ? restrictJoinersToStructural(config.lang_extra) : config.lang_extra;
32557
32600
  if (finalOptions.contextAware) {
32558
- return detectReferencesWithContext(content, books, config.lang_extra, (query) => lookupReference(query, effectiveLanguage), callBack, finalOptions, generateReference);
32601
+ return detectReferencesWithContext(content, books, langExtra, (query) => lookupReference(query, effectiveLanguage), callBack, finalOptions, generateReference);
32559
32602
  }
32560
- return processReferenceDetection(content, books, config.lang_extra, (query) => lookupReference(query, effectiveLanguage), callBack);
32603
+ return processReferenceDetection(content, books, langExtra, (query) => lookupReference(query, effectiveLanguage), callBack);
32561
32604
  };
32562
32605
  var findReferences = (content, options = null) => {
32563
32606
  if (typeof options === "string" || options === null) {
@@ -32571,7 +32614,8 @@ var findReferences = (content, options = null) => {
32571
32614
  enableImpliedBooks: true,
32572
32615
  enableVerseAbbrev: true,
32573
32616
  abbreviations: true,
32574
- chapterOnly: true
32617
+ chapterOnly: true,
32618
+ chainAcrossMarkers: true
32575
32619
  };
32576
32620
  const finalOptions = { ...defaultOptions, ...options };
32577
32621
  const effectiveLanguage = getEffectiveLanguage(finalOptions.language);
@@ -32580,7 +32624,8 @@ var findReferences = (content, options = null) => {
32580
32624
  const dst = [...new Set(config.raw_regex.books.map((i) => i[1]))];
32581
32625
  const books = [...dst, ...src];
32582
32626
  const lookup = (query) => lookupReference(query, effectiveLanguage);
32583
- const found = finalOptions.contextAware ? collectReferencesWithContext(content, books, config.lang_extra, lookup, finalOptions) : collectReferences(content, books, config.lang_extra, lookup);
32627
+ const langExtra = finalOptions.chainAcrossMarkers === false ? restrictJoinersToStructural(config.lang_extra) : config.lang_extra;
32628
+ const found = finalOptions.contextAware ? collectReferencesWithContext(content, books, langExtra, lookup, finalOptions) : collectReferences(content, books, langExtra, lookup);
32584
32629
  let records = found.filter((m) => m.verse_ids.length > 0).map(({ start, end, text, verse_ids }) => ({
32585
32630
  start,
32586
32631
  end,
@@ -32682,6 +32727,7 @@ var getLanguageConfig = function(language, canon = null) {
32682
32727
  };
32683
32728
  if (effectiveLanguage === "en" || !raw_lang[effectiveLanguage]) {
32684
32729
  config.lang_extra.joiners = config.raw_regex.joiners;
32730
+ config.lang_extra.capitalizedOnly = config.raw_regex.capitalized_only || [];
32685
32731
  return applyCanonOverride(config, effectiveCanon);
32686
32732
  }
32687
32733
  const langData2 = raw_lang[effectiveLanguage];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scripture-guide",
3
- "version": "1.0.93",
3
+ "version": "1.0.97",
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",