scripture-guide 1.0.97 → 1.1.1
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 +1 -0
- package/dist/scriptures.cjs +183 -92
- package/dist/scriptures.d.ts +23 -2
- package/dist/scriptures.mjs +183 -92
- package/package.json +19 -18
package/README.md
CHANGED
|
@@ -61,6 +61,7 @@ lookupReference('1 Nephi 3:7', { language: 'en', canon: 'lds' });
|
|
|
61
61
|
| `options` | string \| object | If string, treated as language code |
|
|
62
62
|
| `options.language` | string | Language code |
|
|
63
63
|
| `options.canon` | string | Canon: `'lds'`, `'rlds'`, etc. |
|
|
64
|
+
| `options.maxVerses` | number | The most verses one range expands to (default 1000). A longer range is cut there |
|
|
64
65
|
|
|
65
66
|
> **Backward Compatibility:** The old 3-parameter signature `lookupReference(query, language, config)` is deprecated but still supported.
|
|
66
67
|
|
package/dist/scriptures.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* scripture-guide v1.
|
|
1
|
+
/* scripture-guide v1.1.1 */
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -45,6 +45,7 @@ __export(scriptures_exports, {
|
|
|
45
45
|
setCanon: () => setCanon,
|
|
46
46
|
setLang: () => setLanguage,
|
|
47
47
|
setLanguage: () => setLanguage,
|
|
48
|
+
toSlug: () => toSlug,
|
|
48
49
|
verseId2Ref: () => generateReference
|
|
49
50
|
});
|
|
50
51
|
module.exports = __toCommonJS(scriptures_exports);
|
|
@@ -898,7 +899,7 @@ var structure_default = {
|
|
|
898
899
|
"first_verse_id": 17317
|
|
899
900
|
},
|
|
900
901
|
{
|
|
901
|
-
"key": "
|
|
902
|
+
"key": "song_of_solomon",
|
|
902
903
|
"order": 22,
|
|
903
904
|
"chapters": 8,
|
|
904
905
|
"verses": [
|
|
@@ -2538,9 +2539,11 @@ var en_default = {
|
|
|
2538
2539
|
]
|
|
2539
2540
|
},
|
|
2540
2541
|
"song_of_solomon": {
|
|
2541
|
-
"name": "Song
|
|
2542
|
-
"pattern": "(?<!solomon's )(the )*song*\\.*(?: *of *solomon)*",
|
|
2542
|
+
"name": "Solomon's Song",
|
|
2543
|
+
"pattern": "(?<!solomon['\u2019]?s )(the )*song*\\.*(?: *of *solomon)*",
|
|
2543
2544
|
"alt": [
|
|
2545
|
+
"solomon\u2019s song",
|
|
2546
|
+
"solomons song",
|
|
2544
2547
|
"song",
|
|
2545
2548
|
"sos",
|
|
2546
2549
|
"ss",
|
|
@@ -31479,10 +31482,12 @@ var rangesOverlap = (range1, range2) => {
|
|
|
31479
31482
|
var removeOverlaps = (matches, content, preferenceResolver = null) => {
|
|
31480
31483
|
if (matches.length <= 1) return matches;
|
|
31481
31484
|
const result = [];
|
|
31485
|
+
const sorted = matches.every((m, i) => i === 0 || m[0] >= matches[i - 1][0]);
|
|
31486
|
+
let includedMaxEnd = -Infinity;
|
|
31482
31487
|
for (let i = 0; i < matches.length; i++) {
|
|
31483
31488
|
const current = matches[i];
|
|
31484
31489
|
let shouldInclude = true;
|
|
31485
|
-
for (const included of result) {
|
|
31490
|
+
if (!sorted || includedMaxEnd > current[0]) for (const included of result) {
|
|
31486
31491
|
if (rangesOverlap(current, included)) {
|
|
31487
31492
|
shouldInclude = false;
|
|
31488
31493
|
break;
|
|
@@ -31491,6 +31496,7 @@ var removeOverlaps = (matches, content, preferenceResolver = null) => {
|
|
|
31491
31496
|
if (shouldInclude) {
|
|
31492
31497
|
for (let j = i + 1; j < matches.length; j++) {
|
|
31493
31498
|
const next = matches[j];
|
|
31499
|
+
if (sorted && next[0] >= current[1]) break;
|
|
31494
31500
|
if (rangesOverlap(current, next)) {
|
|
31495
31501
|
if (preferenceResolver) {
|
|
31496
31502
|
const preferred = preferenceResolver(current, next, content);
|
|
@@ -31511,10 +31517,27 @@ var removeOverlaps = (matches, content, preferenceResolver = null) => {
|
|
|
31511
31517
|
}
|
|
31512
31518
|
if (shouldInclude) {
|
|
31513
31519
|
result.push(current);
|
|
31520
|
+
includedMaxEnd = Math.max(includedMaxEnd, current[1]);
|
|
31514
31521
|
}
|
|
31515
31522
|
}
|
|
31516
31523
|
return result;
|
|
31517
31524
|
};
|
|
31525
|
+
var spanCoverage = (spans) => {
|
|
31526
|
+
const sorted = [...spans || []].sort((a, b) => a[0] - b[0]);
|
|
31527
|
+
const maxEnd = [];
|
|
31528
|
+
for (let i = 0; i < sorted.length; i++) maxEnd.push(Math.max(sorted[i][1], i ? maxEnd[i - 1] : -Infinity));
|
|
31529
|
+
return (position) => {
|
|
31530
|
+
let lo = 0, hi = sorted.length - 1, last = -1;
|
|
31531
|
+
while (lo <= hi) {
|
|
31532
|
+
const mid = lo + hi >> 1;
|
|
31533
|
+
if (sorted[mid][0] <= position) {
|
|
31534
|
+
last = mid;
|
|
31535
|
+
lo = mid + 1;
|
|
31536
|
+
} else hi = mid - 1;
|
|
31537
|
+
}
|
|
31538
|
+
return last >= 0 && maxEnd[last] > position;
|
|
31539
|
+
};
|
|
31540
|
+
};
|
|
31518
31541
|
var calculateGaps = (matches) => {
|
|
31519
31542
|
return matches.reduce((prev, current, index) => {
|
|
31520
31543
|
if (index === 0) return prev;
|
|
@@ -31575,6 +31598,7 @@ var mergeAdjacentMatches = (matches, gapMergeFlags, compatibilityCheck = null) =
|
|
|
31575
31598
|
};
|
|
31576
31599
|
var gapCanMerge = (gapString, joiners) => {
|
|
31577
31600
|
if (!/\S/.test(gapString)) return true;
|
|
31601
|
+
if (/^\s*\./.test(gapString)) return false;
|
|
31578
31602
|
const list = Array.isArray(joiners) ? joiners : joiners && joiners.patterns || [];
|
|
31579
31603
|
let residue = gapString;
|
|
31580
31604
|
for (const joiner of list) {
|
|
@@ -31631,7 +31655,7 @@ var findMatches = (content, books, lang_extra) => {
|
|
|
31631
31655
|
normalizedContent = normalizedContent.replace(new RegExp(entity, "g"), unicode);
|
|
31632
31656
|
});
|
|
31633
31657
|
const tail = lang_extra.tail ? new RegExp(lang_extra.tail, "ig") : /[^0-9]+$/;
|
|
31634
|
-
const preBookMatch = lang_extra.book || `(First|
|
|
31658
|
+
const preBookMatch = lang_extra.book || `(?:(?:First|Second|Third|Fourth|1st|2nd|3rd|4th|III|II|IV|I|[1-4])\\s*)?(?:books? of\\s*)?`;
|
|
31635
31659
|
const matchingBooks = findMatchingBooks(normalizedContent, books);
|
|
31636
31660
|
const gap = "[ \\t]*(?:\\n(?![ \\t]*\\n)[ \\t]*)?(?:,[ \\t]*sec(?:tion)?\\.?[ \\t]*)?\\(?[ \\t]*(?=[0-9])";
|
|
31637
31661
|
const core = "(?:[0-9:.;,~\u2014\u2013-]|[ \\t]|\\n(?![ \\t]*\\n)|and\\b|cf\\b|\\()*[0-9]";
|
|
@@ -31645,13 +31669,11 @@ var findMatches = (content, books, lang_extra) => {
|
|
|
31645
31669
|
const stringMatch = pattern.test(normalizedContent) ? patternString : null;
|
|
31646
31670
|
return stringMatch;
|
|
31647
31671
|
}).filter((x) => !!x);
|
|
31648
|
-
const
|
|
31672
|
+
const allBookSubStrings = fullBookMatches.map((bookMatch) => {
|
|
31649
31673
|
const substrings = normalizedContent.match(new RegExp(bookMatch, "ig")).flat();
|
|
31650
31674
|
return substrings;
|
|
31651
|
-
}).flat()
|
|
31652
|
-
|
|
31653
|
-
return [...prev, current];
|
|
31654
|
-
}, []).filter((i) => !!i).filter((substring) => {
|
|
31675
|
+
}).flat();
|
|
31676
|
+
const bookSubStrings = [...new Set(allBookSubStrings)].filter((i) => !!i).filter((substring) => {
|
|
31655
31677
|
const token = substring.trim();
|
|
31656
31678
|
if (!capitalizedOnlyAbbreviations.has(token.toLowerCase())) return true;
|
|
31657
31679
|
return token !== token.toLowerCase();
|
|
@@ -31675,15 +31697,16 @@ var findMatches = (content, books, lang_extra) => {
|
|
|
31675
31697
|
return [substring, positions];
|
|
31676
31698
|
}).filter((i) => !!i);
|
|
31677
31699
|
const possiblyOverlappingMatches = bookSubStrings.map(([substring, positions]) => {
|
|
31700
|
+
let pattern = null;
|
|
31701
|
+
try {
|
|
31702
|
+
pattern = new RegExp(substring + postBookMatch, "iy");
|
|
31703
|
+
} catch (e) {
|
|
31704
|
+
return [];
|
|
31705
|
+
}
|
|
31678
31706
|
return positions.map(
|
|
31679
31707
|
(i) => {
|
|
31680
|
-
|
|
31681
|
-
|
|
31682
|
-
pattern = new RegExp(substring + postBookMatch, "ig");
|
|
31683
|
-
} catch (e) {
|
|
31684
|
-
return null;
|
|
31685
|
-
}
|
|
31686
|
-
const match = normalizedContent.slice(i).match(pattern)?.[0]?.replace(tail, "").trim();
|
|
31708
|
+
pattern.lastIndex = i;
|
|
31709
|
+
const match = pattern.exec(normalizedContent)?.[0]?.replace(tail, "").trim();
|
|
31687
31710
|
if (!match) return null;
|
|
31688
31711
|
const len = match.length;
|
|
31689
31712
|
const pos = i;
|
|
@@ -31693,22 +31716,35 @@ var findMatches = (content, books, lang_extra) => {
|
|
|
31693
31716
|
}
|
|
31694
31717
|
);
|
|
31695
31718
|
}).flat().filter((i) => !!i);
|
|
31719
|
+
const byStart = [...possiblyOverlappingMatches].sort((a, b) => a[1] - b[1]);
|
|
31720
|
+
const maxEndUpTo = [];
|
|
31721
|
+
byStart.forEach(([, , e1], i) => maxEndUpTo.push(Math.max(e1, i ? maxEndUpTo[i - 1] : -Infinity)));
|
|
31722
|
+
const cutPoint = (string, end) => {
|
|
31723
|
+
let lo = 0, hi = byStart.length - 1, first = byStart.length;
|
|
31724
|
+
while (lo <= hi) {
|
|
31725
|
+
const mid = lo + hi >> 1;
|
|
31726
|
+
if (maxEndUpTo[mid] > end) {
|
|
31727
|
+
first = mid;
|
|
31728
|
+
hi = mid - 1;
|
|
31729
|
+
} else lo = mid + 1;
|
|
31730
|
+
}
|
|
31731
|
+
for (let k = first; k < byStart.length && byStart[k][1] < end; k++) {
|
|
31732
|
+
const [s, s1, e1] = byStart[k];
|
|
31733
|
+
if (s !== string && e1 > end) return s1;
|
|
31734
|
+
}
|
|
31735
|
+
return end;
|
|
31736
|
+
};
|
|
31696
31737
|
const matchesWithReferences = possiblyOverlappingMatches.map(([string, start, end]) => {
|
|
31697
|
-
const
|
|
31698
|
-
const hasOverlap = overLappingItems.length > 0;
|
|
31699
|
-
const newEnd = hasOverlap ? Math.min(...overLappingItems.map(([s, s1, e1]) => s1)) : end;
|
|
31738
|
+
const newEnd = cutPoint(string, end);
|
|
31700
31739
|
const newString = normalizedContent.slice(start, newEnd);
|
|
31701
31740
|
return newString.replace(tail, "").trim();
|
|
31702
31741
|
}).filter((i) => !!i);
|
|
31703
|
-
const matches = matchesWithReferences.map((string) => {
|
|
31742
|
+
const matches = [...new Set(matchesWithReferences)].map((string) => {
|
|
31704
31743
|
const pattern = new RegExp(string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "ig");
|
|
31705
31744
|
const matches2 = normalizedContent.match(pattern)?.map((i) => i.trim().replace(tail, ""));
|
|
31706
31745
|
return matches2;
|
|
31707
|
-
}).flat()
|
|
31708
|
-
|
|
31709
|
-
return [...prev, current];
|
|
31710
|
-
}, []).filter((i) => !!i);
|
|
31711
|
-
return matches;
|
|
31746
|
+
}).flat();
|
|
31747
|
+
return [...new Set(matches)].filter((i) => !!i);
|
|
31712
31748
|
};
|
|
31713
31749
|
function findMatchIndexes(content, matches, lookupReference2, lang_extra) {
|
|
31714
31750
|
const tail = lang_extra.tail ? new RegExp(lang_extra.tail, "ig") : /[^0-9]+$/;
|
|
@@ -31779,7 +31815,7 @@ var processReferenceDetection = (content, books, lang_extra, lookupReference2, c
|
|
|
31779
31815
|
var collectReferencesWithContext = (content, books, lang_extra, lookupReference2, options) => {
|
|
31780
31816
|
const explicitMatches = findMatches(content, books, lang_extra);
|
|
31781
31817
|
const explicitIndices = findMatchIndexes(content, explicitMatches, lookupReference2, lang_extra) || [];
|
|
31782
|
-
const impliedMatches = findImpliedReferences(content, explicitMatches, explicitIndices, lookupReference2, options);
|
|
31818
|
+
const impliedMatches = findImpliedReferences(content, explicitMatches, explicitIndices, lookupReference2, options, lang_extra);
|
|
31783
31819
|
const explicitMatchesWithRefs = explicitIndices.map(([start, end]) => {
|
|
31784
31820
|
const originalText = content.substring(start, end);
|
|
31785
31821
|
const verification = lookupReference2(originalText);
|
|
@@ -31870,7 +31906,21 @@ var getNearestBookContext = (position, bookContexts, maxDistance) => {
|
|
|
31870
31906
|
}
|
|
31871
31907
|
return bestContext;
|
|
31872
31908
|
};
|
|
31873
|
-
var
|
|
31909
|
+
var CITATION_CONNECTIVES = ["including", "namely", "e.g", "i.e"];
|
|
31910
|
+
var bindsToBookContext = (tail, joiners) => {
|
|
31911
|
+
const trimmed = tail.replace(/\s+$/, "");
|
|
31912
|
+
if (!trimmed) return true;
|
|
31913
|
+
if (/[;&([]$/.test(trimmed)) return true;
|
|
31914
|
+
const list = Array.isArray(joiners) ? joiners : joiners && joiners.patterns || [];
|
|
31915
|
+
const words = /* @__PURE__ */ new Set([
|
|
31916
|
+
...list.filter((j) => typeof j === "string" && /[a-z]/i.test(j)).map((j) => j.toLowerCase().replace(/\.+$/, "").split(/\s+/).pop()),
|
|
31917
|
+
...CITATION_CONNECTIVES
|
|
31918
|
+
]);
|
|
31919
|
+
const lastWord = (trimmed.match(/[A-Za-z.']+$/) || [""])[0].toLowerCase().replace(/[.']+$/, "");
|
|
31920
|
+
return lastWord !== "" && words.has(lastWord);
|
|
31921
|
+
};
|
|
31922
|
+
var findImpliedReferences = (content, explicitMatches, explicitIndices, lookupReference2, options, lang_extra = {}) => {
|
|
31923
|
+
const joiners = lang_extra && (lang_extra.unrestrictedJoiners || lang_extra.joiners) || ["and", ";", ",", "&", "compare", "see also", "see", "cf", "c.f.", "cited at", "also"];
|
|
31874
31924
|
const matches = [];
|
|
31875
31925
|
const bookContexts = findBookContexts(content, explicitMatches, explicitIndices, lookupReference2);
|
|
31876
31926
|
const verseGroupPattern = /\b(?:vv?\.?\s*|vs\.?\s*|verses?\s+)([\d:,\s–—-]+?)(?=\s*[).;\n]|$)/gi;
|
|
@@ -31889,19 +31939,21 @@ var findImpliedReferences = (content, explicitMatches, explicitIndices, lookupRe
|
|
|
31889
31939
|
}
|
|
31890
31940
|
}
|
|
31891
31941
|
const chapterVersePattern = /\b(\d+):(\d+(?:[–—-]\d+)?(?:\s*,\s*\d+(?:[–—-]\d+)?)*)/g;
|
|
31942
|
+
const insideExplicit = spanCoverage(explicitIndices || []);
|
|
31892
31943
|
while ((match = chapterVersePattern.exec(content)) !== null) {
|
|
31893
31944
|
const fullMatch = match[0];
|
|
31894
31945
|
const chapter = match[1];
|
|
31895
31946
|
const verses = match[2];
|
|
31896
31947
|
const position = match.index;
|
|
31897
|
-
const isPartOfExplicit =
|
|
31898
|
-
([start, end]) => position >= start && position < end
|
|
31899
|
-
);
|
|
31948
|
+
const isPartOfExplicit = insideExplicit(position);
|
|
31900
31949
|
if (isPartOfExplicit) {
|
|
31901
31950
|
continue;
|
|
31902
31951
|
}
|
|
31952
|
+
if (/^\s*(?:[ap]\.?\s?m\b\.?|o['’]?clock\b)/i.test(content.slice(position + fullMatch.length))) {
|
|
31953
|
+
continue;
|
|
31954
|
+
}
|
|
31903
31955
|
const context = getNearestBookContext(position, bookContexts, options.maxContextDistance);
|
|
31904
|
-
if (context) {
|
|
31956
|
+
if (context && (options.strictImpliedBooks === false || bindsToBookContext(content.slice(context.endPosition, position), joiners))) {
|
|
31905
31957
|
const impliedRef = `${context.book} ${chapter}:${verses}`;
|
|
31906
31958
|
const verification = lookupReference2(impliedRef);
|
|
31907
31959
|
if (verification.verse_ids && verification.verse_ids.length > 0) {
|
|
@@ -31998,6 +32050,11 @@ var convertCanon = (verseIds, options = {}) => {
|
|
|
31998
32050
|
return result;
|
|
31999
32051
|
};
|
|
32000
32052
|
|
|
32053
|
+
// src/slug.mjs
|
|
32054
|
+
function toSlug(ref) {
|
|
32055
|
+
return ref.trim().toLowerCase().replace(/[־᠆‐‒–—―﹣-‑]+/gu, "-").replace(/[\s:]+/g, ".").replace(/\.+/g, ".").replace(/;\./g, ";").replace(/,\./g, ",").replace(/\.;/g, ";").replace(/\.,/g, ",");
|
|
32056
|
+
}
|
|
32057
|
+
|
|
32001
32058
|
// src/config.mjs
|
|
32002
32059
|
var MAX_RANGE_SIZE = 1e3;
|
|
32003
32060
|
var MAX_CHAPTER = 200;
|
|
@@ -32031,11 +32088,20 @@ for (const [canonKey, canonData] of Object.entries(extraCanons)) {
|
|
|
32031
32088
|
});
|
|
32032
32089
|
}
|
|
32033
32090
|
}
|
|
32034
|
-
var
|
|
32035
|
-
|
|
32036
|
-
|
|
32037
|
-
|
|
32038
|
-
|
|
32091
|
+
var INDEX_CACHE_LIMIT = 4;
|
|
32092
|
+
var refIndexCache = /* @__PURE__ */ new Map();
|
|
32093
|
+
var verseIdIndexCache = /* @__PURE__ */ new Map();
|
|
32094
|
+
var cachedIndex = (cache, key, build) => {
|
|
32095
|
+
if (cache.has(key)) {
|
|
32096
|
+
const value2 = cache.get(key);
|
|
32097
|
+
cache.delete(key);
|
|
32098
|
+
cache.set(key, value2);
|
|
32099
|
+
return value2;
|
|
32100
|
+
}
|
|
32101
|
+
const value = build();
|
|
32102
|
+
cache.set(key, value);
|
|
32103
|
+
if (cache.size > INDEX_CACHE_LIMIT) cache.delete(cache.keys().next().value);
|
|
32104
|
+
return value;
|
|
32039
32105
|
};
|
|
32040
32106
|
var hashConfig = (config) => {
|
|
32041
32107
|
return (config?.language || "en") + ":" + (config?.canon || DEFAULTS.canon);
|
|
@@ -32112,7 +32178,8 @@ var lookupReference = function(query, optionsOrLanguage = {}, legacyConfig = nul
|
|
|
32112
32178
|
const effectiveLanguage = getEffectiveLanguage(language);
|
|
32113
32179
|
const { convertTo, includeParallel } = lookupConfig;
|
|
32114
32180
|
const canon = lookupConfig.canon || getEffectiveCanon();
|
|
32115
|
-
const
|
|
32181
|
+
const limit = rangeLimit(lookupConfig.maxVerses);
|
|
32182
|
+
const lookupResult = lookupInLanguage(query, effectiveLanguage, canon, limit);
|
|
32116
32183
|
const verse_ids = lookupResult.verse_ids;
|
|
32117
32184
|
const errors = lookupResult.errors;
|
|
32118
32185
|
if (verse_ids?.length) {
|
|
@@ -32141,7 +32208,7 @@ var lookupReference = function(query, optionsOrLanguage = {}, legacyConfig = nul
|
|
|
32141
32208
|
return result;
|
|
32142
32209
|
}
|
|
32143
32210
|
if (!lookupConfig.noMulti) {
|
|
32144
|
-
const fallbackResult = lookupWithLanguageFallback(query, effectiveLanguage, canon);
|
|
32211
|
+
const fallbackResult = lookupWithLanguageFallback(query, effectiveLanguage, canon, limit);
|
|
32145
32212
|
if (fallbackResult.verse_ids.length === 0 && errors) {
|
|
32146
32213
|
fallbackResult.error = errors.join("; ");
|
|
32147
32214
|
}
|
|
@@ -32154,14 +32221,17 @@ var lookupReference = function(query, optionsOrLanguage = {}, legacyConfig = nul
|
|
|
32154
32221
|
error: errors ? errors.join("; ") : void 0
|
|
32155
32222
|
};
|
|
32156
32223
|
};
|
|
32157
|
-
var
|
|
32224
|
+
var rangeLimit = function(maxVerses) {
|
|
32225
|
+
return Number.isInteger(maxVerses) && maxVerses > 0 ? maxVerses : MAX_RANGE_SIZE;
|
|
32226
|
+
};
|
|
32227
|
+
var lookupInLanguage = function(query, language, canon = null, limit = MAX_RANGE_SIZE) {
|
|
32158
32228
|
const config = getLanguageConfig(language, canon);
|
|
32159
32229
|
let ref = cleanReference(query, config);
|
|
32160
32230
|
let refs = splitReferences(ref, config);
|
|
32161
32231
|
let verse_ids = [];
|
|
32162
32232
|
let errors = [];
|
|
32163
32233
|
for (let i in refs) {
|
|
32164
|
-
const result = lookupSingleRef(refs[i], config);
|
|
32234
|
+
const result = lookupSingleRef(refs[i], config, limit);
|
|
32165
32235
|
if (result && result.error) {
|
|
32166
32236
|
errors.push(result.error);
|
|
32167
32237
|
} else if (Array.isArray(result)) {
|
|
@@ -32175,10 +32245,17 @@ var lookupInLanguage = function(query, language, canon = null) {
|
|
|
32175
32245
|
errors: errors.length > 0 ? errors : void 0
|
|
32176
32246
|
};
|
|
32177
32247
|
};
|
|
32178
|
-
var
|
|
32248
|
+
var detectionLookup = function(language) {
|
|
32249
|
+
const seen = /* @__PURE__ */ new Map();
|
|
32250
|
+
return (query) => {
|
|
32251
|
+
if (!seen.has(query)) seen.set(query, lookupReference(query, { language, noMulti: true }));
|
|
32252
|
+
return seen.get(query);
|
|
32253
|
+
};
|
|
32254
|
+
};
|
|
32255
|
+
var lookupWithLanguageFallback = function(query, targetLanguage, canon = null, limit = MAX_RANGE_SIZE) {
|
|
32179
32256
|
const fallbackLanguages = targetLanguage !== "en" ? ["en", ...Object.keys(raw_lang).filter((lang) => lang !== "en" && lang !== targetLanguage)] : Object.keys(raw_lang).filter((lang) => lang !== targetLanguage);
|
|
32180
32257
|
for (const lang of fallbackLanguages) {
|
|
32181
|
-
const lookupResult = lookupInLanguage(query, lang, canon);
|
|
32258
|
+
const lookupResult = lookupInLanguage(query, lang, canon, limit);
|
|
32182
32259
|
const verse_ids = lookupResult.verse_ids;
|
|
32183
32260
|
if (verse_ids?.length) {
|
|
32184
32261
|
const refInTargetLanguage = generateReference(verse_ids, { language: targetLanguage, canon });
|
|
@@ -32195,9 +32272,9 @@ var lookupWithLanguageFallback = function(query, targetLanguage, canon = null) {
|
|
|
32195
32272
|
"verse_ids": []
|
|
32196
32273
|
};
|
|
32197
32274
|
};
|
|
32198
|
-
var lookupSingleRef = function(ref, config) {
|
|
32275
|
+
var lookupSingleRef = function(ref, config, limit = MAX_RANGE_SIZE) {
|
|
32199
32276
|
const booksWithDashRegex = /^(joseph|조셉)/i;
|
|
32200
|
-
if (!booksWithDashRegex.test(ref) && ref.match(/[—-](\d\s)*[\D]/ig)) return lookupMultiBookRange(ref, config);
|
|
32277
|
+
if (!booksWithDashRegex.test(ref) && ref.match(/[—-](\d\s)*[\D]/ig)) return lookupMultiBookRange(ref, config, limit);
|
|
32201
32278
|
let book = getBook(ref, config);
|
|
32202
32279
|
if (!book) {
|
|
32203
32280
|
return {
|
|
@@ -32206,7 +32283,7 @@ var lookupSingleRef = function(ref, config) {
|
|
|
32206
32283
|
};
|
|
32207
32284
|
}
|
|
32208
32285
|
let ranges = getRanges(ref, book);
|
|
32209
|
-
let verse_ids = loadVerseIds(book, ranges, config);
|
|
32286
|
+
let verse_ids = loadVerseIds(book, ranges, config, limit);
|
|
32210
32287
|
return verse_ids;
|
|
32211
32288
|
};
|
|
32212
32289
|
var validateVerseIdsMixed = function(verse_ids) {
|
|
@@ -32242,7 +32319,7 @@ var generateReference = function(verse_ids, optionsOrLanguage = {}, legacyOption
|
|
|
32242
32319
|
let ref = refs.join("; ");
|
|
32243
32320
|
return ref;
|
|
32244
32321
|
};
|
|
32245
|
-
var lookupMultiBookRange = function(cleanRef, config) {
|
|
32322
|
+
var lookupMultiBookRange = function(cleanRef, config, limit = MAX_RANGE_SIZE) {
|
|
32246
32323
|
let range = cleanRef.split(/[—-]/);
|
|
32247
32324
|
if (!range[0].match(/[:]/)) {
|
|
32248
32325
|
if (range[0].match(/\d+\s*$/)) range[0] = range[0].trim() + ":1";
|
|
@@ -32263,7 +32340,7 @@ var lookupMultiBookRange = function(cleanRef, config) {
|
|
|
32263
32340
|
let end = lookupSingleRef(range[1], config)[0];
|
|
32264
32341
|
let all_verse_ids = [];
|
|
32265
32342
|
for (let i = start; i <= end; i++) {
|
|
32266
|
-
if (all_verse_ids.length >=
|
|
32343
|
+
if (all_verse_ids.length >= limit) break;
|
|
32267
32344
|
all_verse_ids.push(i);
|
|
32268
32345
|
}
|
|
32269
32346
|
return all_verse_ids;
|
|
@@ -32276,41 +32353,44 @@ var strToHash = function(str) {
|
|
|
32276
32353
|
}
|
|
32277
32354
|
return `==${hash}==`;
|
|
32278
32355
|
};
|
|
32356
|
+
var cleanRulesCache = /* @__PURE__ */ new WeakMap();
|
|
32357
|
+
var cleanRules = function(config) {
|
|
32358
|
+
let rules = cleanRulesCache.get(config);
|
|
32359
|
+
if (rules) return rules;
|
|
32360
|
+
const pre = (config.raw_regex.pre_rules || []).map((rule) => [new RegExp(rule.pattern ?? rule[0], "ig"), rule.replacement ?? rule[1] ?? ""]);
|
|
32361
|
+
const [wordBreak, buffer] = config.raw_regex.spacing || ["\\b", ""];
|
|
32362
|
+
let srcbooks = config.raw_regex.books;
|
|
32363
|
+
let dstbooks = buffer ? config.raw_regex.books.map((i) => [i[1], i[1]]) : [];
|
|
32364
|
+
let bookMatchList = [...dstbooks, ...srcbooks].sort((a, b) => b[0].length - a[0].length);
|
|
32365
|
+
let hashCypher = {};
|
|
32366
|
+
for (const [, book] of bookMatchList) hashCypher[book] = strToHash(book);
|
|
32367
|
+
const bookRules = bookMatchList.map(([pattern, book]) => [new RegExp(wordBreak + buffer + pattern + buffer + "\\.*" + wordBreak, "ig"), hashCypher[book] || book]);
|
|
32368
|
+
const hashes = Object.values(hashCypher);
|
|
32369
|
+
rules = { pre, buffer, books: Object.keys(hashCypher), hashes, bookRules, hashRe: new RegExp(hashes.join("|"), "g") };
|
|
32370
|
+
cleanRulesCache.set(config, rules);
|
|
32371
|
+
return rules;
|
|
32372
|
+
};
|
|
32279
32373
|
var cleanReference = function(messyReference, config) {
|
|
32280
32374
|
let ref = messyReference.replace(/[\s]+/g, " ").trim();
|
|
32281
32375
|
ref = ref.replace(/(\d)\s+and\s+(\d)/g, "$1,$2");
|
|
32282
32376
|
ref = ref.replace(/[()]/g, " ");
|
|
32283
32377
|
ref = ref.replace(/\bsec(?:tion)?\b\.?/ig, " ");
|
|
32284
|
-
|
|
32285
|
-
|
|
32286
|
-
|
|
32287
|
-
|
|
32288
|
-
}
|
|
32378
|
+
ref = ref.replace(/(\d)[.](?=(?:\d[.\s]*)?\p{L})/gu, "$1 ");
|
|
32379
|
+
ref = ref.replace(/(\d)\s+(?=\d[\s.]*\p{L}[\p{L}\s.&'-]{0,40}?[\s.]\d)/gu, "$1; ");
|
|
32380
|
+
const rules = cleanRules(config);
|
|
32381
|
+
for (const [re, replacement] of rules.pre) ref = ref.replace(re, replacement);
|
|
32289
32382
|
ref = ref.replace(/(\d+)[.](\d+)/g, "$1:$2");
|
|
32290
32383
|
ref = ref.replace(/[.]/g, "");
|
|
32291
32384
|
ref = ref.replace(/;/g, "; ");
|
|
32292
32385
|
ref = ref.replace(/^([0-9;,:-]+)(\d+)/g, "$1 $2");
|
|
32293
32386
|
ref = ref.replace(/([–-])(\D+)/g, " $1 $2 ");
|
|
32294
|
-
const
|
|
32295
|
-
|
|
32296
|
-
let dstbooks = buffer ? config.raw_regex.books.map((i) => [i[1], i[1]]) : [];
|
|
32297
|
-
let bookMatchList = [...dstbooks, ...srcbooks].sort((a, b) => b[0].length - a[0].length);
|
|
32298
|
-
regex = bookMatchList;
|
|
32299
|
-
let hashCypher = {};
|
|
32300
|
-
for (let i in regex) {
|
|
32301
|
-
const [, book] = regex[i];
|
|
32302
|
-
const hash = strToHash(book);
|
|
32303
|
-
hashCypher[book] = hash;
|
|
32304
|
-
}
|
|
32305
|
-
for (let i in regex) {
|
|
32306
|
-
var re = new RegExp(wordBreak + buffer + regex[i][0] + buffer + "\\.*" + wordBreak, "ig");
|
|
32307
|
-
let replacement = hashCypher[regex[i][1]] || regex[i][1];
|
|
32387
|
+
const { buffer, books, hashes } = rules;
|
|
32388
|
+
for (const [re, replacement] of rules.bookRules) {
|
|
32308
32389
|
ref = (buffer + ref + buffer).replace(re, replacement).trim();
|
|
32309
32390
|
}
|
|
32310
|
-
|
|
32311
|
-
const hashes = Object.values(hashCypher);
|
|
32391
|
+
ref = ref.replace(/(\d)\s*(==\d+==)(?=\s*\d)/g, "$1; $2");
|
|
32312
32392
|
ref = ref.replace(
|
|
32313
|
-
|
|
32393
|
+
rules.hashRe,
|
|
32314
32394
|
function(match) {
|
|
32315
32395
|
const bookValue = books[hashes.indexOf(match)];
|
|
32316
32396
|
return bookValue + " ";
|
|
@@ -32338,6 +32418,11 @@ var splitReferences = function(compoundReference, config) {
|
|
|
32338
32418
|
let completeRefs = [];
|
|
32339
32419
|
for (let i in refs) {
|
|
32340
32420
|
const ref = refs[i];
|
|
32421
|
+
const multiBook = ref.match(/^(.*?\D)\s*\d[\d:,]*\s*[—-]\s*((?:\d\s*)?\D+?)\s*\d[\d:,]*$/);
|
|
32422
|
+
if (multiBook && bookExists(multiBook[1].trim(), config) && bookExists(multiBook[2].trim(), config)) {
|
|
32423
|
+
completeRefs.push(ref.trim());
|
|
32424
|
+
continue;
|
|
32425
|
+
}
|
|
32341
32426
|
let pieces = ref.split(/([0-9:,-]+)$/);
|
|
32342
32427
|
const firstPiece = pieces[0].trim();
|
|
32343
32428
|
runningBook = bookExists(firstPiece, config) ? firstPiece : runningBook;
|
|
@@ -32440,11 +32525,11 @@ var getRanges = function(ref) {
|
|
|
32440
32525
|
;
|
|
32441
32526
|
return ranges;
|
|
32442
32527
|
};
|
|
32443
|
-
var loadVerseIds = function(book, ranges, config) {
|
|
32528
|
+
var loadVerseIds = function(book, ranges, config, limit = MAX_RANGE_SIZE) {
|
|
32444
32529
|
let refIndex = loadRefIndex(config);
|
|
32445
32530
|
let verseList = [];
|
|
32446
32531
|
for (let i in ranges) {
|
|
32447
|
-
if (verseList.length >=
|
|
32532
|
+
if (verseList.length >= limit) break;
|
|
32448
32533
|
let range = ranges[i];
|
|
32449
32534
|
let matches = range.match(/(\d+): *([\dX]+)-*([\dX]*)/);
|
|
32450
32535
|
if (!matches) continue;
|
|
@@ -32458,7 +32543,7 @@ var loadVerseIds = function(book, ranges, config) {
|
|
|
32458
32543
|
start = Math.max(1, Math.min(start, MAX_VERSE));
|
|
32459
32544
|
end = Math.max(start, Math.min(end, MAX_VERSE));
|
|
32460
32545
|
for (let verse_num = start; verse_num <= end; verse_num++) {
|
|
32461
|
-
if (verseList.length >=
|
|
32546
|
+
if (verseList.length >= limit) break;
|
|
32462
32547
|
if (refIndex[book]?.[chapter]?.[verse_num]) {
|
|
32463
32548
|
verseList.push(refIndex[book][chapter][verse_num]);
|
|
32464
32549
|
}
|
|
@@ -32548,10 +32633,9 @@ var loadRefsFromRanges = function(ranges, config) {
|
|
|
32548
32633
|
return refs;
|
|
32549
32634
|
};
|
|
32550
32635
|
var loadRefIndex = function(config) {
|
|
32551
|
-
|
|
32552
|
-
|
|
32553
|
-
|
|
32554
|
-
}
|
|
32636
|
+
return cachedIndex(refIndexCache, hashConfig(config), () => buildRefIndex(config));
|
|
32637
|
+
};
|
|
32638
|
+
var buildRefIndex = function(config) {
|
|
32555
32639
|
let refIndex = {};
|
|
32556
32640
|
let verse_id = 1;
|
|
32557
32641
|
let book_list = Object.keys(config.raw_index);
|
|
@@ -32568,15 +32652,12 @@ var loadRefIndex = function(config) {
|
|
|
32568
32652
|
}
|
|
32569
32653
|
}
|
|
32570
32654
|
}
|
|
32571
|
-
indexCache.refIndex = refIndex;
|
|
32572
|
-
indexCache.refIndexHash = configHash;
|
|
32573
32655
|
return refIndex;
|
|
32574
32656
|
};
|
|
32575
32657
|
var loadVerseIdIndex = function(config) {
|
|
32576
|
-
|
|
32577
|
-
|
|
32578
|
-
|
|
32579
|
-
}
|
|
32658
|
+
return cachedIndex(verseIdIndexCache, hashConfig(config), () => buildVerseIdIndex(config));
|
|
32659
|
+
};
|
|
32660
|
+
var buildVerseIdIndex = function(config) {
|
|
32580
32661
|
let verseIdIndex = [null];
|
|
32581
32662
|
let book_list = Object.keys(config.raw_index);
|
|
32582
32663
|
for (let a in book_list) {
|
|
@@ -32589,8 +32670,6 @@ var loadVerseIdIndex = function(config) {
|
|
|
32589
32670
|
}
|
|
32590
32671
|
}
|
|
32591
32672
|
}
|
|
32592
|
-
indexCache.verseIdIndex = verseIdIndex;
|
|
32593
|
-
indexCache.verseIdIndexHash = configHash;
|
|
32594
32673
|
return verseIdIndex;
|
|
32595
32674
|
};
|
|
32596
32675
|
var bookExists = function(book, config) {
|
|
@@ -32620,7 +32699,7 @@ var restrictJoinersToStructural = (lang_extra) => {
|
|
|
32620
32699
|
} else {
|
|
32621
32700
|
joiners = [...STRUCTURAL_JOINERS];
|
|
32622
32701
|
}
|
|
32623
|
-
return { ...src, joiners };
|
|
32702
|
+
return { ...src, joiners, unrestrictedJoiners: src.joiners };
|
|
32624
32703
|
};
|
|
32625
32704
|
var detectReferences = (content, callBack, options = null) => {
|
|
32626
32705
|
if (typeof options === "string" || options === null) {
|
|
@@ -32634,7 +32713,10 @@ var detectReferences = (content, callBack, options = null) => {
|
|
|
32634
32713
|
maxContextDistance: 500,
|
|
32635
32714
|
enableImpliedBooks: true,
|
|
32636
32715
|
enableVerseAbbrev: true,
|
|
32637
|
-
chainAcrossMarkers: true
|
|
32716
|
+
chainAcrossMarkers: true,
|
|
32717
|
+
// A bare "6:3" binds to an earlier book only when the token before it is
|
|
32718
|
+
// citation material. false restores pre-1.0.98 distance-only binding.
|
|
32719
|
+
strictImpliedBooks: true
|
|
32638
32720
|
};
|
|
32639
32721
|
const finalOptions = { ...defaultOptions, ...options };
|
|
32640
32722
|
callBack = callBack ? callBack : (i) => {
|
|
@@ -32647,9 +32729,9 @@ var detectReferences = (content, callBack, options = null) => {
|
|
|
32647
32729
|
const books = [...dst, ...src];
|
|
32648
32730
|
const langExtra = finalOptions.chainAcrossMarkers === false ? restrictJoinersToStructural(config.lang_extra) : config.lang_extra;
|
|
32649
32731
|
if (finalOptions.contextAware) {
|
|
32650
|
-
return detectReferencesWithContext(content, books, langExtra, (
|
|
32732
|
+
return detectReferencesWithContext(content, books, langExtra, detectionLookup(effectiveLanguage), callBack, finalOptions, generateReference);
|
|
32651
32733
|
}
|
|
32652
|
-
return processReferenceDetection(content, books, langExtra, (
|
|
32734
|
+
return processReferenceDetection(content, books, langExtra, detectionLookup(effectiveLanguage), callBack);
|
|
32653
32735
|
};
|
|
32654
32736
|
var findReferences = (content, options = null) => {
|
|
32655
32737
|
if (typeof options === "string" || options === null) {
|
|
@@ -32664,7 +32746,10 @@ var findReferences = (content, options = null) => {
|
|
|
32664
32746
|
enableVerseAbbrev: true,
|
|
32665
32747
|
abbreviations: true,
|
|
32666
32748
|
chapterOnly: true,
|
|
32667
|
-
chainAcrossMarkers: true
|
|
32749
|
+
chainAcrossMarkers: true,
|
|
32750
|
+
// A bare "6:3" binds to an earlier book only when the token before it is
|
|
32751
|
+
// citation material. false restores pre-1.0.98 distance-only binding.
|
|
32752
|
+
strictImpliedBooks: true
|
|
32668
32753
|
};
|
|
32669
32754
|
const finalOptions = { ...defaultOptions, ...options };
|
|
32670
32755
|
const effectiveLanguage = getEffectiveLanguage(finalOptions.language);
|
|
@@ -32672,7 +32757,7 @@ var findReferences = (content, options = null) => {
|
|
|
32672
32757
|
const src = config.raw_regex.books.map((i) => i[0]);
|
|
32673
32758
|
const dst = [...new Set(config.raw_regex.books.map((i) => i[1]))];
|
|
32674
32759
|
const books = [...dst, ...src];
|
|
32675
|
-
const lookup = (
|
|
32760
|
+
const lookup = detectionLookup(effectiveLanguage);
|
|
32676
32761
|
const langExtra = finalOptions.chainAcrossMarkers === false ? restrictJoinersToStructural(config.lang_extra) : config.lang_extra;
|
|
32677
32762
|
const found = finalOptions.contextAware ? collectReferencesWithContext(content, books, langExtra, lookup, finalOptions) : collectReferences(content, books, langExtra, lookup);
|
|
32678
32763
|
let records = found.filter((m) => m.verse_ids.length > 0).map(({ start, end, text, verse_ids }) => ({
|
|
@@ -32763,9 +32848,15 @@ var applyDetectionFlags = (records, opts) => {
|
|
|
32763
32848
|
}
|
|
32764
32849
|
return out;
|
|
32765
32850
|
};
|
|
32851
|
+
var languageConfigCache = /* @__PURE__ */ new Map();
|
|
32766
32852
|
var getLanguageConfig = function(language, canon = null) {
|
|
32767
32853
|
const effectiveLanguage = language && raw_lang[language] ? language : "en";
|
|
32768
32854
|
const effectiveCanon = canon && extraCanons[canon] ? canon : DEFAULTS.canon;
|
|
32855
|
+
const key = `${effectiveLanguage}|${effectiveCanon}`;
|
|
32856
|
+
if (!languageConfigCache.has(key)) languageConfigCache.set(key, buildLanguageConfig(effectiveLanguage, effectiveCanon));
|
|
32857
|
+
return languageConfigCache.get(key);
|
|
32858
|
+
};
|
|
32859
|
+
var buildLanguageConfig = function(effectiveLanguage, effectiveCanon) {
|
|
32769
32860
|
const config = {
|
|
32770
32861
|
language: effectiveLanguage,
|
|
32771
32862
|
canon: effectiveCanon,
|
package/dist/scriptures.d.ts
CHANGED
|
@@ -26,13 +26,27 @@ export type DetectionCallback = (reference: string) => string;
|
|
|
26
26
|
*/
|
|
27
27
|
export type LanguageCode = 'en' | 'ko' | 'de' | 'fr' | 'swe' | 'ru' | 'jp' | 'vn' | 'tr' | 'sl' | 'eo' | null;
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Options for lookupReference
|
|
31
|
+
*/
|
|
32
|
+
export interface LookupOptions {
|
|
33
|
+
/** Language code. If not provided, uses setLanguage value or defaults to 'en' */
|
|
34
|
+
language?: LanguageCode;
|
|
35
|
+
/** Canon versification: 'lds', 'rlds', ... */
|
|
36
|
+
canon?: string;
|
|
37
|
+
/** If true, no fallback to other languages */
|
|
38
|
+
noMulti?: boolean;
|
|
39
|
+
/** The most verses one range expands to (default 1000); a longer range is cut there */
|
|
40
|
+
maxVerses?: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
29
43
|
/**
|
|
30
44
|
* Looks up a scripture reference and returns structured data
|
|
31
45
|
* @param query - The scripture reference string to parse (e.g., "John 3:16")
|
|
32
|
-
* @param
|
|
46
|
+
* @param options - A language code, or LookupOptions. If no language is given, uses setLanguage value or defaults to 'en'
|
|
33
47
|
* @returns Object containing the query, parsed reference, and verse IDs
|
|
34
48
|
*/
|
|
35
|
-
export function lookupReference(query: string,
|
|
49
|
+
export function lookupReference(query: string, options?: LanguageCode | LookupOptions): LookupResult;
|
|
36
50
|
|
|
37
51
|
/**
|
|
38
52
|
* Generates a human-readable scripture reference from verse IDs
|
|
@@ -58,6 +72,13 @@ export function setLanguage(language: LanguageCode): void;
|
|
|
58
72
|
*/
|
|
59
73
|
export function detectReferences(content: string, callback?: DetectionCallback, language?: LanguageCode): string;
|
|
60
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Converts a reference string into a scripture.guide URL slug
|
|
77
|
+
* @param ref - Reference string, e.g. "John 3:16-18"
|
|
78
|
+
* @returns URL slug, e.g. "john.3.16-18"
|
|
79
|
+
*/
|
|
80
|
+
export function toSlug(ref: string): string;
|
|
81
|
+
|
|
61
82
|
// Aliases for convenience
|
|
62
83
|
export { setLanguage as lang };
|
|
63
84
|
export { setLanguage as language };
|
package/dist/scriptures.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* scripture-guide v1.
|
|
1
|
+
/* scripture-guide v1.1.1 */
|
|
2
2
|
|
|
3
3
|
// src/data/canons/bible/structure.mjs
|
|
4
4
|
var structure_default = {
|
|
@@ -849,7 +849,7 @@ var structure_default = {
|
|
|
849
849
|
"first_verse_id": 17317
|
|
850
850
|
},
|
|
851
851
|
{
|
|
852
|
-
"key": "
|
|
852
|
+
"key": "song_of_solomon",
|
|
853
853
|
"order": 22,
|
|
854
854
|
"chapters": 8,
|
|
855
855
|
"verses": [
|
|
@@ -2489,9 +2489,11 @@ var en_default = {
|
|
|
2489
2489
|
]
|
|
2490
2490
|
},
|
|
2491
2491
|
"song_of_solomon": {
|
|
2492
|
-
"name": "Song
|
|
2493
|
-
"pattern": "(?<!solomon's )(the )*song*\\.*(?: *of *solomon)*",
|
|
2492
|
+
"name": "Solomon's Song",
|
|
2493
|
+
"pattern": "(?<!solomon['\u2019]?s )(the )*song*\\.*(?: *of *solomon)*",
|
|
2494
2494
|
"alt": [
|
|
2495
|
+
"solomon\u2019s song",
|
|
2496
|
+
"solomons song",
|
|
2495
2497
|
"song",
|
|
2496
2498
|
"sos",
|
|
2497
2499
|
"ss",
|
|
@@ -31430,10 +31432,12 @@ var rangesOverlap = (range1, range2) => {
|
|
|
31430
31432
|
var removeOverlaps = (matches, content, preferenceResolver = null) => {
|
|
31431
31433
|
if (matches.length <= 1) return matches;
|
|
31432
31434
|
const result = [];
|
|
31435
|
+
const sorted = matches.every((m, i) => i === 0 || m[0] >= matches[i - 1][0]);
|
|
31436
|
+
let includedMaxEnd = -Infinity;
|
|
31433
31437
|
for (let i = 0; i < matches.length; i++) {
|
|
31434
31438
|
const current = matches[i];
|
|
31435
31439
|
let shouldInclude = true;
|
|
31436
|
-
for (const included of result) {
|
|
31440
|
+
if (!sorted || includedMaxEnd > current[0]) for (const included of result) {
|
|
31437
31441
|
if (rangesOverlap(current, included)) {
|
|
31438
31442
|
shouldInclude = false;
|
|
31439
31443
|
break;
|
|
@@ -31442,6 +31446,7 @@ var removeOverlaps = (matches, content, preferenceResolver = null) => {
|
|
|
31442
31446
|
if (shouldInclude) {
|
|
31443
31447
|
for (let j = i + 1; j < matches.length; j++) {
|
|
31444
31448
|
const next = matches[j];
|
|
31449
|
+
if (sorted && next[0] >= current[1]) break;
|
|
31445
31450
|
if (rangesOverlap(current, next)) {
|
|
31446
31451
|
if (preferenceResolver) {
|
|
31447
31452
|
const preferred = preferenceResolver(current, next, content);
|
|
@@ -31462,10 +31467,27 @@ var removeOverlaps = (matches, content, preferenceResolver = null) => {
|
|
|
31462
31467
|
}
|
|
31463
31468
|
if (shouldInclude) {
|
|
31464
31469
|
result.push(current);
|
|
31470
|
+
includedMaxEnd = Math.max(includedMaxEnd, current[1]);
|
|
31465
31471
|
}
|
|
31466
31472
|
}
|
|
31467
31473
|
return result;
|
|
31468
31474
|
};
|
|
31475
|
+
var spanCoverage = (spans) => {
|
|
31476
|
+
const sorted = [...spans || []].sort((a, b) => a[0] - b[0]);
|
|
31477
|
+
const maxEnd = [];
|
|
31478
|
+
for (let i = 0; i < sorted.length; i++) maxEnd.push(Math.max(sorted[i][1], i ? maxEnd[i - 1] : -Infinity));
|
|
31479
|
+
return (position) => {
|
|
31480
|
+
let lo = 0, hi = sorted.length - 1, last = -1;
|
|
31481
|
+
while (lo <= hi) {
|
|
31482
|
+
const mid = lo + hi >> 1;
|
|
31483
|
+
if (sorted[mid][0] <= position) {
|
|
31484
|
+
last = mid;
|
|
31485
|
+
lo = mid + 1;
|
|
31486
|
+
} else hi = mid - 1;
|
|
31487
|
+
}
|
|
31488
|
+
return last >= 0 && maxEnd[last] > position;
|
|
31489
|
+
};
|
|
31490
|
+
};
|
|
31469
31491
|
var calculateGaps = (matches) => {
|
|
31470
31492
|
return matches.reduce((prev, current, index) => {
|
|
31471
31493
|
if (index === 0) return prev;
|
|
@@ -31526,6 +31548,7 @@ var mergeAdjacentMatches = (matches, gapMergeFlags, compatibilityCheck = null) =
|
|
|
31526
31548
|
};
|
|
31527
31549
|
var gapCanMerge = (gapString, joiners) => {
|
|
31528
31550
|
if (!/\S/.test(gapString)) return true;
|
|
31551
|
+
if (/^\s*\./.test(gapString)) return false;
|
|
31529
31552
|
const list = Array.isArray(joiners) ? joiners : joiners && joiners.patterns || [];
|
|
31530
31553
|
let residue = gapString;
|
|
31531
31554
|
for (const joiner of list) {
|
|
@@ -31582,7 +31605,7 @@ var findMatches = (content, books, lang_extra) => {
|
|
|
31582
31605
|
normalizedContent = normalizedContent.replace(new RegExp(entity, "g"), unicode);
|
|
31583
31606
|
});
|
|
31584
31607
|
const tail = lang_extra.tail ? new RegExp(lang_extra.tail, "ig") : /[^0-9]+$/;
|
|
31585
|
-
const preBookMatch = lang_extra.book || `(First|
|
|
31608
|
+
const preBookMatch = lang_extra.book || `(?:(?:First|Second|Third|Fourth|1st|2nd|3rd|4th|III|II|IV|I|[1-4])\\s*)?(?:books? of\\s*)?`;
|
|
31586
31609
|
const matchingBooks = findMatchingBooks(normalizedContent, books);
|
|
31587
31610
|
const gap = "[ \\t]*(?:\\n(?![ \\t]*\\n)[ \\t]*)?(?:,[ \\t]*sec(?:tion)?\\.?[ \\t]*)?\\(?[ \\t]*(?=[0-9])";
|
|
31588
31611
|
const core = "(?:[0-9:.;,~\u2014\u2013-]|[ \\t]|\\n(?![ \\t]*\\n)|and\\b|cf\\b|\\()*[0-9]";
|
|
@@ -31596,13 +31619,11 @@ var findMatches = (content, books, lang_extra) => {
|
|
|
31596
31619
|
const stringMatch = pattern.test(normalizedContent) ? patternString : null;
|
|
31597
31620
|
return stringMatch;
|
|
31598
31621
|
}).filter((x) => !!x);
|
|
31599
|
-
const
|
|
31622
|
+
const allBookSubStrings = fullBookMatches.map((bookMatch) => {
|
|
31600
31623
|
const substrings = normalizedContent.match(new RegExp(bookMatch, "ig")).flat();
|
|
31601
31624
|
return substrings;
|
|
31602
|
-
}).flat()
|
|
31603
|
-
|
|
31604
|
-
return [...prev, current];
|
|
31605
|
-
}, []).filter((i) => !!i).filter((substring) => {
|
|
31625
|
+
}).flat();
|
|
31626
|
+
const bookSubStrings = [...new Set(allBookSubStrings)].filter((i) => !!i).filter((substring) => {
|
|
31606
31627
|
const token = substring.trim();
|
|
31607
31628
|
if (!capitalizedOnlyAbbreviations.has(token.toLowerCase())) return true;
|
|
31608
31629
|
return token !== token.toLowerCase();
|
|
@@ -31626,15 +31647,16 @@ var findMatches = (content, books, lang_extra) => {
|
|
|
31626
31647
|
return [substring, positions];
|
|
31627
31648
|
}).filter((i) => !!i);
|
|
31628
31649
|
const possiblyOverlappingMatches = bookSubStrings.map(([substring, positions]) => {
|
|
31650
|
+
let pattern = null;
|
|
31651
|
+
try {
|
|
31652
|
+
pattern = new RegExp(substring + postBookMatch, "iy");
|
|
31653
|
+
} catch (e) {
|
|
31654
|
+
return [];
|
|
31655
|
+
}
|
|
31629
31656
|
return positions.map(
|
|
31630
31657
|
(i) => {
|
|
31631
|
-
|
|
31632
|
-
|
|
31633
|
-
pattern = new RegExp(substring + postBookMatch, "ig");
|
|
31634
|
-
} catch (e) {
|
|
31635
|
-
return null;
|
|
31636
|
-
}
|
|
31637
|
-
const match = normalizedContent.slice(i).match(pattern)?.[0]?.replace(tail, "").trim();
|
|
31658
|
+
pattern.lastIndex = i;
|
|
31659
|
+
const match = pattern.exec(normalizedContent)?.[0]?.replace(tail, "").trim();
|
|
31638
31660
|
if (!match) return null;
|
|
31639
31661
|
const len = match.length;
|
|
31640
31662
|
const pos = i;
|
|
@@ -31644,22 +31666,35 @@ var findMatches = (content, books, lang_extra) => {
|
|
|
31644
31666
|
}
|
|
31645
31667
|
);
|
|
31646
31668
|
}).flat().filter((i) => !!i);
|
|
31669
|
+
const byStart = [...possiblyOverlappingMatches].sort((a, b) => a[1] - b[1]);
|
|
31670
|
+
const maxEndUpTo = [];
|
|
31671
|
+
byStart.forEach(([, , e1], i) => maxEndUpTo.push(Math.max(e1, i ? maxEndUpTo[i - 1] : -Infinity)));
|
|
31672
|
+
const cutPoint = (string, end) => {
|
|
31673
|
+
let lo = 0, hi = byStart.length - 1, first = byStart.length;
|
|
31674
|
+
while (lo <= hi) {
|
|
31675
|
+
const mid = lo + hi >> 1;
|
|
31676
|
+
if (maxEndUpTo[mid] > end) {
|
|
31677
|
+
first = mid;
|
|
31678
|
+
hi = mid - 1;
|
|
31679
|
+
} else lo = mid + 1;
|
|
31680
|
+
}
|
|
31681
|
+
for (let k = first; k < byStart.length && byStart[k][1] < end; k++) {
|
|
31682
|
+
const [s, s1, e1] = byStart[k];
|
|
31683
|
+
if (s !== string && e1 > end) return s1;
|
|
31684
|
+
}
|
|
31685
|
+
return end;
|
|
31686
|
+
};
|
|
31647
31687
|
const matchesWithReferences = possiblyOverlappingMatches.map(([string, start, end]) => {
|
|
31648
|
-
const
|
|
31649
|
-
const hasOverlap = overLappingItems.length > 0;
|
|
31650
|
-
const newEnd = hasOverlap ? Math.min(...overLappingItems.map(([s, s1, e1]) => s1)) : end;
|
|
31688
|
+
const newEnd = cutPoint(string, end);
|
|
31651
31689
|
const newString = normalizedContent.slice(start, newEnd);
|
|
31652
31690
|
return newString.replace(tail, "").trim();
|
|
31653
31691
|
}).filter((i) => !!i);
|
|
31654
|
-
const matches = matchesWithReferences.map((string) => {
|
|
31692
|
+
const matches = [...new Set(matchesWithReferences)].map((string) => {
|
|
31655
31693
|
const pattern = new RegExp(string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "ig");
|
|
31656
31694
|
const matches2 = normalizedContent.match(pattern)?.map((i) => i.trim().replace(tail, ""));
|
|
31657
31695
|
return matches2;
|
|
31658
|
-
}).flat()
|
|
31659
|
-
|
|
31660
|
-
return [...prev, current];
|
|
31661
|
-
}, []).filter((i) => !!i);
|
|
31662
|
-
return matches;
|
|
31696
|
+
}).flat();
|
|
31697
|
+
return [...new Set(matches)].filter((i) => !!i);
|
|
31663
31698
|
};
|
|
31664
31699
|
function findMatchIndexes(content, matches, lookupReference2, lang_extra) {
|
|
31665
31700
|
const tail = lang_extra.tail ? new RegExp(lang_extra.tail, "ig") : /[^0-9]+$/;
|
|
@@ -31730,7 +31765,7 @@ var processReferenceDetection = (content, books, lang_extra, lookupReference2, c
|
|
|
31730
31765
|
var collectReferencesWithContext = (content, books, lang_extra, lookupReference2, options) => {
|
|
31731
31766
|
const explicitMatches = findMatches(content, books, lang_extra);
|
|
31732
31767
|
const explicitIndices = findMatchIndexes(content, explicitMatches, lookupReference2, lang_extra) || [];
|
|
31733
|
-
const impliedMatches = findImpliedReferences(content, explicitMatches, explicitIndices, lookupReference2, options);
|
|
31768
|
+
const impliedMatches = findImpliedReferences(content, explicitMatches, explicitIndices, lookupReference2, options, lang_extra);
|
|
31734
31769
|
const explicitMatchesWithRefs = explicitIndices.map(([start, end]) => {
|
|
31735
31770
|
const originalText = content.substring(start, end);
|
|
31736
31771
|
const verification = lookupReference2(originalText);
|
|
@@ -31821,7 +31856,21 @@ var getNearestBookContext = (position, bookContexts, maxDistance) => {
|
|
|
31821
31856
|
}
|
|
31822
31857
|
return bestContext;
|
|
31823
31858
|
};
|
|
31824
|
-
var
|
|
31859
|
+
var CITATION_CONNECTIVES = ["including", "namely", "e.g", "i.e"];
|
|
31860
|
+
var bindsToBookContext = (tail, joiners) => {
|
|
31861
|
+
const trimmed = tail.replace(/\s+$/, "");
|
|
31862
|
+
if (!trimmed) return true;
|
|
31863
|
+
if (/[;&([]$/.test(trimmed)) return true;
|
|
31864
|
+
const list = Array.isArray(joiners) ? joiners : joiners && joiners.patterns || [];
|
|
31865
|
+
const words = /* @__PURE__ */ new Set([
|
|
31866
|
+
...list.filter((j) => typeof j === "string" && /[a-z]/i.test(j)).map((j) => j.toLowerCase().replace(/\.+$/, "").split(/\s+/).pop()),
|
|
31867
|
+
...CITATION_CONNECTIVES
|
|
31868
|
+
]);
|
|
31869
|
+
const lastWord = (trimmed.match(/[A-Za-z.']+$/) || [""])[0].toLowerCase().replace(/[.']+$/, "");
|
|
31870
|
+
return lastWord !== "" && words.has(lastWord);
|
|
31871
|
+
};
|
|
31872
|
+
var findImpliedReferences = (content, explicitMatches, explicitIndices, lookupReference2, options, lang_extra = {}) => {
|
|
31873
|
+
const joiners = lang_extra && (lang_extra.unrestrictedJoiners || lang_extra.joiners) || ["and", ";", ",", "&", "compare", "see also", "see", "cf", "c.f.", "cited at", "also"];
|
|
31825
31874
|
const matches = [];
|
|
31826
31875
|
const bookContexts = findBookContexts(content, explicitMatches, explicitIndices, lookupReference2);
|
|
31827
31876
|
const verseGroupPattern = /\b(?:vv?\.?\s*|vs\.?\s*|verses?\s+)([\d:,\s–—-]+?)(?=\s*[).;\n]|$)/gi;
|
|
@@ -31840,19 +31889,21 @@ var findImpliedReferences = (content, explicitMatches, explicitIndices, lookupRe
|
|
|
31840
31889
|
}
|
|
31841
31890
|
}
|
|
31842
31891
|
const chapterVersePattern = /\b(\d+):(\d+(?:[–—-]\d+)?(?:\s*,\s*\d+(?:[–—-]\d+)?)*)/g;
|
|
31892
|
+
const insideExplicit = spanCoverage(explicitIndices || []);
|
|
31843
31893
|
while ((match = chapterVersePattern.exec(content)) !== null) {
|
|
31844
31894
|
const fullMatch = match[0];
|
|
31845
31895
|
const chapter = match[1];
|
|
31846
31896
|
const verses = match[2];
|
|
31847
31897
|
const position = match.index;
|
|
31848
|
-
const isPartOfExplicit =
|
|
31849
|
-
([start, end]) => position >= start && position < end
|
|
31850
|
-
);
|
|
31898
|
+
const isPartOfExplicit = insideExplicit(position);
|
|
31851
31899
|
if (isPartOfExplicit) {
|
|
31852
31900
|
continue;
|
|
31853
31901
|
}
|
|
31902
|
+
if (/^\s*(?:[ap]\.?\s?m\b\.?|o['’]?clock\b)/i.test(content.slice(position + fullMatch.length))) {
|
|
31903
|
+
continue;
|
|
31904
|
+
}
|
|
31854
31905
|
const context = getNearestBookContext(position, bookContexts, options.maxContextDistance);
|
|
31855
|
-
if (context) {
|
|
31906
|
+
if (context && (options.strictImpliedBooks === false || bindsToBookContext(content.slice(context.endPosition, position), joiners))) {
|
|
31856
31907
|
const impliedRef = `${context.book} ${chapter}:${verses}`;
|
|
31857
31908
|
const verification = lookupReference2(impliedRef);
|
|
31858
31909
|
if (verification.verse_ids && verification.verse_ids.length > 0) {
|
|
@@ -31949,6 +32000,11 @@ var convertCanon = (verseIds, options = {}) => {
|
|
|
31949
32000
|
return result;
|
|
31950
32001
|
};
|
|
31951
32002
|
|
|
32003
|
+
// src/slug.mjs
|
|
32004
|
+
function toSlug(ref) {
|
|
32005
|
+
return ref.trim().toLowerCase().replace(/[־᠆‐‒–—―﹣-‑]+/gu, "-").replace(/[\s:]+/g, ".").replace(/\.+/g, ".").replace(/;\./g, ";").replace(/,\./g, ",").replace(/\.;/g, ";").replace(/\.,/g, ",");
|
|
32006
|
+
}
|
|
32007
|
+
|
|
31952
32008
|
// src/config.mjs
|
|
31953
32009
|
var MAX_RANGE_SIZE = 1e3;
|
|
31954
32010
|
var MAX_CHAPTER = 200;
|
|
@@ -31982,11 +32038,20 @@ for (const [canonKey, canonData] of Object.entries(extraCanons)) {
|
|
|
31982
32038
|
});
|
|
31983
32039
|
}
|
|
31984
32040
|
}
|
|
31985
|
-
var
|
|
31986
|
-
|
|
31987
|
-
|
|
31988
|
-
|
|
31989
|
-
|
|
32041
|
+
var INDEX_CACHE_LIMIT = 4;
|
|
32042
|
+
var refIndexCache = /* @__PURE__ */ new Map();
|
|
32043
|
+
var verseIdIndexCache = /* @__PURE__ */ new Map();
|
|
32044
|
+
var cachedIndex = (cache, key, build) => {
|
|
32045
|
+
if (cache.has(key)) {
|
|
32046
|
+
const value2 = cache.get(key);
|
|
32047
|
+
cache.delete(key);
|
|
32048
|
+
cache.set(key, value2);
|
|
32049
|
+
return value2;
|
|
32050
|
+
}
|
|
32051
|
+
const value = build();
|
|
32052
|
+
cache.set(key, value);
|
|
32053
|
+
if (cache.size > INDEX_CACHE_LIMIT) cache.delete(cache.keys().next().value);
|
|
32054
|
+
return value;
|
|
31990
32055
|
};
|
|
31991
32056
|
var hashConfig = (config) => {
|
|
31992
32057
|
return (config?.language || "en") + ":" + (config?.canon || DEFAULTS.canon);
|
|
@@ -32063,7 +32128,8 @@ var lookupReference = function(query, optionsOrLanguage = {}, legacyConfig = nul
|
|
|
32063
32128
|
const effectiveLanguage = getEffectiveLanguage(language);
|
|
32064
32129
|
const { convertTo, includeParallel } = lookupConfig;
|
|
32065
32130
|
const canon = lookupConfig.canon || getEffectiveCanon();
|
|
32066
|
-
const
|
|
32131
|
+
const limit = rangeLimit(lookupConfig.maxVerses);
|
|
32132
|
+
const lookupResult = lookupInLanguage(query, effectiveLanguage, canon, limit);
|
|
32067
32133
|
const verse_ids = lookupResult.verse_ids;
|
|
32068
32134
|
const errors = lookupResult.errors;
|
|
32069
32135
|
if (verse_ids?.length) {
|
|
@@ -32092,7 +32158,7 @@ var lookupReference = function(query, optionsOrLanguage = {}, legacyConfig = nul
|
|
|
32092
32158
|
return result;
|
|
32093
32159
|
}
|
|
32094
32160
|
if (!lookupConfig.noMulti) {
|
|
32095
|
-
const fallbackResult = lookupWithLanguageFallback(query, effectiveLanguage, canon);
|
|
32161
|
+
const fallbackResult = lookupWithLanguageFallback(query, effectiveLanguage, canon, limit);
|
|
32096
32162
|
if (fallbackResult.verse_ids.length === 0 && errors) {
|
|
32097
32163
|
fallbackResult.error = errors.join("; ");
|
|
32098
32164
|
}
|
|
@@ -32105,14 +32171,17 @@ var lookupReference = function(query, optionsOrLanguage = {}, legacyConfig = nul
|
|
|
32105
32171
|
error: errors ? errors.join("; ") : void 0
|
|
32106
32172
|
};
|
|
32107
32173
|
};
|
|
32108
|
-
var
|
|
32174
|
+
var rangeLimit = function(maxVerses) {
|
|
32175
|
+
return Number.isInteger(maxVerses) && maxVerses > 0 ? maxVerses : MAX_RANGE_SIZE;
|
|
32176
|
+
};
|
|
32177
|
+
var lookupInLanguage = function(query, language, canon = null, limit = MAX_RANGE_SIZE) {
|
|
32109
32178
|
const config = getLanguageConfig(language, canon);
|
|
32110
32179
|
let ref = cleanReference(query, config);
|
|
32111
32180
|
let refs = splitReferences(ref, config);
|
|
32112
32181
|
let verse_ids = [];
|
|
32113
32182
|
let errors = [];
|
|
32114
32183
|
for (let i in refs) {
|
|
32115
|
-
const result = lookupSingleRef(refs[i], config);
|
|
32184
|
+
const result = lookupSingleRef(refs[i], config, limit);
|
|
32116
32185
|
if (result && result.error) {
|
|
32117
32186
|
errors.push(result.error);
|
|
32118
32187
|
} else if (Array.isArray(result)) {
|
|
@@ -32126,10 +32195,17 @@ var lookupInLanguage = function(query, language, canon = null) {
|
|
|
32126
32195
|
errors: errors.length > 0 ? errors : void 0
|
|
32127
32196
|
};
|
|
32128
32197
|
};
|
|
32129
|
-
var
|
|
32198
|
+
var detectionLookup = function(language) {
|
|
32199
|
+
const seen = /* @__PURE__ */ new Map();
|
|
32200
|
+
return (query) => {
|
|
32201
|
+
if (!seen.has(query)) seen.set(query, lookupReference(query, { language, noMulti: true }));
|
|
32202
|
+
return seen.get(query);
|
|
32203
|
+
};
|
|
32204
|
+
};
|
|
32205
|
+
var lookupWithLanguageFallback = function(query, targetLanguage, canon = null, limit = MAX_RANGE_SIZE) {
|
|
32130
32206
|
const fallbackLanguages = targetLanguage !== "en" ? ["en", ...Object.keys(raw_lang).filter((lang) => lang !== "en" && lang !== targetLanguage)] : Object.keys(raw_lang).filter((lang) => lang !== targetLanguage);
|
|
32131
32207
|
for (const lang of fallbackLanguages) {
|
|
32132
|
-
const lookupResult = lookupInLanguage(query, lang, canon);
|
|
32208
|
+
const lookupResult = lookupInLanguage(query, lang, canon, limit);
|
|
32133
32209
|
const verse_ids = lookupResult.verse_ids;
|
|
32134
32210
|
if (verse_ids?.length) {
|
|
32135
32211
|
const refInTargetLanguage = generateReference(verse_ids, { language: targetLanguage, canon });
|
|
@@ -32146,9 +32222,9 @@ var lookupWithLanguageFallback = function(query, targetLanguage, canon = null) {
|
|
|
32146
32222
|
"verse_ids": []
|
|
32147
32223
|
};
|
|
32148
32224
|
};
|
|
32149
|
-
var lookupSingleRef = function(ref, config) {
|
|
32225
|
+
var lookupSingleRef = function(ref, config, limit = MAX_RANGE_SIZE) {
|
|
32150
32226
|
const booksWithDashRegex = /^(joseph|조셉)/i;
|
|
32151
|
-
if (!booksWithDashRegex.test(ref) && ref.match(/[—-](\d\s)*[\D]/ig)) return lookupMultiBookRange(ref, config);
|
|
32227
|
+
if (!booksWithDashRegex.test(ref) && ref.match(/[—-](\d\s)*[\D]/ig)) return lookupMultiBookRange(ref, config, limit);
|
|
32152
32228
|
let book = getBook(ref, config);
|
|
32153
32229
|
if (!book) {
|
|
32154
32230
|
return {
|
|
@@ -32157,7 +32233,7 @@ var lookupSingleRef = function(ref, config) {
|
|
|
32157
32233
|
};
|
|
32158
32234
|
}
|
|
32159
32235
|
let ranges = getRanges(ref, book);
|
|
32160
|
-
let verse_ids = loadVerseIds(book, ranges, config);
|
|
32236
|
+
let verse_ids = loadVerseIds(book, ranges, config, limit);
|
|
32161
32237
|
return verse_ids;
|
|
32162
32238
|
};
|
|
32163
32239
|
var validateVerseIdsMixed = function(verse_ids) {
|
|
@@ -32193,7 +32269,7 @@ var generateReference = function(verse_ids, optionsOrLanguage = {}, legacyOption
|
|
|
32193
32269
|
let ref = refs.join("; ");
|
|
32194
32270
|
return ref;
|
|
32195
32271
|
};
|
|
32196
|
-
var lookupMultiBookRange = function(cleanRef, config) {
|
|
32272
|
+
var lookupMultiBookRange = function(cleanRef, config, limit = MAX_RANGE_SIZE) {
|
|
32197
32273
|
let range = cleanRef.split(/[—-]/);
|
|
32198
32274
|
if (!range[0].match(/[:]/)) {
|
|
32199
32275
|
if (range[0].match(/\d+\s*$/)) range[0] = range[0].trim() + ":1";
|
|
@@ -32214,7 +32290,7 @@ var lookupMultiBookRange = function(cleanRef, config) {
|
|
|
32214
32290
|
let end = lookupSingleRef(range[1], config)[0];
|
|
32215
32291
|
let all_verse_ids = [];
|
|
32216
32292
|
for (let i = start; i <= end; i++) {
|
|
32217
|
-
if (all_verse_ids.length >=
|
|
32293
|
+
if (all_verse_ids.length >= limit) break;
|
|
32218
32294
|
all_verse_ids.push(i);
|
|
32219
32295
|
}
|
|
32220
32296
|
return all_verse_ids;
|
|
@@ -32227,41 +32303,44 @@ var strToHash = function(str) {
|
|
|
32227
32303
|
}
|
|
32228
32304
|
return `==${hash}==`;
|
|
32229
32305
|
};
|
|
32306
|
+
var cleanRulesCache = /* @__PURE__ */ new WeakMap();
|
|
32307
|
+
var cleanRules = function(config) {
|
|
32308
|
+
let rules = cleanRulesCache.get(config);
|
|
32309
|
+
if (rules) return rules;
|
|
32310
|
+
const pre = (config.raw_regex.pre_rules || []).map((rule) => [new RegExp(rule.pattern ?? rule[0], "ig"), rule.replacement ?? rule[1] ?? ""]);
|
|
32311
|
+
const [wordBreak, buffer] = config.raw_regex.spacing || ["\\b", ""];
|
|
32312
|
+
let srcbooks = config.raw_regex.books;
|
|
32313
|
+
let dstbooks = buffer ? config.raw_regex.books.map((i) => [i[1], i[1]]) : [];
|
|
32314
|
+
let bookMatchList = [...dstbooks, ...srcbooks].sort((a, b) => b[0].length - a[0].length);
|
|
32315
|
+
let hashCypher = {};
|
|
32316
|
+
for (const [, book] of bookMatchList) hashCypher[book] = strToHash(book);
|
|
32317
|
+
const bookRules = bookMatchList.map(([pattern, book]) => [new RegExp(wordBreak + buffer + pattern + buffer + "\\.*" + wordBreak, "ig"), hashCypher[book] || book]);
|
|
32318
|
+
const hashes = Object.values(hashCypher);
|
|
32319
|
+
rules = { pre, buffer, books: Object.keys(hashCypher), hashes, bookRules, hashRe: new RegExp(hashes.join("|"), "g") };
|
|
32320
|
+
cleanRulesCache.set(config, rules);
|
|
32321
|
+
return rules;
|
|
32322
|
+
};
|
|
32230
32323
|
var cleanReference = function(messyReference, config) {
|
|
32231
32324
|
let ref = messyReference.replace(/[\s]+/g, " ").trim();
|
|
32232
32325
|
ref = ref.replace(/(\d)\s+and\s+(\d)/g, "$1,$2");
|
|
32233
32326
|
ref = ref.replace(/[()]/g, " ");
|
|
32234
32327
|
ref = ref.replace(/\bsec(?:tion)?\b\.?/ig, " ");
|
|
32235
|
-
|
|
32236
|
-
|
|
32237
|
-
|
|
32238
|
-
|
|
32239
|
-
}
|
|
32328
|
+
ref = ref.replace(/(\d)[.](?=(?:\d[.\s]*)?\p{L})/gu, "$1 ");
|
|
32329
|
+
ref = ref.replace(/(\d)\s+(?=\d[\s.]*\p{L}[\p{L}\s.&'-]{0,40}?[\s.]\d)/gu, "$1; ");
|
|
32330
|
+
const rules = cleanRules(config);
|
|
32331
|
+
for (const [re, replacement] of rules.pre) ref = ref.replace(re, replacement);
|
|
32240
32332
|
ref = ref.replace(/(\d+)[.](\d+)/g, "$1:$2");
|
|
32241
32333
|
ref = ref.replace(/[.]/g, "");
|
|
32242
32334
|
ref = ref.replace(/;/g, "; ");
|
|
32243
32335
|
ref = ref.replace(/^([0-9;,:-]+)(\d+)/g, "$1 $2");
|
|
32244
32336
|
ref = ref.replace(/([–-])(\D+)/g, " $1 $2 ");
|
|
32245
|
-
const
|
|
32246
|
-
|
|
32247
|
-
let dstbooks = buffer ? config.raw_regex.books.map((i) => [i[1], i[1]]) : [];
|
|
32248
|
-
let bookMatchList = [...dstbooks, ...srcbooks].sort((a, b) => b[0].length - a[0].length);
|
|
32249
|
-
regex = bookMatchList;
|
|
32250
|
-
let hashCypher = {};
|
|
32251
|
-
for (let i in regex) {
|
|
32252
|
-
const [, book] = regex[i];
|
|
32253
|
-
const hash = strToHash(book);
|
|
32254
|
-
hashCypher[book] = hash;
|
|
32255
|
-
}
|
|
32256
|
-
for (let i in regex) {
|
|
32257
|
-
var re = new RegExp(wordBreak + buffer + regex[i][0] + buffer + "\\.*" + wordBreak, "ig");
|
|
32258
|
-
let replacement = hashCypher[regex[i][1]] || regex[i][1];
|
|
32337
|
+
const { buffer, books, hashes } = rules;
|
|
32338
|
+
for (const [re, replacement] of rules.bookRules) {
|
|
32259
32339
|
ref = (buffer + ref + buffer).replace(re, replacement).trim();
|
|
32260
32340
|
}
|
|
32261
|
-
|
|
32262
|
-
const hashes = Object.values(hashCypher);
|
|
32341
|
+
ref = ref.replace(/(\d)\s*(==\d+==)(?=\s*\d)/g, "$1; $2");
|
|
32263
32342
|
ref = ref.replace(
|
|
32264
|
-
|
|
32343
|
+
rules.hashRe,
|
|
32265
32344
|
function(match) {
|
|
32266
32345
|
const bookValue = books[hashes.indexOf(match)];
|
|
32267
32346
|
return bookValue + " ";
|
|
@@ -32289,6 +32368,11 @@ var splitReferences = function(compoundReference, config) {
|
|
|
32289
32368
|
let completeRefs = [];
|
|
32290
32369
|
for (let i in refs) {
|
|
32291
32370
|
const ref = refs[i];
|
|
32371
|
+
const multiBook = ref.match(/^(.*?\D)\s*\d[\d:,]*\s*[—-]\s*((?:\d\s*)?\D+?)\s*\d[\d:,]*$/);
|
|
32372
|
+
if (multiBook && bookExists(multiBook[1].trim(), config) && bookExists(multiBook[2].trim(), config)) {
|
|
32373
|
+
completeRefs.push(ref.trim());
|
|
32374
|
+
continue;
|
|
32375
|
+
}
|
|
32292
32376
|
let pieces = ref.split(/([0-9:,-]+)$/);
|
|
32293
32377
|
const firstPiece = pieces[0].trim();
|
|
32294
32378
|
runningBook = bookExists(firstPiece, config) ? firstPiece : runningBook;
|
|
@@ -32391,11 +32475,11 @@ var getRanges = function(ref) {
|
|
|
32391
32475
|
;
|
|
32392
32476
|
return ranges;
|
|
32393
32477
|
};
|
|
32394
|
-
var loadVerseIds = function(book, ranges, config) {
|
|
32478
|
+
var loadVerseIds = function(book, ranges, config, limit = MAX_RANGE_SIZE) {
|
|
32395
32479
|
let refIndex = loadRefIndex(config);
|
|
32396
32480
|
let verseList = [];
|
|
32397
32481
|
for (let i in ranges) {
|
|
32398
|
-
if (verseList.length >=
|
|
32482
|
+
if (verseList.length >= limit) break;
|
|
32399
32483
|
let range = ranges[i];
|
|
32400
32484
|
let matches = range.match(/(\d+): *([\dX]+)-*([\dX]*)/);
|
|
32401
32485
|
if (!matches) continue;
|
|
@@ -32409,7 +32493,7 @@ var loadVerseIds = function(book, ranges, config) {
|
|
|
32409
32493
|
start = Math.max(1, Math.min(start, MAX_VERSE));
|
|
32410
32494
|
end = Math.max(start, Math.min(end, MAX_VERSE));
|
|
32411
32495
|
for (let verse_num = start; verse_num <= end; verse_num++) {
|
|
32412
|
-
if (verseList.length >=
|
|
32496
|
+
if (verseList.length >= limit) break;
|
|
32413
32497
|
if (refIndex[book]?.[chapter]?.[verse_num]) {
|
|
32414
32498
|
verseList.push(refIndex[book][chapter][verse_num]);
|
|
32415
32499
|
}
|
|
@@ -32499,10 +32583,9 @@ var loadRefsFromRanges = function(ranges, config) {
|
|
|
32499
32583
|
return refs;
|
|
32500
32584
|
};
|
|
32501
32585
|
var loadRefIndex = function(config) {
|
|
32502
|
-
|
|
32503
|
-
|
|
32504
|
-
|
|
32505
|
-
}
|
|
32586
|
+
return cachedIndex(refIndexCache, hashConfig(config), () => buildRefIndex(config));
|
|
32587
|
+
};
|
|
32588
|
+
var buildRefIndex = function(config) {
|
|
32506
32589
|
let refIndex = {};
|
|
32507
32590
|
let verse_id = 1;
|
|
32508
32591
|
let book_list = Object.keys(config.raw_index);
|
|
@@ -32519,15 +32602,12 @@ var loadRefIndex = function(config) {
|
|
|
32519
32602
|
}
|
|
32520
32603
|
}
|
|
32521
32604
|
}
|
|
32522
|
-
indexCache.refIndex = refIndex;
|
|
32523
|
-
indexCache.refIndexHash = configHash;
|
|
32524
32605
|
return refIndex;
|
|
32525
32606
|
};
|
|
32526
32607
|
var loadVerseIdIndex = function(config) {
|
|
32527
|
-
|
|
32528
|
-
|
|
32529
|
-
|
|
32530
|
-
}
|
|
32608
|
+
return cachedIndex(verseIdIndexCache, hashConfig(config), () => buildVerseIdIndex(config));
|
|
32609
|
+
};
|
|
32610
|
+
var buildVerseIdIndex = function(config) {
|
|
32531
32611
|
let verseIdIndex = [null];
|
|
32532
32612
|
let book_list = Object.keys(config.raw_index);
|
|
32533
32613
|
for (let a in book_list) {
|
|
@@ -32540,8 +32620,6 @@ var loadVerseIdIndex = function(config) {
|
|
|
32540
32620
|
}
|
|
32541
32621
|
}
|
|
32542
32622
|
}
|
|
32543
|
-
indexCache.verseIdIndex = verseIdIndex;
|
|
32544
|
-
indexCache.verseIdIndexHash = configHash;
|
|
32545
32623
|
return verseIdIndex;
|
|
32546
32624
|
};
|
|
32547
32625
|
var bookExists = function(book, config) {
|
|
@@ -32571,7 +32649,7 @@ var restrictJoinersToStructural = (lang_extra) => {
|
|
|
32571
32649
|
} else {
|
|
32572
32650
|
joiners = [...STRUCTURAL_JOINERS];
|
|
32573
32651
|
}
|
|
32574
|
-
return { ...src, joiners };
|
|
32652
|
+
return { ...src, joiners, unrestrictedJoiners: src.joiners };
|
|
32575
32653
|
};
|
|
32576
32654
|
var detectReferences = (content, callBack, options = null) => {
|
|
32577
32655
|
if (typeof options === "string" || options === null) {
|
|
@@ -32585,7 +32663,10 @@ var detectReferences = (content, callBack, options = null) => {
|
|
|
32585
32663
|
maxContextDistance: 500,
|
|
32586
32664
|
enableImpliedBooks: true,
|
|
32587
32665
|
enableVerseAbbrev: true,
|
|
32588
|
-
chainAcrossMarkers: true
|
|
32666
|
+
chainAcrossMarkers: true,
|
|
32667
|
+
// A bare "6:3" binds to an earlier book only when the token before it is
|
|
32668
|
+
// citation material. false restores pre-1.0.98 distance-only binding.
|
|
32669
|
+
strictImpliedBooks: true
|
|
32589
32670
|
};
|
|
32590
32671
|
const finalOptions = { ...defaultOptions, ...options };
|
|
32591
32672
|
callBack = callBack ? callBack : (i) => {
|
|
@@ -32598,9 +32679,9 @@ var detectReferences = (content, callBack, options = null) => {
|
|
|
32598
32679
|
const books = [...dst, ...src];
|
|
32599
32680
|
const langExtra = finalOptions.chainAcrossMarkers === false ? restrictJoinersToStructural(config.lang_extra) : config.lang_extra;
|
|
32600
32681
|
if (finalOptions.contextAware) {
|
|
32601
|
-
return detectReferencesWithContext(content, books, langExtra, (
|
|
32682
|
+
return detectReferencesWithContext(content, books, langExtra, detectionLookup(effectiveLanguage), callBack, finalOptions, generateReference);
|
|
32602
32683
|
}
|
|
32603
|
-
return processReferenceDetection(content, books, langExtra, (
|
|
32684
|
+
return processReferenceDetection(content, books, langExtra, detectionLookup(effectiveLanguage), callBack);
|
|
32604
32685
|
};
|
|
32605
32686
|
var findReferences = (content, options = null) => {
|
|
32606
32687
|
if (typeof options === "string" || options === null) {
|
|
@@ -32615,7 +32696,10 @@ var findReferences = (content, options = null) => {
|
|
|
32615
32696
|
enableVerseAbbrev: true,
|
|
32616
32697
|
abbreviations: true,
|
|
32617
32698
|
chapterOnly: true,
|
|
32618
|
-
chainAcrossMarkers: true
|
|
32699
|
+
chainAcrossMarkers: true,
|
|
32700
|
+
// A bare "6:3" binds to an earlier book only when the token before it is
|
|
32701
|
+
// citation material. false restores pre-1.0.98 distance-only binding.
|
|
32702
|
+
strictImpliedBooks: true
|
|
32619
32703
|
};
|
|
32620
32704
|
const finalOptions = { ...defaultOptions, ...options };
|
|
32621
32705
|
const effectiveLanguage = getEffectiveLanguage(finalOptions.language);
|
|
@@ -32623,7 +32707,7 @@ var findReferences = (content, options = null) => {
|
|
|
32623
32707
|
const src = config.raw_regex.books.map((i) => i[0]);
|
|
32624
32708
|
const dst = [...new Set(config.raw_regex.books.map((i) => i[1]))];
|
|
32625
32709
|
const books = [...dst, ...src];
|
|
32626
|
-
const lookup = (
|
|
32710
|
+
const lookup = detectionLookup(effectiveLanguage);
|
|
32627
32711
|
const langExtra = finalOptions.chainAcrossMarkers === false ? restrictJoinersToStructural(config.lang_extra) : config.lang_extra;
|
|
32628
32712
|
const found = finalOptions.contextAware ? collectReferencesWithContext(content, books, langExtra, lookup, finalOptions) : collectReferences(content, books, langExtra, lookup);
|
|
32629
32713
|
let records = found.filter((m) => m.verse_ids.length > 0).map(({ start, end, text, verse_ids }) => ({
|
|
@@ -32714,9 +32798,15 @@ var applyDetectionFlags = (records, opts) => {
|
|
|
32714
32798
|
}
|
|
32715
32799
|
return out;
|
|
32716
32800
|
};
|
|
32801
|
+
var languageConfigCache = /* @__PURE__ */ new Map();
|
|
32717
32802
|
var getLanguageConfig = function(language, canon = null) {
|
|
32718
32803
|
const effectiveLanguage = language && raw_lang[language] ? language : "en";
|
|
32719
32804
|
const effectiveCanon = canon && extraCanons[canon] ? canon : DEFAULTS.canon;
|
|
32805
|
+
const key = `${effectiveLanguage}|${effectiveCanon}`;
|
|
32806
|
+
if (!languageConfigCache.has(key)) languageConfigCache.set(key, buildLanguageConfig(effectiveLanguage, effectiveCanon));
|
|
32807
|
+
return languageConfigCache.get(key);
|
|
32808
|
+
};
|
|
32809
|
+
var buildLanguageConfig = function(effectiveLanguage, effectiveCanon) {
|
|
32720
32810
|
const config = {
|
|
32721
32811
|
language: effectiveLanguage,
|
|
32722
32812
|
canon: effectiveCanon,
|
|
@@ -32788,6 +32878,7 @@ export {
|
|
|
32788
32878
|
setCanon,
|
|
32789
32879
|
setLanguage as setLang,
|
|
32790
32880
|
setLanguage,
|
|
32881
|
+
toSlug,
|
|
32791
32882
|
generateReference as verseId2Ref
|
|
32792
32883
|
};
|
|
32793
32884
|
//# sourceMappingURL=scriptures.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scripture-guide",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
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",
|
|
@@ -14,24 +14,24 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
|
-
"
|
|
18
|
-
"test": "node test/test.mjs",
|
|
17
|
+
"test": "npm run test:jest",
|
|
19
18
|
"build": "node build/build.mjs",
|
|
20
19
|
"embed": "node build/build.mjs",
|
|
21
20
|
"generate-coc-mapping": "node build/generate-coc-mapping.cjs",
|
|
22
|
-
"prepublishOnly": "npm
|
|
23
|
-
"test:jest": "
|
|
24
|
-
"test:critical": "
|
|
25
|
-
"test:edge": "
|
|
26
|
-
"test:known-issues": "
|
|
27
|
-
"test:coverage": "
|
|
21
|
+
"prepublishOnly": "npm run build",
|
|
22
|
+
"test:jest": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
23
|
+
"test:critical": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPatterns='critical\\.test\\.js$'",
|
|
24
|
+
"test:edge": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPatterns='edge-cases\\.test\\.js$'",
|
|
25
|
+
"test:known-issues": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPatterns='known-issues\\.test\\.js$'",
|
|
26
|
+
"test:coverage": "NODE_OPTIONS=--experimental-vm-modules jest --coverage"
|
|
28
27
|
},
|
|
29
28
|
"author": "",
|
|
30
29
|
"license": "ISC",
|
|
31
30
|
"homepage": "https://scripture.guide",
|
|
32
31
|
"repository": {
|
|
33
32
|
"type": "git",
|
|
34
|
-
"url": "git://github.com/kckern/
|
|
33
|
+
"url": "git+https://github.com/kckern/ScriptureGuide.git",
|
|
34
|
+
"directory": "packages/scripture-guide"
|
|
35
35
|
},
|
|
36
36
|
"keywords": [
|
|
37
37
|
"bible",
|
|
@@ -50,18 +50,19 @@
|
|
|
50
50
|
"pearl of great price"
|
|
51
51
|
],
|
|
52
52
|
"files": [
|
|
53
|
-
"scriptures.mjs",
|
|
54
|
-
"scriptures.cjs",
|
|
55
|
-
"scriptures.d.ts"
|
|
53
|
+
"dist/scriptures.mjs",
|
|
54
|
+
"dist/scriptures.cjs",
|
|
55
|
+
"dist/scriptures.d.ts"
|
|
56
56
|
],
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"
|
|
58
|
+
"dotenv": "^17.2.3",
|
|
59
|
+
"esbuild": "^0.28.2",
|
|
59
60
|
"glob": "^13.0.0",
|
|
60
61
|
"jest": "^30.2.0",
|
|
61
|
-
"js-yaml": "^4.1.1"
|
|
62
|
-
},
|
|
63
|
-
"dependencies": {
|
|
64
|
-
"dotenv": "^17.2.3",
|
|
62
|
+
"js-yaml": "^4.1.1",
|
|
65
63
|
"mysql2": "^3.16.0"
|
|
64
|
+
},
|
|
65
|
+
"bugs": {
|
|
66
|
+
"url": "https://github.com/kckern/ScriptureGuide/issues"
|
|
66
67
|
}
|
|
67
68
|
}
|