codexparser 0.1.45 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/CodexParser.js +15 -103
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codexparser",
3
- "version": "0.1.45",
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": {
@@ -297,13 +297,25 @@ class CodexParser {
297
297
  }
298
298
  } else {
299
299
  // Handle individual chapter:verse references (e.g., "9:5" in "8:22-9:1,5")
300
+
300
301
  let [chapterPart, versePart] = part.includes(separator)
301
302
  ? part.split(separator)
302
303
  : [parsedPassage.chapter, part]
303
304
 
304
- if (singleChapterBook) {
305
- parsedPassage.chapter = 1
306
- parsedPassage.verses.push(versePart) // Add single verse to array
305
+ if (separator !== ":") {
306
+ if (singleChapterBook) {
307
+ parsedPassage.chapter = 1
308
+ parsedPassage.verses.push(versePart) // Add single verse to array
309
+ } else {
310
+ parsedPassage.chapter = Number(part)
311
+ parsedPassage.verses = [
312
+ `${this.chapterVerses[book][parsedPassage.chapter][0]}-${
313
+ this.chapterVerses[book][parsedPassage.chapter][
314
+ this.chapterVerses[book][parsedPassage.chapter].length - 1
315
+ ]
316
+ }`,
317
+ ]
318
+ }
307
319
  } else {
308
320
  if (chapterPart) {
309
321
  if (partIndex === parts.length - 1 && parsedPassage.to) {
@@ -624,106 +636,6 @@ class CodexParser {
624
636
  * @return {object} The combined passage object.
625
637
  */
626
638
  combine(passages) {
627
- if (!passages || passages.length === 0) {
628
- throw new Error("No passages provided to combine.")
629
- }
630
-
631
- // Ensure all passages are from the same book
632
- const uniqueBooks = [...new Set(passages.map((p) => p.book))]
633
- if (uniqueBooks.length > 1) {
634
- throw new Error("Passages must be from the same book to combine.")
635
- }
636
-
637
- // Initialize combined passage object
638
- const combined = {
639
- ...passages[0],
640
- verses: [],
641
- passages: [],
642
- to: null,
643
- type: null,
644
- }
645
-
646
- const chapterVerses = {}
647
- let firstChapter = null
648
- let lastChapter = null
649
-
650
- // Collect all verses grouped by chapter
651
- passages.forEach((passage) => {
652
- passage.passages.forEach((p) => {
653
- if (!chapterVerses[p.chapter]) {
654
- chapterVerses[p.chapter] = new Set()
655
- }
656
- chapterVerses[p.chapter].add(p.verse)
657
- combined.passages.push(p) // Add individual passage
658
- })
659
-
660
- // Track first and last chapters
661
- const chapters = passage.passages.map((p) => p.chapter)
662
- if (!firstChapter || Math.min(...chapters) < firstChapter) {
663
- firstChapter = Math.min(...chapters)
664
- }
665
- if (!lastChapter || Math.max(...chapters) > lastChapter) {
666
- lastChapter = Math.max(...chapters)
667
- }
668
- })
669
-
670
- // Ensure unique and sorted passages
671
- combined.passages = Array.from(new Set(combined.passages.map(JSON.stringify))).map(JSON.parse)
672
-
673
- // Process chapter and verse data
674
- const sortedChapters = Object.keys(chapterVerses)
675
- .map(Number)
676
- .sort((a, b) => a - b)
677
-
678
- const originalParts = []
679
- sortedChapters.forEach((chapter, index) => {
680
- const verses = Array.from(chapterVerses[chapter]).sort((a, b) => a - b)
681
- if (chapter === firstChapter) {
682
- combined.verses = verses // First chapter's verses
683
- }
684
- if (chapter === lastChapter) {
685
- combined.to = {
686
- book: combined.book,
687
- chapter,
688
- verses,
689
- }
690
- }
691
- originalParts.push(`${chapter}:${verses.join(",")}`)
692
- })
693
-
694
- // Ensure `to` is properly set for multi-chapter ranges
695
- if (firstChapter !== lastChapter) {
696
- const lastChapterVerses = Array.from(chapterVerses[lastChapter]).sort((a, b) => a - b)
697
- combined.to = {
698
- book: combined.book,
699
- chapter: lastChapter,
700
- verses: lastChapterVerses,
701
- }
702
- }
703
-
704
- // Determine the passage type
705
- if (firstChapter !== lastChapter) {
706
- combined.type = "multi_chapter_verse_range"
707
- } else if (combined.verses.length > 1) {
708
- combined.type = "chapter_verse_range"
709
- } else {
710
- combined.type = "chapter_verse"
711
- }
712
-
713
- // Build the `original` field
714
- combined.original = `${combined.book} ${originalParts.join("-")}`
715
-
716
- return this.parse(combined.original).getPassages().first()
717
- }
718
-
719
- /**
720
- * Combine multiple passages into one. The method checks for duplicates, merges overlapping or adjacent ranges,
721
- * and builds the original and scripture properties.
722
- *
723
- * @param {array} passages - An array of passage objects to combine.
724
- * @return {object} The combined passage object.
725
- */
726
- join(passages) {
727
639
  if (!passages || passages.length === 0) {
728
640
  throw new Error("No passages provided to join.")
729
641
  }