@joewalker/scripture-ref 0.4.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ # 0.4.0 (2026-05-10)
2
+
3
+ * The package is now published to npm as `@joewalker/scripture-ref`, alongside the existing tagged releases on GitLab.
4
+ * Fixed verse rendering so verses containing `;`, `:`, `!`, or `?` no longer emit a stray space before the punctuation when returned from `search`. `getPassageText` and `search` now share a single rendering helper instead of duplicating the word-joining loop.
5
+ * Fixed the `Passage` constructor so it copies and normalises the caller's range array, and made `verseRanges()` return a defensive copy. Mutating the array passed into the constructor, or the array returned from `verseRanges()`, no longer bypasses the sort and defragment invariants and corrupts the `Passage`'s internal state.
6
+
7
+ # 0.3.2 (2026-05-10)
8
+
9
+ * Fixed `Verse.min` and `Verse.max` so a verse already at the canonical boundary is returned as-is rather than replaced with a fresh sentinel, and made at-least-one-argument a type-level requirement.
10
+ * Fixed `PassageTally.results` so it no longer crashes when called with a non-positive `minScore`, and short-circuited `search` to return an empty result block for queries that contain no usable terms instead of ranking every verse in the Bible.
11
+ * Fixed the README quick start and API overview so the documented usage matches the public API: `Passage.fromString` instead of the non-existent `Passage.parse`, and the uppercase `'ESV'` bookId that `getPassageText` and `search` actually accept.
12
+
13
+ # 0.3.1 (2026-05-07)
14
+
15
+ * Fixed `search` so repeated matches are no longer skipped after an earlier hit, and punctuation or regular expression characters in search terms are treated as literal text rather than causing a search error.
16
+ * Fixed `PassageTally` and search result ranking so the final verse of the Bible, Rev 22:21, can be counted and returned.
17
+ * Fixed reference parsing so tab characters inside a reference are treated as whitespace rather than splitting the reference and expanding a single verse to a whole book.
18
+ * Fixed `Verse` coordinate handling so zero or negative values clamp into the valid Bible range, while non-finite and fractional coordinates are rejected with a clear error.
19
+ * Fixed `verseOrdinal` so invalid verse numbers are rejected instead of silently rolling into the next chapter.
20
+ * Updated repository metadata and installation documentation to point consumers at the GitLab repository.
21
+
22
+ # 0.3.0 (2026-05-07)
23
+
24
+ * Initial release post separation from the alsdiary repo
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # scripture-ref
2
+
3
+ A TypeScript library for parsing, normalising, and looking up references to Biblical passages. The package handles the 66-book Western Christian canon and ships with the English Standard Version (ESV) text bundled as JSON, so consumers can resolve a parsed reference straight to its verse text without a network call.
4
+
5
+ The implementation is a port of [JSword](https://www.crosswire.org/jsword/) reduced to the parts an English-language web client typically needs.
6
+
7
+ ## Installation
8
+
9
+ The package is published to npm as [`@joewalker/scripture-ref`](https://www.npmjs.com/package/@joewalker/scripture-ref):
10
+
11
+ Source and tagged releases are also available from the [GitLab repository](https://gitlab.com/joewalk/scripture-ref), and individual versions can be browsed on the [releases page](https://gitlab.com/joewalk/scripture-ref/-/tags).
12
+
13
+ ## Quick start
14
+
15
+ ```ts
16
+ import { Passage, getPassageText } from '@joewalker/scripture-ref';
17
+
18
+ const passage = Passage.fromString('John 3:16-17');
19
+
20
+ for (const { verse, text } of getPassageText('ESV', passage)) {
21
+ console.log(`${verse.toString()} ${text}`);
22
+ }
23
+ ```
24
+
25
+ Formatting (joining verses, applying styles, choosing whether to inline verse numbers) is the consumer's responsibility. `getPassageText` returns the raw verse-by-verse data and stays out of presentation concerns.
26
+
27
+ ## API overview
28
+
29
+ The library is organised around three layers.
30
+
31
+ `Verse`, `VerseRange`, and `Passage` represent references at increasing levels of granularity. A `Verse` is a single book/chapter/verse triple. A `VerseRange` is a contiguous span of verses. A `Passage` is an unordered collection of one or more ranges, suitable for representing things like a daily reading or a topical lookup. `PassageTally` tracks scoring or ranking across verses, used for example by search.
32
+
33
+ `getPassageText(bookId, passage)` is the bridge from a parsed reference to text. It returns a `ReadonlyArray<VerseText>` where each element is `{ verse, text }`. `search(bookId, terms)` runs a keyword search across the bundled translation. The only `bookId` currently shipped is `'ESV'`.
34
+
35
+ `bible-info` exposes structural helpers about the canon itself: `findBookNumber`, `getShortName`, `getLongName`, `chaptersInBook`, `versesInChapter`, `versesInBible`, `chaptersInBible`, `booksInBible`, `verseOrdinal`, `decodeOrdinal`, `bookNames`, and `shortBookNames`. These are pure data lookups and require no translation.
36
+
37
+ The `ACCURACY` constant and `Accuracy` type describe how precisely a parsed reference matched (verse, chapter, or book level). They are exposed via `__testutil__` for downstream tests that want to inspect parser internals.
38
+
39
+ ## Project layout
40
+
41
+ ```
42
+ src/
43
+ index.ts entry point and public exports
44
+ __testutil__/index.ts test-only re-exports (parser internals)
45
+ book/
46
+ books.ts getPassageText, search
47
+ esv.json ESV text (about 10MB)
48
+ passage/
49
+ bible-info.ts structural helpers
50
+ verse.ts Verse and parser
51
+ verse-range.ts VerseRange and parser
52
+ passage.ts Passage (multi-range)
53
+ passage-tally.ts PassageTally for ranking
54
+ ```
55
+
56
+ ## Development
57
+
58
+ The relevant scripts are:
59
+
60
+ ```sh
61
+ pnpm install # install dependencies
62
+ pnpm build # production build into dist/
63
+ pnpm tsc # compile all TypeScript, including tests
64
+ pnpm test # vitest, ~70 tests
65
+ pnpm lint # eslint with typed linting
66
+ pnpm format # oxfmt
67
+ pnpm clean # remove build output
68
+ ```
69
+
70
+ CI runs `pnpm tsc`, `pnpm test`, and `pnpm lint` on every pull request.
71
+
72
+ # Version Control
73
+
74
+ ## Check-in tags
75
+
76
+ We use a set of tags at the start of commits to help us update [the changelog](./CHANGELOG.md) (by enabling us to group commits and ignore inconsequential commits).
77
+
78
+ The following tags are ignored in the production of release notes.
79
+
80
+ * `Agent`: Tweaks to the configuration of LLM agent config files
81
+ * `Docs`: For updates to our documentation.
82
+ * `Lint`: For changes to and from eslint/tsc (and similar).
83
+ * `Minor`: Some small tweak like fixing a spelling mistake or changes to the editor configuration files.
84
+ * `Refactor`: For a change that makes the code nicer but doesn't introduce any new features.
85
+ * `Release vX.X.X`: When we push a release to production.
86
+ * `Testing`: For changes to the unit and integration tests.
87
+ * `Upgrade`: Keeping NPM dependencies up to date.
88
+ * `Config`: For changes to ci/pnpm/ts/git/etc. configuration files.
89
+
90
+ Example tags that would generally warrant a CHANGELOG.md entry:
91
+
92
+ * `Feature`: Some new ability, which will typically result in a bumped minor release version number and potentially a callout in the [the changelog](./CHANGELOG.md)
93
+ * `Fix`: For a blatant bug fix. However when we're updating things as we go, we're more likely to use a tag for the ongoing work, so this is more for fixing longstanding bugs.
94
+ * `Perf`: Alterations to make things faster
95
+ * `Safety`: For changes that make the system safer and easier to use.
96
+ * `Security`: For any fix that could be security sensitive.
97
+
98
+ Often there is a set of commits that achieve a larger goal and that work takes a tag.
99
+
100
+ ## License
101
+
102
+ Licensed under the [Apache License, Version 2.0](./LICENSE).
@@ -0,0 +1,45 @@
1
+ import type { Passage } from '../passage/passage.js';
2
+ import type { Verse } from '../passage/verse.js';
3
+ type BookName = string;
4
+ type BibleText = Record<BookName, Chapters>;
5
+ type Chapters = ReadonlyArray<Verses>;
6
+ type Verses = ReadonlyArray<Words>;
7
+ type Words = ReadonlyArray<Word>;
8
+ type Word = [string, string] | [string];
9
+ /**
10
+ *
11
+ */
12
+ export interface Book {
13
+ readonly version: string;
14
+ readonly versionName: string;
15
+ readonly meta: {
16
+ readonly description: string | null;
17
+ readonly source: string;
18
+ readonly swordVersion: string;
19
+ readonly swordVersionDate: string;
20
+ readonly encoding: string;
21
+ readonly language: string;
22
+ readonly license: string | null;
23
+ readonly copyright: string;
24
+ };
25
+ /**
26
+ * Record<BookName, Chapters>
27
+ * Chapters = ReadonlyArray<Verses>
28
+ * Verses = ReadonlyArray<Words>
29
+ * Words = [EnglishWords, StrongsNumber];
30
+ */
31
+ readonly books: BibleText;
32
+ }
33
+ export interface VerseText {
34
+ readonly verse: Verse;
35
+ readonly text: string;
36
+ }
37
+ /**
38
+ * Look up the Bible text for a given passage
39
+ */
40
+ export declare function getPassageText(bookId: string, passage: Passage): ReadonlyArray<VerseText>;
41
+ /**
42
+ * Produce the output text needed for a search term
43
+ */
44
+ export declare function search(bookId: string, terms: string): string;
45
+ export {};
@@ -0,0 +1,196 @@
1
+ import { chaptersInBook, verseOrdinal, versesInChapter, } from '../passage/bible-info.js';
2
+ import { PassageTally } from '../passage/passage-tally.js';
3
+ // https://github.com/jestjs/jest/issues/15000#issuecomment-2470602098
4
+ const esv = (await import(/* webpackChunkName: "mobile/esv" */ './esv.json', {
5
+ with: { type: 'json' },
6
+ })).default;
7
+ // It's not clear why we need to cast to unknown before Book, I suspect some
8
+ // data inconsistency
9
+ const esvBibleText = esv.books;
10
+ /**
11
+ * Look up the Bible text for a given passage
12
+ */
13
+ export function getPassageText(bookId, passage) {
14
+ if (bookId !== 'ESV') {
15
+ throw new Error(`Unknown book: '${bookId}'.`);
16
+ }
17
+ const output = [];
18
+ for (const range of passage.verseRanges()) {
19
+ for (const verse of range.verses()) {
20
+ output.push({ verse, text: renderVerseText(lookupWords(verse)) });
21
+ }
22
+ }
23
+ return output;
24
+ }
25
+ function lookupWords(verse) {
26
+ const bookName = indexLookup[verse.book];
27
+ return esvBibleText[bookName][verse.chapter - 1][verse.verse - 1];
28
+ }
29
+ /**
30
+ * Join the per-word entries for a single verse into a display string,
31
+ * keeping attaching punctuation (.,;!?:) flush with the preceding word.
32
+ */
33
+ function renderVerseText(words) {
34
+ let text = '';
35
+ for (const word of words) {
36
+ const head = word[0];
37
+ if (text.length === 0 || isAttachingPunctuation(head)) {
38
+ text += head;
39
+ }
40
+ else {
41
+ text += ` ${head}`;
42
+ }
43
+ }
44
+ return text;
45
+ }
46
+ /**
47
+ * True for punctuation that should attach to the previous word with no
48
+ * intervening space (sentence/clause punctuation).
49
+ */
50
+ function isAttachingPunctuation(word) {
51
+ return (word.startsWith('.') ||
52
+ word.startsWith(',') ||
53
+ word.startsWith(';') ||
54
+ word.startsWith('!') ||
55
+ word.startsWith('?') ||
56
+ word.startsWith(':'));
57
+ }
58
+ const indexLookup = [
59
+ '',
60
+ 'Genesis',
61
+ 'Exodus',
62
+ 'Leviticus',
63
+ 'Numbers',
64
+ 'Deuteronomy',
65
+ 'Joshua',
66
+ 'Judges',
67
+ 'Ruth',
68
+ 'I Samuel',
69
+ 'II Samuel',
70
+ 'I Kings',
71
+ 'II Kings',
72
+ 'I Chronicles',
73
+ 'II Chronicles',
74
+ 'Ezra',
75
+ 'Nehemiah',
76
+ 'Esther',
77
+ 'Job',
78
+ 'Psalms',
79
+ 'Proverbs',
80
+ 'Ecclesiastes',
81
+ 'Song of Solomon',
82
+ 'Isaiah',
83
+ 'Jeremiah',
84
+ 'Lamentations',
85
+ 'Ezekiel',
86
+ 'Daniel',
87
+ 'Hosea',
88
+ 'Joel',
89
+ 'Amos',
90
+ 'Obadiah',
91
+ 'Jonah',
92
+ 'Micah',
93
+ 'Nahum',
94
+ 'Habakkuk',
95
+ 'Zephaniah',
96
+ 'Haggai',
97
+ 'Zechariah',
98
+ 'Malachi',
99
+ 'Matthew',
100
+ 'Mark',
101
+ 'Luke',
102
+ 'John',
103
+ 'Acts',
104
+ 'Romans',
105
+ 'I Corinthians',
106
+ 'II Corinthians',
107
+ 'Galatians',
108
+ 'Ephesians',
109
+ 'Philippians',
110
+ 'Colossians',
111
+ 'I Thessalonians',
112
+ 'II Thessalonians',
113
+ 'I Timothy',
114
+ 'II Timothy',
115
+ 'Titus',
116
+ 'Philemon',
117
+ 'Hebrews',
118
+ 'James',
119
+ 'I Peter',
120
+ 'II Peter',
121
+ 'I John',
122
+ 'II John',
123
+ 'III John',
124
+ 'Jude',
125
+ 'Revelation of John',
126
+ ];
127
+ /**
128
+ * Escape a string so it can be safely embedded in a regular expression.
129
+ */
130
+ function escapeRegExp(value) {
131
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
132
+ }
133
+ /**
134
+ * Produce the output text needed for a search term
135
+ */
136
+ export function search(bookId, terms) {
137
+ if (bookId !== 'ESV') {
138
+ throw new Error(`Unknown book: '${bookId}'.`);
139
+ }
140
+ const searchWords = terms
141
+ .split(' ')
142
+ .filter(word => word.trim().length > 0)
143
+ .map(word => {
144
+ const pattern = `\\b(${escapeRegExp(word)})\\b`;
145
+ return {
146
+ // The `g` flag mutates `lastIndex` across `.test()` calls and would
147
+ // make matches on later words start past the beginning of the string.
148
+ test: new RegExp(pattern, 'i'),
149
+ highlight: new RegExp(pattern, 'gi'),
150
+ };
151
+ });
152
+ if (searchWords.length === 0) {
153
+ return '\n\n';
154
+ }
155
+ const tally = new PassageTally();
156
+ for (let book = 1; book < indexLookup.length; book++) {
157
+ const bookName = indexLookup[book];
158
+ const bookData = esvBibleText[bookName];
159
+ const maxChapter = chaptersInBook(book);
160
+ for (let chapter = 1; chapter <= maxChapter; chapter++) {
161
+ const chapterData = bookData[chapter - 1];
162
+ const maxVerse = versesInChapter(book, chapter);
163
+ for (let verse = 1; verse <= maxVerse; verse++) {
164
+ const ordinal = verseOrdinal(book, chapter, verse);
165
+ const words = chapterData[verse - 1];
166
+ for (const searchWord of searchWords) {
167
+ wordLoop: for (const word of words) {
168
+ if (searchWord.test.test(word[0])) {
169
+ tally.incrementByOrdinal(ordinal, 1);
170
+ // Verses with multiple matches for a search term should not
171
+ // get extra weighting
172
+ break wordLoop;
173
+ }
174
+ }
175
+ }
176
+ }
177
+ }
178
+ }
179
+ return (
180
+ // eslint-disable-next-line prefer-template
181
+ '\n' +
182
+ tally
183
+ .results({ minScore: searchWords.length })
184
+ .map(verse => {
185
+ let text = renderVerseText(lookupWords(verse));
186
+ for (const searchWord of searchWords) {
187
+ text = text.replace(searchWord.highlight, x => {
188
+ return `**${x}**`;
189
+ });
190
+ }
191
+ return `[${verse.toString()} → ${text}]`;
192
+ })
193
+ .join('\n') +
194
+ '\n');
195
+ }
196
+ //# sourceMappingURL=books.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"books.js","sourceRoot":"","sources":["../../src/book/books.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,YAAY,EACZ,eAAe,GAChB,M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