codexparser 0.1.27 → 0.1.29
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 +44 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codexparser",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
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
|
@@ -486,21 +486,49 @@ class CodexParser {
|
|
|
486
486
|
* @return {object} The object with the human-readable name, chapter and verses and a hash.
|
|
487
487
|
*/
|
|
488
488
|
scripturize(passage) {
|
|
489
|
-
const { book, chapter,
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
489
|
+
const { book, chapter, passages } = passage
|
|
490
|
+
|
|
491
|
+
// Extract verses from the passages array
|
|
492
|
+
const verses = passages.map((p) => p.verse)
|
|
493
|
+
let formattedVerses = ""
|
|
494
|
+
|
|
495
|
+
if (verses.length === 1) {
|
|
496
|
+
// If there is only one verse
|
|
497
|
+
formattedVerses = verses[0].toString()
|
|
498
|
+
} else if (verses.length === 2 && verses[1] === verses[0] + 1) {
|
|
499
|
+
// If there are exactly two verses and they are consecutive, use a comma
|
|
500
|
+
formattedVerses = `${verses[0]},${verses[1]}`
|
|
501
|
+
} else {
|
|
502
|
+
// For more than two verses, or non-consecutive verses
|
|
503
|
+
let ranges = []
|
|
504
|
+
let tempRange = [verses[0]]
|
|
505
|
+
|
|
506
|
+
for (let i = 1; i < verses.length; i++) {
|
|
507
|
+
if (verses[i] === verses[i - 1] + 1) {
|
|
508
|
+
// If the verse is consecutive, add to tempRange
|
|
509
|
+
tempRange.push(verses[i])
|
|
510
|
+
} else {
|
|
511
|
+
// If not consecutive, finalize tempRange
|
|
512
|
+
ranges.push(tempRange)
|
|
513
|
+
tempRange = [verses[i]]
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
ranges.push(tempRange) // Push the last range
|
|
517
|
+
|
|
518
|
+
// Format ranges: convert consecutive numbers to ranges, non-consecutive remain separate
|
|
519
|
+
formattedVerses = ranges
|
|
520
|
+
.map((range) => (range.length > 1 ? `${range[0]}-${range[range.length - 1]}` : range[0]))
|
|
521
|
+
.join(",")
|
|
494
522
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
.trim()
|
|
523
|
+
|
|
524
|
+
// Format the final passage
|
|
525
|
+
const colon = formattedVerses ? ":" : ""
|
|
526
|
+
const full = `${book} ${chapter}${colon}${formattedVerses}`.trim()
|
|
500
527
|
const hash = full.toLowerCase().replace(/ /g, "_").replace(/:/g, ".").replace(/-/g, ".").replace(/,/g, ".")
|
|
528
|
+
|
|
501
529
|
return {
|
|
502
530
|
passage: full,
|
|
503
|
-
cv: chapter
|
|
531
|
+
cv: `${chapter}${colon}${formattedVerses}`,
|
|
504
532
|
hash,
|
|
505
533
|
}
|
|
506
534
|
}
|
|
@@ -514,10 +542,12 @@ class CodexParser {
|
|
|
514
542
|
* @return {object} The combined passage object.
|
|
515
543
|
*/
|
|
516
544
|
combine(passages) {
|
|
517
|
-
|
|
545
|
+
// Only check if passages are from the same book
|
|
546
|
+
const noDuplicates = [...new Set(passages.map((p) => p.book))]
|
|
518
547
|
if (noDuplicates.length > 1) {
|
|
519
|
-
throw new Error("Passages are not from the same book
|
|
548
|
+
throw new Error("Passages are not from the same book.")
|
|
520
549
|
}
|
|
550
|
+
|
|
521
551
|
const newPassages = []
|
|
522
552
|
passages.forEach((passageSet) => {
|
|
523
553
|
passageSet.passages.forEach((passage) => {
|
|
@@ -528,6 +558,7 @@ class CodexParser {
|
|
|
528
558
|
}
|
|
529
559
|
})
|
|
530
560
|
})
|
|
561
|
+
|
|
531
562
|
const noDuplicates2 = [...new Set(newPassages)]
|
|
532
563
|
const parsed = this.parse(noDuplicates2.join(" // ")).getPassages()
|
|
533
564
|
return this.join(parsed)
|