codexparser 0.1.33 → 0.1.35
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 +83 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codexparser",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.35",
|
|
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
|
@@ -46,6 +46,7 @@ class CodexParser {
|
|
|
46
46
|
]
|
|
47
47
|
this.chapterVerses = chapter_verses
|
|
48
48
|
this.error = false
|
|
49
|
+
this.version = "eng"
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
/**
|
|
@@ -227,10 +228,21 @@ class CodexParser {
|
|
|
227
228
|
return this // Return this instance for method chaining
|
|
228
229
|
}
|
|
229
230
|
|
|
231
|
+
//TODO: set the version and adjust the versifications
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Parses a given reference and returns an object with the parsed passage,
|
|
235
|
+
* including book, chapter, verse, type, testament, index, and version.
|
|
236
|
+
*
|
|
237
|
+
* @param {string} reference - The reference to parse.
|
|
238
|
+
* @returns {object} An object with the parsed passage.
|
|
239
|
+
*/
|
|
230
240
|
parse(reference) {
|
|
231
|
-
|
|
241
|
+
// Call scan to populate this.found
|
|
242
|
+
this.scan(reference)
|
|
232
243
|
|
|
233
244
|
this.passages = this.found.map((passage) => {
|
|
245
|
+
// Clean up spaces and remove any dots from the reference
|
|
234
246
|
passage.reference =
|
|
235
247
|
passage.reference.match(/[:]/g)?.length > 1 ? passage.reference.replace(/[:]/, "") : passage.reference
|
|
236
248
|
const book = this.bookify(passage.book)
|
|
@@ -275,7 +287,6 @@ class CodexParser {
|
|
|
275
287
|
this.chapterVerses[book][startChapter].indexOf(Number(startVerse))
|
|
276
288
|
)
|
|
277
289
|
}
|
|
278
|
-
|
|
279
290
|
// Handle same-chapter ranges (e.g., "27:27-29") and multi-chapter ranges (e.g., "Ex 2:1-3:4")
|
|
280
291
|
if (end.includes(separator)) {
|
|
281
292
|
let [endChapter, endVerse] = end.split(separator)
|
|
@@ -319,7 +330,6 @@ class CodexParser {
|
|
|
319
330
|
}
|
|
320
331
|
} else {
|
|
321
332
|
// Handle individual chapter:verse references (e.g., "27:27")
|
|
322
|
-
|
|
323
333
|
let [chapterPart, versePart] = part.includes(separator)
|
|
324
334
|
? part.split(separator)
|
|
325
335
|
: [parsedPassage.chapter, part]
|
|
@@ -335,7 +345,6 @@ class CodexParser {
|
|
|
335
345
|
// Need to check if chapterPart is undefined
|
|
336
346
|
// If it's undefined, then versePart actually is the chapter and we need to populate the
|
|
337
347
|
// verses from this.chapterVerses
|
|
338
|
-
|
|
339
348
|
if (chapterPart) {
|
|
340
349
|
parsedPassage.chapter = Number(chapterPart)
|
|
341
350
|
parsedPassage.verses.push(versePart) // Add single verse to array
|
|
@@ -344,6 +353,8 @@ class CodexParser {
|
|
|
344
353
|
if (!this.chapterVerses[book][parsedPassage.chapter]) {
|
|
345
354
|
parsedPassage.valid = this._isValid(parsedPassage, passage.reference)
|
|
346
355
|
} else {
|
|
356
|
+
// Need to set the version of the passage here, i.e. LXX, MT, English
|
|
357
|
+
this._setVersion(parsedPassage)
|
|
347
358
|
parsedPassage.verses = [
|
|
348
359
|
this.chapterVerses[book][parsedPassage.chapter][0] +
|
|
349
360
|
"-" +
|
|
@@ -368,6 +379,30 @@ class CodexParser {
|
|
|
368
379
|
return this // Return this instance
|
|
369
380
|
}
|
|
370
381
|
|
|
382
|
+
_searchVersificationDifferences(passage) {
|
|
383
|
+
const { book, chapter, version } = passage
|
|
384
|
+
|
|
385
|
+
// Loop through each key-value pair in the dictionary
|
|
386
|
+
for (const [key, value] of Object.entries(this.versificationDifferences[book])) {
|
|
387
|
+
// Check if the key starts with the desired chapter
|
|
388
|
+
if (value[version.abbreviation].startsWith(`${chapter}:`)) {
|
|
389
|
+
// Ensure the version exists in the value object
|
|
390
|
+
if (value[version.abbreviation]) {
|
|
391
|
+
// Extract the verse number from the value
|
|
392
|
+
const verse = value[version.abbreviation].split(":")[1]
|
|
393
|
+
this.chapterVerses[book][chapter].push(Number(verse))
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
this.chapterVerses[book][chapter] = Array.from(this.chapterVerses[book][chapter])
|
|
398
|
+
return this.chapterVerses // Return the array of verses
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
_setVersion(passage) {
|
|
402
|
+
this.version = passage.version.abbreviation
|
|
403
|
+
this._searchVersificationDifferences(passage)
|
|
404
|
+
}
|
|
405
|
+
|
|
371
406
|
versification() {
|
|
372
407
|
this.passages.forEach((passage) => {
|
|
373
408
|
const hasVersification = this.versificationDifferences[passage.book]
|
|
@@ -416,9 +451,10 @@ class CodexParser {
|
|
|
416
451
|
*/
|
|
417
452
|
populate(parsedPassage) {
|
|
418
453
|
const passages = []
|
|
419
|
-
|
|
420
454
|
// Helper function to process a parsed passage's verses
|
|
421
|
-
const processVerses = (
|
|
455
|
+
const processVerses = (passage) => {
|
|
456
|
+
const { book, chapter, verses } = passage
|
|
457
|
+
|
|
422
458
|
if (!verses) {
|
|
423
459
|
return
|
|
424
460
|
}
|
|
@@ -435,11 +471,11 @@ class CodexParser {
|
|
|
435
471
|
}
|
|
436
472
|
|
|
437
473
|
// Process main passage
|
|
438
|
-
processVerses(parsedPassage
|
|
474
|
+
processVerses(parsedPassage)
|
|
439
475
|
|
|
440
476
|
// Process 'to' object if it exists (for cross-chapter ranges)
|
|
441
477
|
if (parsedPassage.to) {
|
|
442
|
-
processVerses(parsedPassage.to
|
|
478
|
+
processVerses(parsedPassage.to)
|
|
443
479
|
}
|
|
444
480
|
|
|
445
481
|
return passages
|
|
@@ -703,6 +739,45 @@ class CodexParser {
|
|
|
703
739
|
return merged
|
|
704
740
|
}
|
|
705
741
|
|
|
742
|
+
getToc(version = "ESV") {
|
|
743
|
+
// Initialize the table of contents (toc)
|
|
744
|
+
const toc = {}
|
|
745
|
+
|
|
746
|
+
// Add Old Testament books and their chapters/verses to toc
|
|
747
|
+
this.bible.old.forEach((book) => {
|
|
748
|
+
if (this.chapterVerses[book]) {
|
|
749
|
+
toc[book] = this.chapterVerses[book]
|
|
750
|
+
}
|
|
751
|
+
})
|
|
752
|
+
|
|
753
|
+
// Add New Testament books and their chapters/verses to toc
|
|
754
|
+
this.bible.new.forEach((book) => {
|
|
755
|
+
if (this.chapterVerses[book]) {
|
|
756
|
+
toc[book] = this.chapterVerses[book]
|
|
757
|
+
}
|
|
758
|
+
})
|
|
759
|
+
|
|
760
|
+
// Merge in single-chapter books if not already in toc
|
|
761
|
+
this.singleChapterBook.forEach((item) => {
|
|
762
|
+
Object.keys(item).forEach((book) => {
|
|
763
|
+
if (!toc[book]) {
|
|
764
|
+
toc[book] = item[book]
|
|
765
|
+
}
|
|
766
|
+
})
|
|
767
|
+
})
|
|
768
|
+
|
|
769
|
+
// Sort the keys of toc by canonical order
|
|
770
|
+
const orderedToc = {}
|
|
771
|
+
const canonicalOrder = [...this.bible.old, ...this.bible.new]
|
|
772
|
+
canonicalOrder.forEach((book) => {
|
|
773
|
+
if (toc[book]) {
|
|
774
|
+
orderedToc[book] = toc[book]
|
|
775
|
+
}
|
|
776
|
+
})
|
|
777
|
+
|
|
778
|
+
return orderedToc
|
|
779
|
+
}
|
|
780
|
+
|
|
706
781
|
_isValid(passage, reference) {
|
|
707
782
|
const singleChapterBook = this.singleChapterBook.find((bible) => bible[passage.book])
|
|
708
783
|
if (!passage.verses) {
|