codexparser 0.1.46 → 0.1.48

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 +9 -107
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codexparser",
3
- "version": "0.1.46",
3
+ "version": "0.1.48",
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": {
@@ -302,7 +302,7 @@ class CodexParser {
302
302
  ? part.split(separator)
303
303
  : [parsedPassage.chapter, part]
304
304
 
305
- if (separator !== ":") {
305
+ if (separator.trim() !== ":" && !parsedPassage.chapter) {
306
306
  if (singleChapterBook) {
307
307
  parsedPassage.chapter = 1
308
308
  parsedPassage.verses.push(versePart) // Add single verse to array
@@ -438,6 +438,7 @@ class CodexParser {
438
438
  */
439
439
  populate(parsedPassage) {
440
440
  const passages = []
441
+
441
442
  const { book, chapter, verses, type, to } = parsedPassage
442
443
  const version = parsedPassage.version ? parsedPassage.version.abbreviation : "eng"
443
444
  this._setVersion(book, chapter, version) // Set version data if needed
@@ -451,11 +452,10 @@ class CodexParser {
451
452
  }
452
453
  } else if (type === "comma_separated_verses") {
453
454
  // Handle explicitly mentioned verses (e.g., 3:1,3,6)
454
- if (this.chapterVerses[book] && this.chapterVerses[book][chapter]) {
455
- verses.forEach((verse) => {
456
- passages.push({ book, chapter: Number(chapter), verse: Number(verse) })
457
- })
458
- }
455
+
456
+ verses.forEach((verse) => {
457
+ passages.push({ book, chapter: Number(chapter), verse: Number(verse) })
458
+ })
459
459
  } else if (type === "chapter_range") {
460
460
  // Handle ranges of chapters (e.g., 3-5)
461
461
  for (let currentChapter = chapter; currentChapter <= to.chapter; currentChapter++) {
@@ -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
  }
@@ -826,7 +726,9 @@ class CodexParser {
826
726
  cv: chapterString,
827
727
  hash: `${combined.book.toLowerCase()}_${chapterString.replace(/:/g, ".").replace(/,/g, ".")}`,
828
728
  }
829
-
729
+ if (combined.to === null) {
730
+ delete combined.to
731
+ }
830
732
  return combined
831
733
  }
832
734