@joewalker/scripture-ref 0.4.0 → 0.5.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 +7 -0
- package/README.md +1 -1
- package/dist/book/books.d.ts +40 -17
- package/dist/book/books.js +147 -113
- package/dist/book/books.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/passage/bible-info.d.ts +21 -0
- package/dist/passage/bible-info.js +319 -421
- package/dist/passage/bible-info.js.map +1 -1
- package/dist/passage/verse.js +6 -2
- package/dist/passage/verse.js.map +1 -1
- package/package.json +1 -1
- /package/dist/book/{esv.json → data/ESV.json} +0 -0
|
@@ -140,194 +140,294 @@ const SHORT_NAMES = [
|
|
|
140
140
|
'Jude',
|
|
141
141
|
'Rev',
|
|
142
142
|
];
|
|
143
|
+
const BOOK_ALIASES = [
|
|
144
|
+
[1, 'bereshis bereshit breshit ge gen genesis gn libergenesis'],
|
|
145
|
+
[2, 'ex exo exod exodus liberexodus shemot shemoth'],
|
|
146
|
+
[3, 'le leuitikon lev leviticus liberleviticus lv vayikra wayyiqra'],
|
|
147
|
+
[4, 'arithmoi bamidbar bemidbar bmidbar nb nm nu num numbers numeri'],
|
|
148
|
+
[5, 'de deu deut deuteronomion deuteronomium deuteronomy devarim dt dvarim'],
|
|
149
|
+
[6, 'joshua josh jos iesousnaue jesusnave josue jsh yehoshua'],
|
|
150
|
+
[7, 'bookofjudges iudices jdg jdgs jg judg judges kritai shoftim'],
|
|
151
|
+
[8, 'routh rth ru rut ruth'],
|
|
152
|
+
[
|
|
153
|
+
9,
|
|
154
|
+
'1sam 1samuel 1basileion 1kingdoms 1regum 1s 1sa 1samuelis 1sm 1stsamuel 1stsam firstsamuel firstsam isam isamuel shmuelalef shmuelaleph',
|
|
155
|
+
],
|
|
156
|
+
[
|
|
157
|
+
10,
|
|
158
|
+
'2sam 2samuel 2basileion 2kingdoms 2ndsamuel 2ndsam 2regum 2s 2sa 2samuelis 2sm iisam iisamuel secondsamuel secondsam shmuelbet shmuelbeth',
|
|
159
|
+
],
|
|
160
|
+
[
|
|
161
|
+
11,
|
|
162
|
+
'1kgs 1kings 1k 1ki 1kin 1stkings 1stkgs 3basileion 3kingdoms 3kings 3regum firstkings firstkgs ikgs ikings melachimalef melachimaleph melakhimalef thirdkings',
|
|
163
|
+
],
|
|
164
|
+
[
|
|
165
|
+
12,
|
|
166
|
+
'2kgs 2kings 2k 2ki 2kin 2ndkings 2ndkgs 4basileion 4kingdoms 4kings 4regum fourthkings iikgs iikings melachimbet melachimbeth melakhimbet secondkings secondkgs',
|
|
167
|
+
],
|
|
168
|
+
[
|
|
169
|
+
13,
|
|
170
|
+
'1chr 1chron 1chronicles 1paralipomenon 1ch 1chro 1paraleipomenon 1paralipomena 1stchronicles 1stchron divreihayamimalef divreihayamimaleph firstchronicles firstchron ichr ichron ichronicles ich',
|
|
171
|
+
],
|
|
172
|
+
[
|
|
173
|
+
14,
|
|
174
|
+
'2chr 2chron 2chronicles 2paralipomenon 2ch 2chro 2ndchronicles 2ndchron 2paraleipomenon 2paralipomena divreihayamimbet divreihayamimbeth iichr iichron iichronicles iich secondchronicles secondchron',
|
|
175
|
+
],
|
|
176
|
+
[15, 'etzra ezr ezra'],
|
|
177
|
+
[16, 'ne nechamyah nechemyah neh nehemiah nehemias'],
|
|
178
|
+
[17, 'es est ester esth esther megillatesther'],
|
|
179
|
+
[18, 'job jb iob iyov iyyov yov'],
|
|
180
|
+
[
|
|
181
|
+
19,
|
|
182
|
+
'ps psa psalm psalmi psalmoi psalms psalter pslm psm pss tehilim tehillim',
|
|
183
|
+
],
|
|
184
|
+
[
|
|
185
|
+
20,
|
|
186
|
+
'mishlei paroimiai pr pro prov proverbia proverbs proverbsofsolomon prv sentences',
|
|
187
|
+
],
|
|
188
|
+
[
|
|
189
|
+
21,
|
|
190
|
+
'ec ecc eccl eccle eccles ecclesiastes ekklesiastes kohelet koheleth preacher qoh qohelet qoheleth thepreacher',
|
|
191
|
+
],
|
|
192
|
+
[
|
|
193
|
+
22,
|
|
194
|
+
'asmaasmaton cant canticleofcanticles canticles canticumcanticorum shirhashirim so son sofsol solsong songofsol songofsolomon songofsongs song songsol sos ss',
|
|
195
|
+
],
|
|
196
|
+
[23, 'esaias is isa isaiah liberisaiae yeshayah yeshayahu'],
|
|
197
|
+
[24, 'hieremias ieremias je jer jeremiah jeremias jr yirmeyah yirmeyahu'],
|
|
198
|
+
[
|
|
199
|
+
25,
|
|
200
|
+
'eicha eikhah la lam lament lamentations lamentationsofjeremiah threni threnoi',
|
|
201
|
+
],
|
|
202
|
+
[26, 'eze ezechiel ezek ezekiel ezk iezekiel yechezkel yechizkiel yehezkel'],
|
|
203
|
+
[27, 'da dan daniel daniyyel dn'],
|
|
204
|
+
[28, 'ho hos hosea hosee hoshea osee'],
|
|
205
|
+
[29, 'joel joe jl ioel yoel'],
|
|
206
|
+
[30, 'amos am amo mos'],
|
|
207
|
+
[31, 'abdias ob oba obad obadiah obdiou ovadiah ovadyah'],
|
|
208
|
+
[32, 'jonah jnh ionas jonas yonah'],
|
|
209
|
+
[33, 'mc mi mic micah micha michaias mikhah'],
|
|
210
|
+
[34, 'nahum nah na naoum'],
|
|
211
|
+
[35, 'abacuc ambakoum hab habacuc habakkuk havaquq hb'],
|
|
212
|
+
[36, 'sophonias tzefanyah tzfanyah zep zeph zephaniah zp'],
|
|
213
|
+
[37, 'aggeus angaios chagai chaggai hag haggai hg'],
|
|
214
|
+
[38, 'zacharias zc zec zech zechariah zekharyah zkharyah'],
|
|
215
|
+
[39, 'mal malachi malachias malakhi ml'],
|
|
216
|
+
[
|
|
217
|
+
40,
|
|
218
|
+
'gospelmatthew gospelofmatthew mat maththaios matt matthaeus matthaios matthew mt secundummatthaeum stmatthew',
|
|
219
|
+
],
|
|
220
|
+
[
|
|
221
|
+
41,
|
|
222
|
+
'gospelmark gospelofmark mar marcus mark markos mk mr mrk secundummarcum stmark',
|
|
223
|
+
],
|
|
224
|
+
[
|
|
225
|
+
42,
|
|
226
|
+
'gospelluke gospelofluke lk loukas lu lucas luk luke secundumlucam stluke',
|
|
227
|
+
],
|
|
228
|
+
[
|
|
229
|
+
43,
|
|
230
|
+
'gospeljohn gospelofjohn ioannes ioannis jhn jn joh john secundumioannem stjohn',
|
|
231
|
+
],
|
|
232
|
+
[44, 'ac act actsoftheapostles acts actus praxeis'],
|
|
233
|
+
[45, 'adromanos epistleromans letterromans rm ro rom romaios romans'],
|
|
234
|
+
[
|
|
235
|
+
46,
|
|
236
|
+
'1cor 1corinthians 1adcorinthios 1co 1korinthios 1stcorinthians 1stcor epistlecorinthiansi firstcorinthians firstcor firstepistlecorinthians icor icorinthians',
|
|
237
|
+
],
|
|
238
|
+
[
|
|
239
|
+
47,
|
|
240
|
+
'2cor 2corinthians 2adcorinthios 2co 2korinthios 2ndcorinthians 2ndcor epistlecorinthiansii iicor iicorinthians secondcorinthians secondcor secondepistlecorinthians',
|
|
241
|
+
],
|
|
242
|
+
[48, 'adgalatas epistlegalatians ga gal galates galatians lettergalatians'],
|
|
243
|
+
[
|
|
244
|
+
49,
|
|
245
|
+
'adephesios ep eph ephes ephesians ephesios epistleephesians letterephesians',
|
|
246
|
+
],
|
|
247
|
+
[
|
|
248
|
+
50,
|
|
249
|
+
'adphilippenses epistlephilippians letterphilippians phili philipp philippesios philippians php pp',
|
|
250
|
+
],
|
|
251
|
+
[
|
|
252
|
+
51,
|
|
253
|
+
'adcolossenses co col coloss colossians epistlecolossians kolossaios lettercolossians',
|
|
254
|
+
],
|
|
255
|
+
[
|
|
256
|
+
52,
|
|
257
|
+
'1thess 1thessalonians 1adthessalonicenses 1stthessalonians 1stthess 1th 1thes 1thessalonikeus firstthessalonians firstepistlethessalonians firstthess ithess ithessalonians ith',
|
|
258
|
+
],
|
|
259
|
+
[
|
|
260
|
+
53,
|
|
261
|
+
'2thess 2thessalonians 2adthessalonicenses 2ndthessalonians 2ndthess 2th 2thes 2thessalonikeus iithess iithessalonians iith secondthessalonians secondepistlethessalonians secondthess',
|
|
262
|
+
],
|
|
263
|
+
[
|
|
264
|
+
54,
|
|
265
|
+
'1tim 1timothy 1adtimotheum 1sttimothy 1sttim 1ti 1timotheos firsttimothy firstepistletimothy firsttim itim itimothy',
|
|
266
|
+
],
|
|
267
|
+
[
|
|
268
|
+
55,
|
|
269
|
+
'2tim 2timothy 2adtimotheum 2ndtimothy 2ndtim 2ti 2timotheos iitim iitimothy secondtimothy secondepistletimothy secondtim',
|
|
270
|
+
],
|
|
271
|
+
[56, 'adtitum epistletitus ti tit titos titus'],
|
|
272
|
+
[
|
|
273
|
+
57,
|
|
274
|
+
'adphilemonem epistlephilemon letterphilemon phile philem philemon phlm phm pm',
|
|
275
|
+
],
|
|
276
|
+
[58, 'adhebraeos epistlehebrews he heb hebr hebraios hebrews letterhebrews'],
|
|
277
|
+
[
|
|
278
|
+
59,
|
|
279
|
+
'epistleofjames generalepistleofjames iacobi iakobos jacob jam james jas jm',
|
|
280
|
+
],
|
|
281
|
+
[
|
|
282
|
+
60,
|
|
283
|
+
'1pet 1peter 1p 1pe 1petri 1petros 1pt 1stpeter firstpeter firstepistleofpeter ipet ipeter ipt',
|
|
284
|
+
],
|
|
285
|
+
[
|
|
286
|
+
61,
|
|
287
|
+
'2pet 2peter 2ndpeter 2p 2pe 2petri 2petros 2pt iipet iipeter iipt secondpeter secondepistleofpeter',
|
|
288
|
+
],
|
|
289
|
+
[
|
|
290
|
+
62,
|
|
291
|
+
'1jn 1john 1ioannes 1ioannis 1j 1jhn 1jo 1joh 1stjohn firstjohn firstepistleofjohn ijn ijohn ijhn ijo ijoh',
|
|
292
|
+
],
|
|
293
|
+
[
|
|
294
|
+
63,
|
|
295
|
+
'2jn 2john 2ioannes 2ioannis 2j 2jhn 2jo 2joh 2ndjohn iijn iijohn iijhn iijo iijoh secondjohn secondepistleofjohn',
|
|
296
|
+
],
|
|
297
|
+
[
|
|
298
|
+
64,
|
|
299
|
+
'3jn 3john 3ioannes 3ioannis 3j 3jhn 3jo 3joh 3rdjohn iiijn iiijohn iiijhn iiijo iiijoh thirdjohn thirdepistleofjohn',
|
|
300
|
+
],
|
|
301
|
+
[65, 'epistleofjude generalepistleofjude ioudas iudas jd jud judas jude'],
|
|
302
|
+
[
|
|
303
|
+
66,
|
|
304
|
+
'apoc apocalypse apocalypseofjohn apocalypsis apokalupsis apokalypsis re rev revelationofjohn revelation revelationofstjohnthedivine revelations rv therevelationofstjohnthedivine therevelation',
|
|
305
|
+
],
|
|
306
|
+
];
|
|
307
|
+
const AMBIGUOUS_BOOK_ALIASES = new Map([
|
|
308
|
+
['ez', 'Ezra (15) / Ezekiel (26)'],
|
|
309
|
+
['jon', 'Jonah (32) / John (43)'],
|
|
310
|
+
['phil', 'Philippians (50) / Philemon (57)'],
|
|
311
|
+
]);
|
|
312
|
+
/**
|
|
313
|
+
* Build the normalized book alias lookup table.
|
|
314
|
+
*
|
|
315
|
+
* Throws if the same alias is assigned to two different books, or if an alias
|
|
316
|
+
* is also listed in `ambiguousAliases` (the ambiguous branch in
|
|
317
|
+
* `_lookupBookNumber` would otherwise silently shadow the concrete entry).
|
|
318
|
+
*/
|
|
319
|
+
export function _buildBookLookup(aliasesByBook, ambiguousAliases) {
|
|
320
|
+
const lookup = new Map();
|
|
321
|
+
for (const [bookNumber, aliases] of aliasesByBook) {
|
|
322
|
+
for (const alias of aliases.split(' ')) {
|
|
323
|
+
if (ambiguousAliases.has(alias)) {
|
|
324
|
+
throw new Error(`Book alias '${alias}' is listed as ambiguous but also assigned ` +
|
|
325
|
+
`concretely to book ${bookNumber}.`);
|
|
326
|
+
}
|
|
327
|
+
const existingBookNumber = lookup.get(alias);
|
|
328
|
+
if (existingBookNumber !== undefined &&
|
|
329
|
+
existingBookNumber !== bookNumber) {
|
|
330
|
+
throw new Error(`Book alias '${alias}' is ambiguous between books ` +
|
|
331
|
+
`${existingBookNumber} and ${bookNumber}.`);
|
|
332
|
+
}
|
|
333
|
+
lookup.set(alias, bookNumber);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return lookup;
|
|
337
|
+
}
|
|
338
|
+
const BOOK_LOOKUP = _buildBookLookup(BOOK_ALIASES, AMBIGUOUS_BOOK_ALIASES);
|
|
339
|
+
/**
|
|
340
|
+
* Normalize a book name for exact lookup.
|
|
341
|
+
*/
|
|
342
|
+
function normalizeBookName(name) {
|
|
343
|
+
return name.replace(/[^a-z0-9]/gi, '').toLowerCase();
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Return the maximum edit distance allowed for a fuzzy book lookup.
|
|
347
|
+
*/
|
|
348
|
+
function maxFuzzyBookNameDistance(nameLength) {
|
|
349
|
+
if (nameLength <= 4) {
|
|
350
|
+
return 0;
|
|
351
|
+
}
|
|
352
|
+
if (nameLength <= 7) {
|
|
353
|
+
return 1;
|
|
354
|
+
}
|
|
355
|
+
if (nameLength <= 12) {
|
|
356
|
+
return 2;
|
|
357
|
+
}
|
|
358
|
+
return 3;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Calculate edit distance while treating adjacent transpositions as one edit.
|
|
362
|
+
*/
|
|
363
|
+
function adjacentTranspositionDistance(left, right) {
|
|
364
|
+
let twoRowsBack = new Array(right.length + 1).fill(0);
|
|
365
|
+
let previousRow = Array.from({ length: right.length + 1 }, (_value, index) => index);
|
|
366
|
+
let currentRow = new Array(right.length + 1).fill(0);
|
|
367
|
+
for (let leftIndex = 1; leftIndex <= left.length; leftIndex += 1) {
|
|
368
|
+
currentRow[0] = leftIndex;
|
|
369
|
+
for (let rightIndex = 1; rightIndex <= right.length; rightIndex += 1) {
|
|
370
|
+
const substitutionCost = left[leftIndex - 1] === right[rightIndex - 1] ? 0 : 1;
|
|
371
|
+
let distance = Math.min(previousRow[rightIndex] + 1, currentRow[rightIndex - 1] + 1, previousRow[rightIndex - 1] + substitutionCost);
|
|
372
|
+
if (leftIndex > 1 &&
|
|
373
|
+
rightIndex > 1 &&
|
|
374
|
+
left[leftIndex - 1] === right[rightIndex - 2] &&
|
|
375
|
+
left[leftIndex - 2] === right[rightIndex - 1]) {
|
|
376
|
+
distance = Math.min(distance, twoRowsBack[rightIndex - 2] + 1);
|
|
377
|
+
}
|
|
378
|
+
currentRow[rightIndex] = distance;
|
|
379
|
+
}
|
|
380
|
+
const completedRow = currentRow;
|
|
381
|
+
currentRow = twoRowsBack;
|
|
382
|
+
twoRowsBack = previousRow;
|
|
383
|
+
previousRow = completedRow;
|
|
384
|
+
}
|
|
385
|
+
return previousRow[right.length];
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Format a list of book numbers for an ambiguous fuzzy lookup result.
|
|
389
|
+
*/
|
|
390
|
+
function formatAmbiguousBookList(books) {
|
|
391
|
+
return books
|
|
392
|
+
.map(bookNumber => `${LONG_NAMES[bookNumber - 1]} (${bookNumber})`)
|
|
393
|
+
.join(' / ');
|
|
394
|
+
}
|
|
143
395
|
/**
|
|
144
|
-
*
|
|
396
|
+
* Look for a unique fuzzy book alias match.
|
|
145
397
|
*/
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
'
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
'
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
'2th': 53,
|
|
180
|
-
'2timothy': 55,
|
|
181
|
-
'2ti': 55,
|
|
182
|
-
},
|
|
183
|
-
'3': {
|
|
184
|
-
'3john': 64,
|
|
185
|
-
'3jo': 64,
|
|
186
|
-
},
|
|
187
|
-
a: {
|
|
188
|
-
acts: 44,
|
|
189
|
-
act: 44,
|
|
190
|
-
amos: 30,
|
|
191
|
-
amo: 30,
|
|
192
|
-
am: 30,
|
|
193
|
-
},
|
|
194
|
-
b: {},
|
|
195
|
-
c: {
|
|
196
|
-
colossians: 51,
|
|
197
|
-
col: 51,
|
|
198
|
-
},
|
|
199
|
-
d: {
|
|
200
|
-
deuteronomy: 5,
|
|
201
|
-
deu: 5,
|
|
202
|
-
daniel: 27,
|
|
203
|
-
dan: 27,
|
|
204
|
-
},
|
|
205
|
-
e: {
|
|
206
|
-
exodus: 2,
|
|
207
|
-
exo: 2,
|
|
208
|
-
ezra: 15,
|
|
209
|
-
ezr: 15,
|
|
210
|
-
esther: 17,
|
|
211
|
-
est: 17,
|
|
212
|
-
ecclesiastes: 21,
|
|
213
|
-
ecc: 21,
|
|
214
|
-
ezekiel: 26,
|
|
215
|
-
eze: 26,
|
|
216
|
-
ephesians: 49,
|
|
217
|
-
eph: 49,
|
|
218
|
-
},
|
|
219
|
-
f: {},
|
|
220
|
-
g: {
|
|
221
|
-
genesis: 1,
|
|
222
|
-
gen: 1,
|
|
223
|
-
galatians: 48,
|
|
224
|
-
gal: 48,
|
|
225
|
-
},
|
|
226
|
-
h: {
|
|
227
|
-
hosea: 28,
|
|
228
|
-
hos: 28,
|
|
229
|
-
habakkuk: 35,
|
|
230
|
-
hab: 35,
|
|
231
|
-
haggai: 37,
|
|
232
|
-
hag: 37,
|
|
233
|
-
hebrews: 58,
|
|
234
|
-
heb: 58,
|
|
235
|
-
},
|
|
236
|
-
i: {
|
|
237
|
-
isaiah: 23,
|
|
238
|
-
isa: 23,
|
|
239
|
-
},
|
|
240
|
-
j: {
|
|
241
|
-
joshua: 6,
|
|
242
|
-
jos: 6,
|
|
243
|
-
judges: 7,
|
|
244
|
-
judg: 7,
|
|
245
|
-
job: 18,
|
|
246
|
-
jeremiah: 24,
|
|
247
|
-
jer: 24,
|
|
248
|
-
joel: 29,
|
|
249
|
-
joe: 29,
|
|
250
|
-
jonah: 32,
|
|
251
|
-
jon: 32,
|
|
252
|
-
john: 43,
|
|
253
|
-
joh: 43,
|
|
254
|
-
james: 59,
|
|
255
|
-
jam: 59,
|
|
256
|
-
jude: 65,
|
|
257
|
-
jud: 65,
|
|
258
|
-
},
|
|
259
|
-
k: {},
|
|
260
|
-
l: {
|
|
261
|
-
leviticus: 3,
|
|
262
|
-
lev: 3,
|
|
263
|
-
lamentations: 25,
|
|
264
|
-
lam: 25,
|
|
265
|
-
luke: 42,
|
|
266
|
-
luk: 42,
|
|
267
|
-
},
|
|
268
|
-
m: {
|
|
269
|
-
micah: 33,
|
|
270
|
-
mic: 33,
|
|
271
|
-
malachi: 39,
|
|
272
|
-
mal: 39,
|
|
273
|
-
matthew: 40,
|
|
274
|
-
mat: 40,
|
|
275
|
-
mark: 41,
|
|
276
|
-
mar: 41,
|
|
277
|
-
},
|
|
278
|
-
n: {
|
|
279
|
-
numbers: 4,
|
|
280
|
-
num: 4,
|
|
281
|
-
nehemiah: 16,
|
|
282
|
-
neh: 16,
|
|
283
|
-
nahum: 34,
|
|
284
|
-
nah: 34,
|
|
285
|
-
},
|
|
286
|
-
o: {
|
|
287
|
-
obadiah: 31,
|
|
288
|
-
oba: 31,
|
|
289
|
-
},
|
|
290
|
-
p: {
|
|
291
|
-
psalms: 19,
|
|
292
|
-
psa: 19,
|
|
293
|
-
proverbs: 20,
|
|
294
|
-
pro: 20,
|
|
295
|
-
philippians: 50,
|
|
296
|
-
phili: 50,
|
|
297
|
-
philemon: 57,
|
|
298
|
-
phile: 57,
|
|
299
|
-
},
|
|
300
|
-
q: {},
|
|
301
|
-
r: {
|
|
302
|
-
ruth: 8,
|
|
303
|
-
rut: 8,
|
|
304
|
-
romans: 45,
|
|
305
|
-
rom: 45,
|
|
306
|
-
revelation: 66,
|
|
307
|
-
rev: 66,
|
|
308
|
-
},
|
|
309
|
-
s: {
|
|
310
|
-
songofsolomon: 22,
|
|
311
|
-
son: 22,
|
|
312
|
-
song: 22,
|
|
313
|
-
ss: 22,
|
|
314
|
-
},
|
|
315
|
-
t: {
|
|
316
|
-
titus: 56,
|
|
317
|
-
tit: 56,
|
|
318
|
-
},
|
|
319
|
-
u: {},
|
|
320
|
-
v: {},
|
|
321
|
-
w: {},
|
|
322
|
-
x: {},
|
|
323
|
-
y: {},
|
|
324
|
-
z: {
|
|
325
|
-
zephaniah: 36,
|
|
326
|
-
zep: 36,
|
|
327
|
-
zechariah: 38,
|
|
328
|
-
zec: 38,
|
|
329
|
-
},
|
|
330
|
-
};
|
|
398
|
+
function lookupFuzzyBookNumber(lookupName) {
|
|
399
|
+
const maxDistance = maxFuzzyBookNameDistance(lookupName.length);
|
|
400
|
+
if (maxDistance === 0) {
|
|
401
|
+
return { type: 'unknown' };
|
|
402
|
+
}
|
|
403
|
+
let bestDistance = maxDistance + 1;
|
|
404
|
+
const bestBooks = new Set();
|
|
405
|
+
for (const [alias, book] of BOOK_LOOKUP) {
|
|
406
|
+
if (Math.abs(alias.length - lookupName.length) > maxDistance) {
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
const distance = adjacentTranspositionDistance(lookupName, alias);
|
|
410
|
+
if (distance > maxDistance || distance > bestDistance) {
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
if (distance < bestDistance) {
|
|
414
|
+
bestBooks.clear();
|
|
415
|
+
bestDistance = distance;
|
|
416
|
+
}
|
|
417
|
+
bestBooks.add(book);
|
|
418
|
+
}
|
|
419
|
+
if (bestBooks.size === 0) {
|
|
420
|
+
return { type: 'unknown' };
|
|
421
|
+
}
|
|
422
|
+
const matchingBooks = Array.from(bestBooks).sort((leftBook, rightBook) => leftBook - rightBook);
|
|
423
|
+
if (matchingBooks.length > 1) {
|
|
424
|
+
return {
|
|
425
|
+
type: 'ambiguous',
|
|
426
|
+
books: formatAmbiguousBookList(matchingBooks),
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
return { type: 'found', book: matchingBooks[0] };
|
|
430
|
+
}
|
|
331
431
|
/**
|
|
332
432
|
* Find the (1-based) book number for a given string.
|
|
333
433
|
* e.g.:
|
|
@@ -336,24 +436,32 @@ const books = {
|
|
|
336
436
|
* - findBookNumber('g') === undefined
|
|
337
437
|
*/
|
|
338
438
|
export function findBookNumber(name) {
|
|
339
|
-
|
|
340
|
-
|
|
439
|
+
const result = _lookupBookNumber(name);
|
|
440
|
+
if (result.type === 'found') {
|
|
441
|
+
return result.book;
|
|
442
|
+
}
|
|
443
|
+
return undefined;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Look up a normalized book name and report ambiguous matches separately.
|
|
447
|
+
*/
|
|
448
|
+
export function _lookupBookNumber(name) {
|
|
449
|
+
if (typeof name !== 'string') {
|
|
450
|
+
return { type: 'unknown' };
|
|
341
451
|
}
|
|
342
|
-
const lookupName = name
|
|
452
|
+
const lookupName = normalizeBookName(name);
|
|
343
453
|
if (lookupName.length < 2) {
|
|
344
|
-
return
|
|
454
|
+
return { type: 'unknown' };
|
|
345
455
|
}
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
return undefined;
|
|
456
|
+
const ambiguousBooks = AMBIGUOUS_BOOK_ALIASES.get(lookupName);
|
|
457
|
+
if (ambiguousBooks !== undefined) {
|
|
458
|
+
return { type: 'ambiguous', books: ambiguousBooks };
|
|
350
459
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
}
|
|
460
|
+
const book = BOOK_LOOKUP.get(lookupName);
|
|
461
|
+
if (book !== undefined) {
|
|
462
|
+
return { type: 'found', book };
|
|
355
463
|
}
|
|
356
|
-
return
|
|
464
|
+
return lookupFuzzyBookNumber(lookupName);
|
|
357
465
|
}
|
|
358
466
|
/**
|
|
359
467
|
* Constant for the number of chapters in each book
|
|
@@ -523,230 +631,20 @@ const VERSES_IN_CHAPTER = [
|
|
|
523
631
|
],
|
|
524
632
|
];
|
|
525
633
|
/**
|
|
526
|
-
*
|
|
527
|
-
*
|
|
528
|
-
* this module) then you will need to cut the psalms line in half to
|
|
529
|
-
* get it to compile under JBuilder.
|
|
634
|
+
* Build ordinal lookups from the chapter verse counts so the generated
|
|
635
|
+
* package does not need to store the same data twice.
|
|
530
636
|
*/
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
1869, 1891, 1922, 1949, 1985, 2001, 2028, 2053, 2079, 2115, 2146, 2179,
|
|
541
|
-
2197, 2237, 2274, 2295, 2338, 2384, 2422, 2440, 2475, 2498, 2533, 2568,
|
|
542
|
-
2606, 2635, 2666, 2709,
|
|
543
|
-
],
|
|
544
|
-
[
|
|
545
|
-
2747, 2764, 2780, 2797, 2832, 2851, 2881, 2919, 2955, 2979, 2999, 3046,
|
|
546
|
-
3054, 3113, 3170, 3203, 3237, 3253, 3283, 3320, 3347, 3371, 3404, 3448,
|
|
547
|
-
3471, 3526, 3572,
|
|
548
|
-
],
|
|
549
|
-
[
|
|
550
|
-
3606, 3660, 3694, 3745, 3794, 3825, 3852, 3941, 3967, 3990, 4026, 4061,
|
|
551
|
-
4077, 4110, 4155, 4196, 4246, 4259, 4291, 4313, 4342, 4377, 4418, 4448,
|
|
552
|
-
4473, 4491, 4556, 4579, 4610, 4650, 4666, 4720, 4762, 4818, 4847, 4881,
|
|
553
|
-
],
|
|
554
|
-
[
|
|
555
|
-
4894, 4940, 4977, 5006, 5055, 5088, 5113, 5139, 5159, 5188, 5210, 5242,
|
|
556
|
-
5274, 5292, 5321, 5344, 5366, 5386, 5408, 5429, 5449, 5472, 5502, 5527,
|
|
557
|
-
5549, 5568, 5587, 5613, 5681, 5710, 5730, 5760, 5812, 5841,
|
|
558
|
-
],
|
|
559
|
-
[
|
|
560
|
-
5853, 5871, 5895, 5912, 5936, 5951, 5978, 6004, 6039, 6066, 6109, 6132,
|
|
561
|
-
6156, 6189, 6204, 6267, 6277, 6295, 6323, 6374, 6383, 6428, 6462, 6478,
|
|
562
|
-
],
|
|
563
|
-
[
|
|
564
|
-
6511, 6547, 6570, 6601, 6625, 6656, 6696, 6721, 6756, 6813, 6831, 6871,
|
|
565
|
-
6886, 6911, 6931, 6951, 6982, 6995, 7026, 7056, 7104,
|
|
566
|
-
],
|
|
567
|
-
[7129, 7151, 7174, 7192],
|
|
568
|
-
[
|
|
569
|
-
7214, 7242, 7278, 7299, 7321, 7333, 7354, 7371, 7393, 7420, 7447, 7462,
|
|
570
|
-
7487, 7510, 7562, 7597, 7620, 7678, 7708, 7732, 7774, 7789, 7812, 7841,
|
|
571
|
-
7863, 7907, 7932, 7944, 7969, 7980, 8011,
|
|
572
|
-
],
|
|
573
|
-
[
|
|
574
|
-
8024, 8051, 8083, 8122, 8134, 8159, 8182, 8211, 8229, 8242, 8261, 8288,
|
|
575
|
-
8319, 8358, 8391, 8428, 8451, 8480, 8513, 8556, 8582, 8604, 8655, 8694,
|
|
576
|
-
],
|
|
577
|
-
[
|
|
578
|
-
8719, 8772, 8818, 8846, 8880, 8898, 8936, 8987, 9053, 9081, 9110, 9153,
|
|
579
|
-
9186, 9220, 9251, 9285, 9319, 9343, 9389, 9410, 9453, 9482,
|
|
580
|
-
],
|
|
581
|
-
[
|
|
582
|
-
9535, 9553, 9578, 9605, 9649, 9676, 9709, 9729, 9758, 9795, 9831, 9852,
|
|
583
|
-
9873, 9898, 9927, 9965, 9985, 10026, 10063, 10100, 10121, 10147, 10167,
|
|
584
|
-
10204, 10224,
|
|
585
|
-
],
|
|
586
|
-
[
|
|
587
|
-
10254, 10308, 10363, 10387, 10430, 10456, 10537, 10577, 10617, 10661, 10675,
|
|
588
|
-
10722, 10762, 10776, 10793, 10822, 10865, 10892, 10909, 10928, 10936, 10966,
|
|
589
|
-
10985, 11017, 11048, 11079, 11111, 11145, 11166,
|
|
590
|
-
],
|
|
591
|
-
[
|
|
592
|
-
11196, 11213, 11231, 11248, 11270, 11284, 11326, 11348, 11366, 11397, 11416,
|
|
593
|
-
11439, 11455, 11477, 11492, 11511, 11525, 11544, 11578, 11589, 11626, 11646,
|
|
594
|
-
11658, 11679, 11706, 11734, 11757, 11766, 11793, 11829, 11856, 11877, 11910,
|
|
595
|
-
11935, 11968, 11995,
|
|
596
|
-
],
|
|
597
|
-
[12018, 12029, 12099, 12112, 12136, 12153, 12175, 12203, 12239, 12254],
|
|
598
|
-
[
|
|
599
|
-
12298, 12309, 12329, 12361, 12384, 12403, 12422, 12495, 12513, 12551, 12590,
|
|
600
|
-
12626, 12673,
|
|
601
|
-
],
|
|
602
|
-
[12704, 12726, 12749, 12764, 12781, 12795, 12809, 12819, 12836, 12868],
|
|
603
|
-
[
|
|
604
|
-
12871, 12893, 12906, 12932, 12953, 12980, 13010, 13031, 13053, 13088, 13110,
|
|
605
|
-
13130, 13155, 13183, 13205, 13240, 13262, 13278, 13299, 13328, 13357, 13391,
|
|
606
|
-
13421, 13438, 13463, 13469, 13483, 13506, 13534, 13559, 13590, 13630, 13652,
|
|
607
|
-
13685, 13722, 13738, 13771, 13795, 13836, 13866, 13890, 13924,
|
|
608
|
-
],
|
|
609
|
-
[
|
|
610
|
-
13941, 13947, 13959, 13967, 13975, 13987, 13997, 14014, 14023, 14043, 14061,
|
|
611
|
-
14068, 14076, 14082, 14089, 14094, 14105, 14120, 14170, 14184, 14193, 14206,
|
|
612
|
-
14237, 14243, 14253, 14275, 14287, 14301, 14310, 14321, 14333, 14357, 14368,
|
|
613
|
-
14390, 14412, 14440, 14452, 14492, 14514, 14527, 14544, 14557, 14568, 14573,
|
|
614
|
-
14599, 14616, 14627, 14636, 14650, 14670, 14693, 14712, 14721, 14727, 14734,
|
|
615
|
-
14757, 14770, 14781, 14792, 14809, 14821, 14829, 14841, 14852, 14862, 14875,
|
|
616
|
-
14895, 14902, 14937, 14973, 14978, 15002, 15022, 15050, 15073, 15083, 15095,
|
|
617
|
-
15115, 15187, 15200, 15219, 15235, 15243, 15261, 15273, 15286, 15303, 15310,
|
|
618
|
-
15328, 15380, 15397, 15413, 15428, 15433, 15456, 15467, 15480, 15492, 15501,
|
|
619
|
-
15510, 15515, 15523, 15551, 15573, 15608, 15653, 15701, 15744, 15757, 15788,
|
|
620
|
-
15795, 15805, 15815, 15824, 15832, 15850, 15869, 15871, 15900, 16076, 16083,
|
|
621
|
-
16091, 16100, 16104, 16112, 16117, 16123, 16128, 16134, 16142, 16150, 16153,
|
|
622
|
-
16171, 16174, 16177, 16198, 16224, 16233, 16241, 16265, 16278, 16288, 16295,
|
|
623
|
-
16307, 16322, 16343, 16353, 16373, 16387, 16396,
|
|
624
|
-
],
|
|
625
|
-
[
|
|
626
|
-
16402, 16435, 16457, 16492, 16519, 16542, 16577, 16604, 16640, 16658, 16690,
|
|
627
|
-
16721, 16749, 16774, 16809, 16842, 16875, 16903, 16927, 16956, 16986, 17017,
|
|
628
|
-
17046, 17081, 17115, 17143, 17171, 17198, 17226, 17253, 17286,
|
|
629
|
-
],
|
|
630
|
-
[
|
|
631
|
-
17317, 17335, 17361, 17383, 17399, 17419, 17431, 17460, 17477, 17495, 17515,
|
|
632
|
-
17525,
|
|
633
|
-
],
|
|
634
|
-
[17539, 17556, 17573, 17584, 17600, 17616, 17629, 17642],
|
|
635
|
-
[
|
|
636
|
-
17656, 17687, 17709, 17735, 17741, 17771, 17784, 17809, 17831, 17852, 17886,
|
|
637
|
-
17902, 17908, 17930, 17962, 17971, 17985, 17999, 18006, 18031, 18037, 18054,
|
|
638
|
-
18079, 18097, 18120, 18132, 18153, 18166, 18195, 18219, 18252, 18261, 18281,
|
|
639
|
-
18305, 18322, 18332, 18354, 18392, 18414, 18422, 18453, 18482, 18507, 18535,
|
|
640
|
-
18563, 18588, 18601, 18616, 18638, 18664, 18675, 18698, 18713, 18725, 18742,
|
|
641
|
-
18755, 18767, 18788, 18802, 18823, 18845, 18856, 18868, 18887, 18899, 18924,
|
|
642
|
-
],
|
|
643
|
-
[
|
|
644
|
-
18948, 18967, 19004, 19029, 19060, 19091, 19121, 19155, 19177, 19203, 19228,
|
|
645
|
-
19251, 19268, 19295, 19317, 19338, 19359, 19386, 19409, 19424, 19442, 19456,
|
|
646
|
-
19486, 19526, 19536, 19574, 19598, 19620, 19637, 19669, 19693, 19733, 19777,
|
|
647
|
-
19803, 19825, 19844, 19876, 19897, 19925, 19943, 19959, 19977, 19999, 20012,
|
|
648
|
-
20042, 20047, 20075, 20082, 20129, 20168, 20214, 20278,
|
|
649
|
-
],
|
|
650
|
-
[20312, 20334, 20356, 20422, 20444],
|
|
651
|
-
[
|
|
652
|
-
20466, 20494, 20504, 20531, 20548, 20565, 20579, 20606, 20624, 20635, 20657,
|
|
653
|
-
20682, 20710, 20733, 20756, 20764, 20827, 20851, 20883, 20897, 20946, 20978,
|
|
654
|
-
21009, 21058, 21085, 21102, 21123, 21159, 21185, 21206, 21232, 21250, 21282,
|
|
655
|
-
21315, 21346, 21361, 21399, 21427, 21450, 21479, 21528, 21554, 21574, 21601,
|
|
656
|
-
21632, 21657, 21681, 21704,
|
|
657
|
-
],
|
|
658
|
-
[
|
|
659
|
-
21739, 21760, 21809, 21839, 21876, 21907, 21935, 21963, 21990, 22017, 22038,
|
|
660
|
-
22083,
|
|
661
|
-
],
|
|
662
|
-
[
|
|
663
|
-
22096, 22107, 22130, 22135, 22154, 22169, 22180, 22196, 22210, 22227, 22242,
|
|
664
|
-
22254, 22268, 22284,
|
|
665
|
-
],
|
|
666
|
-
[22293, 22313, 22345],
|
|
667
|
-
[22366, 22381, 22397, 22412, 22425, 22452, 22466, 22483, 22497],
|
|
668
|
-
[22512],
|
|
669
|
-
[22533, 22550, 22560, 22570],
|
|
670
|
-
[22581, 22597, 22610, 22622, 22635, 22650, 22666],
|
|
671
|
-
[22686, 22701, 22714],
|
|
672
|
-
[22733, 22750, 22770],
|
|
673
|
-
[22789, 22807, 22822],
|
|
674
|
-
[22842, 22857],
|
|
675
|
-
[
|
|
676
|
-
22880, 22901, 22914, 22924, 22938, 22949, 22964, 22978, 23001, 23018, 23030,
|
|
677
|
-
23047, 23061, 23070,
|
|
678
|
-
],
|
|
679
|
-
[23091, 23105, 23122, 23140],
|
|
680
|
-
[
|
|
681
|
-
23146, 23171, 23194, 23211, 23236, 23284, 23318, 23347, 23381, 23419, 23461,
|
|
682
|
-
23491, 23541, 23599, 23635, 23674, 23702, 23729, 23764, 23794, 23828, 23874,
|
|
683
|
-
23920, 23959, 24010, 24056, 24131, 24197,
|
|
684
|
-
],
|
|
685
|
-
[
|
|
686
|
-
24217, 24262, 24290, 24325, 24366, 24409, 24465, 24502, 24540, 24590, 24642,
|
|
687
|
-
24675, 24719, 24756, 24828, 24875,
|
|
688
|
-
],
|
|
689
|
-
[
|
|
690
|
-
24895, 24975, 25027, 25065, 25109, 25148, 25197, 25247, 25303, 25365, 25407,
|
|
691
|
-
25461, 25520, 25555, 25590, 25622, 25653, 25690, 25733, 25781, 25828, 25866,
|
|
692
|
-
25937, 25993,
|
|
693
|
-
],
|
|
694
|
-
[
|
|
695
|
-
26046, 26097, 26122, 26158, 26212, 26259, 26330, 26383, 26442, 26483, 26525,
|
|
696
|
-
26582, 26632, 26670, 26701, 26728, 26761, 26787, 26827, 26869, 26900,
|
|
697
|
-
],
|
|
698
|
-
[
|
|
699
|
-
26925, 26951, 26998, 27024, 27061, 27103, 27118, 27178, 27218, 27261, 27309,
|
|
700
|
-
27339, 27364, 27416, 27444, 27485, 27525, 27559, 27587, 27628, 27666, 27706,
|
|
701
|
-
27736, 27771, 27798, 27825, 27857, 27901,
|
|
702
|
-
],
|
|
703
|
-
[
|
|
704
|
-
27932, 27964, 27993, 28024, 28049, 28070, 28093, 28118, 28157, 28190, 28211,
|
|
705
|
-
28247, 28268, 28282, 28305, 28338,
|
|
706
|
-
],
|
|
707
|
-
[
|
|
708
|
-
28365, 28396, 28412, 28435, 28456, 28469, 28489, 28529, 28542, 28569, 28602,
|
|
709
|
-
28636, 28667, 28680, 28720, 28778,
|
|
710
|
-
],
|
|
711
|
-
[
|
|
712
|
-
28802, 28826, 28843, 28861, 28879, 28900, 28918, 28934, 28958, 28973, 28991,
|
|
713
|
-
29024, 29045,
|
|
714
|
-
],
|
|
715
|
-
[29059, 29083, 29104, 29133, 29164, 29190],
|
|
716
|
-
[29208, 29231, 29253, 29274, 29306, 29339],
|
|
717
|
-
[29363, 29393, 29423, 29444],
|
|
718
|
-
[29467, 29496, 29519, 29544],
|
|
719
|
-
[29562, 29572, 29592, 29605, 29623],
|
|
720
|
-
[29651, 29663, 29680],
|
|
721
|
-
[29698, 29718, 29733, 29749, 29765, 29790],
|
|
722
|
-
[29811, 29829, 29855, 29872],
|
|
723
|
-
[29894, 29910, 29925],
|
|
724
|
-
[29940],
|
|
725
|
-
[
|
|
726
|
-
29965, 29979, 29997, 30016, 30032, 30046, 30066, 30094, 30107, 30135, 30174,
|
|
727
|
-
30214, 30243,
|
|
728
|
-
],
|
|
729
|
-
[30268, 30295, 30321, 30339, 30356],
|
|
730
|
-
[30376, 30401, 30426, 30448, 30467],
|
|
731
|
-
[30481, 30502, 30524],
|
|
732
|
-
[30542, 30552, 30581, 30605, 30626],
|
|
733
|
-
[30647],
|
|
734
|
-
[30660],
|
|
735
|
-
[30674],
|
|
736
|
-
[
|
|
737
|
-
30699, 30719, 30748, 30770, 30781, 30795, 30812, 30829, 30842, 30863, 30874,
|
|
738
|
-
30893, 30910, 30928, 30948, 30956, 30977, 30995, 31019, 31040, 31055, 31082,
|
|
739
|
-
],
|
|
740
|
-
];
|
|
637
|
+
function buildOrdinalAtStartOfChapter() {
|
|
638
|
+
let ordinal = 1;
|
|
639
|
+
return VERSES_IN_CHAPTER.map(chapters => chapters.map(verses => {
|
|
640
|
+
const startOrdinal = ordinal;
|
|
641
|
+
ordinal += verses;
|
|
642
|
+
return startOrdinal;
|
|
643
|
+
}));
|
|
644
|
+
}
|
|
645
|
+
const ORDINAL_AT_START_OF_CHAPTER = buildOrdinalAtStartOfChapter();
|
|
741
646
|
/** Constant for the ordinal number of the first verse in each book */
|
|
742
|
-
const ORDINAL_AT_START_OF_BOOK = [
|
|
743
|
-
1, 1534, 2747, 3606, 4894, 5853, 6511, 7129, 7214, 8024, 8719, 9535, 10254,
|
|
744
|
-
11196, 12018, 12298, 12704, 12871, 13941, 16402, 17317, 17539, 17656, 18948,
|
|
745
|
-
20312, 20466, 21739, 22096, 22293, 22366, 22512, 22533, 22581, 22686, 22733,
|
|
746
|
-
22789, 22842, 22880, 23091, 23146, 24217, 24895, 26046, 26925, 27932, 28365,
|
|
747
|
-
28802, 29059, 29208, 29363, 29467, 29562, 29651, 29698, 29811, 29894, 29940,
|
|
748
|
-
29965, 30268, 30376, 30481, 30542, 30647, 30660, 30674, 30699,
|
|
749
|
-
];
|
|
647
|
+
const ORDINAL_AT_START_OF_BOOK = ORDINAL_AT_START_OF_CHAPTER.map(chapters => chapters[0]);
|
|
750
648
|
/**
|
|
751
649
|
* What is the canonical short name for a book?
|
|
752
650
|
*/
|