codexparser 0.0.80 → 0.0.81
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/package.json +1 -1
- package/src/CodexParser.js +112 -259
- package/src/functions.js +6 -0
- package/sub-verse-scripture-test.js +1 -1
- package/tests/abbreviated_verses.js +8 -0
- package/{bcv-single-test.js → tests/bcv-single-test.js} +1 -1
- package/tests/find.js +3 -2
- package/tests/single.js +10 -0
- /package/{bcv_test.js → tests/bcv_test.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codexparser",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.81",
|
|
4
4
|
"description": "This is a Javascript Bible parser and text scanner. It will search through texts and collate all scripture references into an array and parse them into objects, and it will parse passages into objects by book, chapter, verse, and testament. ",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
package/src/CodexParser.js
CHANGED
|
@@ -22,6 +22,35 @@ class CodexParser {
|
|
|
22
22
|
this.EzraAbbrv = EzraAbbrv
|
|
23
23
|
//this.toc = toc
|
|
24
24
|
this.crawler = new crawler()
|
|
25
|
+
this.preStrings = ["III", "II", "I", "1st", "2nd", "3rd", "First", "Second", "Third", "1", "2", "3"]
|
|
26
|
+
this.preStringed = [
|
|
27
|
+
"Sam",
|
|
28
|
+
"Samuel",
|
|
29
|
+
"Kings",
|
|
30
|
+
"Kgs",
|
|
31
|
+
"Kin",
|
|
32
|
+
"Chron",
|
|
33
|
+
"Chronicles",
|
|
34
|
+
"Corinthians",
|
|
35
|
+
"Co",
|
|
36
|
+
"Cor",
|
|
37
|
+
"Thessalonians",
|
|
38
|
+
"Th",
|
|
39
|
+
"Thes",
|
|
40
|
+
"Thess",
|
|
41
|
+
"Timothy",
|
|
42
|
+
"Ti",
|
|
43
|
+
"Tim",
|
|
44
|
+
"Peter",
|
|
45
|
+
"Pe",
|
|
46
|
+
"Pet",
|
|
47
|
+
"Pt",
|
|
48
|
+
"John",
|
|
49
|
+
"Jn",
|
|
50
|
+
"Jhn",
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
this.text = String
|
|
25
54
|
}
|
|
26
55
|
|
|
27
56
|
/**
|
|
@@ -139,13 +168,14 @@ class CodexParser {
|
|
|
139
168
|
}
|
|
140
169
|
passage.original = result.osis
|
|
141
170
|
passage.scripture = this.scripturize(passage)
|
|
171
|
+
passage.passages = this.populate(result.entities[0], passage.verses)
|
|
142
172
|
passage.indices = result.indices
|
|
143
|
-
passage.entities = result.entities
|
|
144
|
-
if (passage.entities
|
|
173
|
+
passage.entities = result.entities[0]
|
|
174
|
+
if (passage.entities.translations) {
|
|
145
175
|
passage.version = {
|
|
146
|
-
name: passage.entities
|
|
147
|
-
alias: passage.entities
|
|
148
|
-
abbreviation: passage.entities
|
|
176
|
+
name: passage.entities.translations[0].translation,
|
|
177
|
+
alias: passage.entities.translations[0].alias,
|
|
178
|
+
abbreviation: passage.entities.translations[0].osis,
|
|
149
179
|
}
|
|
150
180
|
}
|
|
151
181
|
this.passages.push(passage)
|
|
@@ -153,6 +183,37 @@ class CodexParser {
|
|
|
153
183
|
this.found = []
|
|
154
184
|
return this
|
|
155
185
|
}
|
|
186
|
+
|
|
187
|
+
populate(entities, verses) {
|
|
188
|
+
let passages = []
|
|
189
|
+
for (let i = entities.start.v; i <= entities.end.v; i++) {
|
|
190
|
+
passages.push({
|
|
191
|
+
book: entities.start.b,
|
|
192
|
+
chapter: entities.start.c,
|
|
193
|
+
verse: i,
|
|
194
|
+
})
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (verses.length > 1) {
|
|
198
|
+
for (let i = 0; i < verses.length; i++) {
|
|
199
|
+
const passage = {
|
|
200
|
+
book: entities.start.b,
|
|
201
|
+
chapter: entities.start.c,
|
|
202
|
+
verse: verses[i],
|
|
203
|
+
}
|
|
204
|
+
if (
|
|
205
|
+
!passages.find(
|
|
206
|
+
(p) => p.book === passage.book && p.chapter === passage.chapter && p.verse === passage.verse
|
|
207
|
+
)
|
|
208
|
+
) {
|
|
209
|
+
passages.push(passage)
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return [...new Set(passages)]
|
|
215
|
+
}
|
|
216
|
+
|
|
156
217
|
chapterify(chapter) {
|
|
157
218
|
return chapter.start.c
|
|
158
219
|
}
|
|
@@ -234,259 +295,14 @@ class CodexParser {
|
|
|
234
295
|
.trim()
|
|
235
296
|
}
|
|
236
297
|
find(text) {
|
|
237
|
-
const books = [
|
|
238
|
-
"Gen",
|
|
239
|
-
"Ge",
|
|
240
|
-
"Gn",
|
|
241
|
-
"Exo",
|
|
242
|
-
"Ex",
|
|
243
|
-
"Exod",
|
|
244
|
-
"Lev",
|
|
245
|
-
"Le",
|
|
246
|
-
"Lv",
|
|
247
|
-
"Num",
|
|
248
|
-
"Nu",
|
|
249
|
-
"Nm",
|
|
250
|
-
"Nb",
|
|
251
|
-
"Deut",
|
|
252
|
-
"Dt",
|
|
253
|
-
"Josh",
|
|
254
|
-
"Jos",
|
|
255
|
-
"Jsh",
|
|
256
|
-
"Judg",
|
|
257
|
-
"Jdg",
|
|
258
|
-
"Jg",
|
|
259
|
-
"Jdgs",
|
|
260
|
-
"Rth",
|
|
261
|
-
"Ru",
|
|
262
|
-
"Sam",
|
|
263
|
-
"Samuel",
|
|
264
|
-
"Kings",
|
|
265
|
-
"Kgs",
|
|
266
|
-
"Kin",
|
|
267
|
-
"Chron",
|
|
268
|
-
"Chronicles",
|
|
269
|
-
"Ezra",
|
|
270
|
-
"Ezr",
|
|
271
|
-
"Ez",
|
|
272
|
-
"Neh",
|
|
273
|
-
"Ne",
|
|
274
|
-
"Esth",
|
|
275
|
-
"Es",
|
|
276
|
-
"Job",
|
|
277
|
-
"Job",
|
|
278
|
-
"Jb",
|
|
279
|
-
"Pslm",
|
|
280
|
-
"Ps",
|
|
281
|
-
"Psalms",
|
|
282
|
-
"Psa",
|
|
283
|
-
"Psm",
|
|
284
|
-
"Pss",
|
|
285
|
-
"Prov",
|
|
286
|
-
"Pr",
|
|
287
|
-
"Prv",
|
|
288
|
-
"Eccles",
|
|
289
|
-
"Ec",
|
|
290
|
-
"Song",
|
|
291
|
-
"So",
|
|
292
|
-
"Canticles",
|
|
293
|
-
"Song of Songs",
|
|
294
|
-
"SOS",
|
|
295
|
-
"Isa",
|
|
296
|
-
"Is",
|
|
297
|
-
"Jer",
|
|
298
|
-
"Je",
|
|
299
|
-
"Jr",
|
|
300
|
-
"Lam",
|
|
301
|
-
"La",
|
|
302
|
-
"Ezek",
|
|
303
|
-
"Eze",
|
|
304
|
-
"Ezk",
|
|
305
|
-
"Dan",
|
|
306
|
-
"Da",
|
|
307
|
-
"Dn",
|
|
308
|
-
"Hos",
|
|
309
|
-
"Ho",
|
|
310
|
-
"Joel",
|
|
311
|
-
"Joe",
|
|
312
|
-
"Jl",
|
|
313
|
-
"Amos",
|
|
314
|
-
"Am",
|
|
315
|
-
"Obad",
|
|
316
|
-
"Ob",
|
|
317
|
-
"Jnh",
|
|
318
|
-
"Jon",
|
|
319
|
-
"Micah",
|
|
320
|
-
"Mic",
|
|
321
|
-
"Nah",
|
|
322
|
-
"Na",
|
|
323
|
-
"Hab",
|
|
324
|
-
"Zeph",
|
|
325
|
-
"Zep",
|
|
326
|
-
"Zp",
|
|
327
|
-
"Haggai",
|
|
328
|
-
"Hag",
|
|
329
|
-
"Hg",
|
|
330
|
-
"Zech",
|
|
331
|
-
"Zec",
|
|
332
|
-
"Zc",
|
|
333
|
-
"Mal",
|
|
334
|
-
"Mal",
|
|
335
|
-
"Ml",
|
|
336
|
-
"Matt",
|
|
337
|
-
"Mt",
|
|
338
|
-
"Mrk",
|
|
339
|
-
"Mk",
|
|
340
|
-
"Mr",
|
|
341
|
-
"Luk",
|
|
342
|
-
"Lk",
|
|
343
|
-
"John",
|
|
344
|
-
"Jn",
|
|
345
|
-
"Jhn",
|
|
346
|
-
"Acts",
|
|
347
|
-
"Ac",
|
|
348
|
-
"Rom",
|
|
349
|
-
"Ro",
|
|
350
|
-
"Rm",
|
|
351
|
-
"Co",
|
|
352
|
-
"Cor",
|
|
353
|
-
"Corinthians",
|
|
354
|
-
"Gal",
|
|
355
|
-
"Ga",
|
|
356
|
-
"Ephes",
|
|
357
|
-
"Eph",
|
|
358
|
-
"Phil",
|
|
359
|
-
"Php",
|
|
360
|
-
"Col",
|
|
361
|
-
"Col",
|
|
362
|
-
"Th",
|
|
363
|
-
"Thes",
|
|
364
|
-
"Thess",
|
|
365
|
-
"Thessalonians",
|
|
366
|
-
"Ti",
|
|
367
|
-
"Tim",
|
|
368
|
-
"Timothy",
|
|
369
|
-
"Titus",
|
|
370
|
-
"Tit",
|
|
371
|
-
"Philem",
|
|
372
|
-
"Phm",
|
|
373
|
-
"Hebrews",
|
|
374
|
-
"Heb",
|
|
375
|
-
"He",
|
|
376
|
-
"James",
|
|
377
|
-
"Jas",
|
|
378
|
-
"Jm",
|
|
379
|
-
"Pe",
|
|
380
|
-
"Pet",
|
|
381
|
-
"Pt",
|
|
382
|
-
"Peter",
|
|
383
|
-
"Jn",
|
|
384
|
-
"Jo",
|
|
385
|
-
"Joh",
|
|
386
|
-
"Jhn",
|
|
387
|
-
"John",
|
|
388
|
-
"Jude",
|
|
389
|
-
"Jd",
|
|
390
|
-
"Jud",
|
|
391
|
-
"Jud",
|
|
392
|
-
"Rev",
|
|
393
|
-
"The Revelation",
|
|
394
|
-
"Genesis",
|
|
395
|
-
"Exodus",
|
|
396
|
-
"Leviticus",
|
|
397
|
-
"Numbers",
|
|
398
|
-
"Deuteronomy",
|
|
399
|
-
"Joshua",
|
|
400
|
-
"Judges",
|
|
401
|
-
"Ruth",
|
|
402
|
-
"Samuel",
|
|
403
|
-
"Kings",
|
|
404
|
-
"Chronicles",
|
|
405
|
-
"Ezra",
|
|
406
|
-
"Nehemiah",
|
|
407
|
-
"Esther",
|
|
408
|
-
"Job",
|
|
409
|
-
"Psalms",
|
|
410
|
-
"Psalm",
|
|
411
|
-
"Proverbs",
|
|
412
|
-
"Ecclesiastes",
|
|
413
|
-
"Song of Solomon",
|
|
414
|
-
"Isaiah",
|
|
415
|
-
"Jeremiah",
|
|
416
|
-
"Lamentations",
|
|
417
|
-
"Ezekiel",
|
|
418
|
-
"Daniel",
|
|
419
|
-
"Hosea",
|
|
420
|
-
"Joel",
|
|
421
|
-
"Amos",
|
|
422
|
-
"Obadiah",
|
|
423
|
-
"Jonah",
|
|
424
|
-
"Micah",
|
|
425
|
-
"Nahum",
|
|
426
|
-
"Habakkuk",
|
|
427
|
-
"Zephaniah",
|
|
428
|
-
"Haggai",
|
|
429
|
-
"Zechariah",
|
|
430
|
-
"Malachi",
|
|
431
|
-
"Matthew",
|
|
432
|
-
"Mark",
|
|
433
|
-
"Luke",
|
|
434
|
-
"John",
|
|
435
|
-
"Acts",
|
|
436
|
-
"Romans",
|
|
437
|
-
"Corinthians",
|
|
438
|
-
"Galatians",
|
|
439
|
-
"Ephesians",
|
|
440
|
-
"Philippians",
|
|
441
|
-
"Colossians",
|
|
442
|
-
"Thessalonians",
|
|
443
|
-
"Timothy",
|
|
444
|
-
"Titus",
|
|
445
|
-
"Philemon",
|
|
446
|
-
"Hebrews",
|
|
447
|
-
"James",
|
|
448
|
-
"Peter",
|
|
449
|
-
"John",
|
|
450
|
-
"Revelation",
|
|
451
|
-
"Re",
|
|
452
|
-
"Ap",
|
|
453
|
-
"Jd.",
|
|
454
|
-
"Heb.",
|
|
455
|
-
]
|
|
298
|
+
const books = [...Object.keys(this.abbrevations), ...this.bible.new, ...this.bible.old]
|
|
456
299
|
|
|
457
|
-
const preStrings = ["III", "II", "I", "1st", "2nd", "3rd", "First", "Second", "Third", "1", "2", "3"]
|
|
458
|
-
const preStringed = [
|
|
459
|
-
"Sam",
|
|
460
|
-
"Samuel",
|
|
461
|
-
"Kings",
|
|
462
|
-
"Kgs",
|
|
463
|
-
"Kin",
|
|
464
|
-
"Chron",
|
|
465
|
-
"Chronicles",
|
|
466
|
-
"Corinthians",
|
|
467
|
-
"Co",
|
|
468
|
-
"Cor",
|
|
469
|
-
"Thessalonians",
|
|
470
|
-
"Th",
|
|
471
|
-
"Thes",
|
|
472
|
-
"Thess",
|
|
473
|
-
"Timothy",
|
|
474
|
-
"Ti",
|
|
475
|
-
"Tim",
|
|
476
|
-
"Peter",
|
|
477
|
-
"Pe",
|
|
478
|
-
"Pet",
|
|
479
|
-
"Pt",
|
|
480
|
-
"John",
|
|
481
|
-
"Jn",
|
|
482
|
-
"Jhn",
|
|
483
|
-
]
|
|
484
300
|
let newText = ""
|
|
485
301
|
|
|
486
302
|
//add the prestringed versions e.g. 1 Peter
|
|
487
|
-
for (let b = 0; b < preStringed.length; b++) {
|
|
488
|
-
for (let pre = 0; pre < preStrings.length; pre++) {
|
|
489
|
-
books.push(preStrings[pre] + " " + preStringed[b])
|
|
303
|
+
for (let b = 0; b < this.preStringed.length; b++) {
|
|
304
|
+
for (let pre = 0; pre < this.preStrings.length; pre++) {
|
|
305
|
+
books.push(this.preStrings[pre] + " " + this.preStringed[b])
|
|
490
306
|
}
|
|
491
307
|
}
|
|
492
308
|
// add the book name with . at the end as this seems to be added sometimes, at least to the shortened forms
|
|
@@ -531,30 +347,67 @@ class CodexParser {
|
|
|
531
347
|
newText += "<span class='passage'>" + booksAt[b][0]
|
|
532
348
|
let passage = booksAt[b][0]
|
|
533
349
|
chNoInText += booksAt[b][0].length //skip the 'fill-in characters
|
|
350
|
+
let abbr
|
|
351
|
+
let index = []
|
|
534
352
|
for (let i = 0; i < 100; i++) {
|
|
535
353
|
chNoInText++
|
|
536
|
-
|
|
354
|
+
let nextCh = text.charAt(chNoInText)
|
|
355
|
+
const testStr = text.substring(chNoInText - passage.length, chNoInText + 5).toLowerCase()
|
|
356
|
+
if (testStr.includes("lxx")) abbr = "lxx"
|
|
357
|
+
if (testStr.includes("na")) abbr = "na"
|
|
358
|
+
if (testStr.includes("ubs")) abbr = "ubs"
|
|
359
|
+
if (testStr.includes("mt")) abbr = "mt"
|
|
360
|
+
if (testStr.includes("bhs")) abbr = "bhs"
|
|
361
|
+
if (testStr.includes("lxx")) abbr = "lxx"
|
|
362
|
+
if (testStr.includes("na")) abbr = "na"
|
|
363
|
+
if (testStr.includes("ubs")) abbr = "ubs"
|
|
364
|
+
if (testStr.includes("mt")) abbr = "mt"
|
|
365
|
+
if (testStr.includes("bhs")) abbr = "bhs"
|
|
537
366
|
//test whether are at the end of the chapter(s) and verse(s)
|
|
538
|
-
if (nextCh.match(/^[a-z]+$/) && nextCh !== "f" && nextCh !== "ff") break
|
|
367
|
+
if (nextCh.match(/^[a-z]+$/) && nextCh !== "f" && nextCh !== "ff" && nextCh !== "a") break
|
|
539
368
|
if (nextCh.match(/^[A-Z]+$/)) break
|
|
540
369
|
newText += text.charAt(chNoInText - 1)
|
|
541
370
|
passage += text.charAt(chNoInText - 1)
|
|
371
|
+
index.push(chNoInText - 1)
|
|
542
372
|
}
|
|
543
|
-
|
|
373
|
+
|
|
374
|
+
index = [index[0], index[index.length - 1]]
|
|
375
|
+
console.log(index)
|
|
376
|
+
this.found.push(passage.trim() + (abbr ? " " + abbr.toUpperCase() : ""))
|
|
544
377
|
newText += "</span> "
|
|
545
378
|
}
|
|
546
|
-
|
|
379
|
+
this.text = newText
|
|
547
380
|
return this
|
|
548
381
|
}
|
|
549
382
|
|
|
383
|
+
getText() {
|
|
384
|
+
return this.text
|
|
385
|
+
}
|
|
386
|
+
|
|
550
387
|
enhance() {
|
|
551
388
|
if (this.found.length > 0) {
|
|
552
389
|
for (let i = 0; i < this.found.length; i++) {
|
|
390
|
+
const found = this.found[i]
|
|
391
|
+
const book = this.bookify(this.found[i].match(this.bookRegex)[0])
|
|
392
|
+
const passageWithoutBook = found.replace(book, "")
|
|
393
|
+
let chapter, verse
|
|
394
|
+
if (/[:\.]/.test(passageWithoutBook)) {
|
|
395
|
+
chapter = parseInt(passageWithoutBook.split(":").shift().trim(), 10)
|
|
396
|
+
verse = parseInt(passageWithoutBook.split(":").pop().trim(), 10)
|
|
397
|
+
} else {
|
|
398
|
+
if (/\d+/gim.test(passageWithoutBook)) {
|
|
399
|
+
chapter = parseInt(passageWithoutBook.trim())
|
|
400
|
+
verse = null
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
let type = "verseRange"
|
|
405
|
+
|
|
553
406
|
const passage = {
|
|
554
407
|
original: this.found[i],
|
|
555
408
|
book: this.bookify(this.found[i].match(this.bookRegex)[0]),
|
|
556
409
|
chapter: this.found[i].match(this.chapterRegex),
|
|
557
|
-
verse: this.found[i].match(
|
|
410
|
+
verse: this.found[i].match(/(?<=[.:])(\d+.+)/)[0],
|
|
558
411
|
}
|
|
559
412
|
this.passages.push(passage)
|
|
560
413
|
}
|
package/src/functions.js
ADDED
|
@@ -12,5 +12,5 @@ parser.options({
|
|
|
12
12
|
single_chapter_1_strategy: "verse",
|
|
13
13
|
sequence_combination_strategy: "combine",
|
|
14
14
|
})
|
|
15
|
-
const result = parser.parse("
|
|
15
|
+
const result = parser.parse("Jude 5-7,11 Numbers 14:29-30 Genesis 19:24-25 Genesis 4:3-8 Numbers 31:16 Numbers 16:1-50")
|
|
16
16
|
dump(result.getPassages())
|
|
@@ -4,7 +4,7 @@ const util = require("util")
|
|
|
4
4
|
const dump = (item) => {
|
|
5
5
|
console.log(util.inspect(item, { depth: null, colors: true }))
|
|
6
6
|
}
|
|
7
|
-
const text = "
|
|
7
|
+
const text = "John 12:38 John 1:29,34 Isaiah 53:1 Isaiah 6:10 Isaiah 6:1 Isaiah 52:13 Isaiah 6:3 LXX Isaiah 52:13 LXX Isaiah 6:7 Isaiah 53:12 Isaiah 52:13 - 53:12"
|
|
8
8
|
|
|
9
9
|
const parser = new bcv_parser({
|
|
10
10
|
invalid_sequence_strategy: "include",
|
package/tests/find.js
CHANGED
|
@@ -2,6 +2,7 @@ const CodexParser = require("../src/CodexParser.js")
|
|
|
2
2
|
|
|
3
3
|
const parser = new CodexParser()
|
|
4
4
|
|
|
5
|
-
parser.find('
|
|
5
|
+
parser.find('Psalm 2:2-13; 3:2-4 30:5 LXX').enhance()
|
|
6
6
|
|
|
7
|
-
console.log(parser.getPassages())
|
|
7
|
+
console.log(parser.getPassages())
|
|
8
|
+
console.log(parser.getText())
|
package/tests/single.js
ADDED
|
File without changes
|