codexparser 0.1.27 → 0.1.28
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 +39 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codexparser",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.28",
|
|
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
|
}
|