codexparser 0.1.46 → 0.1.47
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 +0 -100
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codexparser",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.47",
|
|
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
|
@@ -636,106 +636,6 @@ class CodexParser {
|
|
|
636
636
|
* @return {object} The combined passage object.
|
|
637
637
|
*/
|
|
638
638
|
combine(passages) {
|
|
639
|
-
if (!passages || passages.length === 0) {
|
|
640
|
-
throw new Error("No passages provided to combine.")
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
// Ensure all passages are from the same book
|
|
644
|
-
const uniqueBooks = [...new Set(passages.map((p) => p.book))]
|
|
645
|
-
if (uniqueBooks.length > 1) {
|
|
646
|
-
throw new Error("Passages must be from the same book to combine.")
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
// Initialize combined passage object
|
|
650
|
-
const combined = {
|
|
651
|
-
...passages[0],
|
|
652
|
-
verses: [],
|
|
653
|
-
passages: [],
|
|
654
|
-
to: null,
|
|
655
|
-
type: null,
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
const chapterVerses = {}
|
|
659
|
-
let firstChapter = null
|
|
660
|
-
let lastChapter = null
|
|
661
|
-
|
|
662
|
-
// Collect all verses grouped by chapter
|
|
663
|
-
passages.forEach((passage) => {
|
|
664
|
-
passage.passages.forEach((p) => {
|
|
665
|
-
if (!chapterVerses[p.chapter]) {
|
|
666
|
-
chapterVerses[p.chapter] = new Set()
|
|
667
|
-
}
|
|
668
|
-
chapterVerses[p.chapter].add(p.verse)
|
|
669
|
-
combined.passages.push(p) // Add individual passage
|
|
670
|
-
})
|
|
671
|
-
|
|
672
|
-
// Track first and last chapters
|
|
673
|
-
const chapters = passage.passages.map((p) => p.chapter)
|
|
674
|
-
if (!firstChapter || Math.min(...chapters) < firstChapter) {
|
|
675
|
-
firstChapter = Math.min(...chapters)
|
|
676
|
-
}
|
|
677
|
-
if (!lastChapter || Math.max(...chapters) > lastChapter) {
|
|
678
|
-
lastChapter = Math.max(...chapters)
|
|
679
|
-
}
|
|
680
|
-
})
|
|
681
|
-
|
|
682
|
-
// Ensure unique and sorted passages
|
|
683
|
-
combined.passages = Array.from(new Set(combined.passages.map(JSON.stringify))).map(JSON.parse)
|
|
684
|
-
|
|
685
|
-
// Process chapter and verse data
|
|
686
|
-
const sortedChapters = Object.keys(chapterVerses)
|
|
687
|
-
.map(Number)
|
|
688
|
-
.sort((a, b) => a - b)
|
|
689
|
-
|
|
690
|
-
const originalParts = []
|
|
691
|
-
sortedChapters.forEach((chapter, index) => {
|
|
692
|
-
const verses = Array.from(chapterVerses[chapter]).sort((a, b) => a - b)
|
|
693
|
-
if (chapter === firstChapter) {
|
|
694
|
-
combined.verses = verses // First chapter's verses
|
|
695
|
-
}
|
|
696
|
-
if (chapter === lastChapter) {
|
|
697
|
-
combined.to = {
|
|
698
|
-
book: combined.book,
|
|
699
|
-
chapter,
|
|
700
|
-
verses,
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
originalParts.push(`${chapter}:${verses.join(",")}`)
|
|
704
|
-
})
|
|
705
|
-
|
|
706
|
-
// Ensure `to` is properly set for multi-chapter ranges
|
|
707
|
-
if (firstChapter !== lastChapter) {
|
|
708
|
-
const lastChapterVerses = Array.from(chapterVerses[lastChapter]).sort((a, b) => a - b)
|
|
709
|
-
combined.to = {
|
|
710
|
-
book: combined.book,
|
|
711
|
-
chapter: lastChapter,
|
|
712
|
-
verses: lastChapterVerses,
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
// Determine the passage type
|
|
717
|
-
if (firstChapter !== lastChapter) {
|
|
718
|
-
combined.type = "multi_chapter_verse_range"
|
|
719
|
-
} else if (combined.verses.length > 1) {
|
|
720
|
-
combined.type = "chapter_verse_range"
|
|
721
|
-
} else {
|
|
722
|
-
combined.type = "chapter_verse"
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
// Build the `original` field
|
|
726
|
-
combined.original = `${combined.book} ${originalParts.join("-")}`
|
|
727
|
-
|
|
728
|
-
return this.parse(combined.original).getPassages().first()
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
/**
|
|
732
|
-
* Combine multiple passages into one. The method checks for duplicates, merges overlapping or adjacent ranges,
|
|
733
|
-
* and builds the original and scripture properties.
|
|
734
|
-
*
|
|
735
|
-
* @param {array} passages - An array of passage objects to combine.
|
|
736
|
-
* @return {object} The combined passage object.
|
|
737
|
-
*/
|
|
738
|
-
join(passages) {
|
|
739
639
|
if (!passages || passages.length === 0) {
|
|
740
640
|
throw new Error("No passages provided to join.")
|
|
741
641
|
}
|