codexparser 0.1.32 → 0.1.34

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 +49 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codexparser",
3
- "version": "0.1.32",
3
+ "version": "0.1.34",
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": {
@@ -231,6 +231,8 @@ class CodexParser {
231
231
  this.scan(reference) // Call scan to populate this.found
232
232
 
233
233
  this.passages = this.found.map((passage) => {
234
+ passage.reference =
235
+ passage.reference.match(/[:]/g)?.length > 1 ? passage.reference.replace(/[:]/, "") : passage.reference
234
236
  const book = this.bookify(passage.book)
235
237
  const testament = this.bible.old.find((bible) => bible === book) ? "old" : "new"
236
238
  // Initialize the parsed passage object
@@ -617,6 +619,14 @@ class CodexParser {
617
619
  })
618
620
  })
619
621
 
622
+ // Sort the newObject.passages array by chapter first, then by verse
623
+ newObject.passages.sort((a, b) => {
624
+ if (a.chapter !== b.chapter) {
625
+ return a.chapter - b.chapter // Sort by chapter
626
+ }
627
+ return a.verse - b.verse // Sort by verse within the same chapter
628
+ })
629
+
620
630
  // Prepare to build the final result
621
631
  const chapterStrings = []
622
632
  let firstChapter = null
@@ -693,6 +703,45 @@ class CodexParser {
693
703
  return merged
694
704
  }
695
705
 
706
+ getToc(version = "ESV") {
707
+ // Initialize the table of contents (toc)
708
+ const toc = {}
709
+
710
+ // Add Old Testament books and their chapters/verses to toc
711
+ this.bible.old.forEach((book) => {
712
+ if (this.chapterVerses[book]) {
713
+ toc[book] = this.chapterVerses[book]
714
+ }
715
+ })
716
+
717
+ // Add New Testament books and their chapters/verses to toc
718
+ this.bible.new.forEach((book) => {
719
+ if (this.chapterVerses[book]) {
720
+ toc[book] = this.chapterVerses[book]
721
+ }
722
+ })
723
+
724
+ // Merge in single-chapter books if not already in toc
725
+ this.singleChapterBook.forEach((item) => {
726
+ Object.keys(item).forEach((book) => {
727
+ if (!toc[book]) {
728
+ toc[book] = item[book]
729
+ }
730
+ })
731
+ })
732
+
733
+ // Sort the keys of toc by canonical order
734
+ const orderedToc = {}
735
+ const canonicalOrder = [...this.bible.old, ...this.bible.new]
736
+ canonicalOrder.forEach((book) => {
737
+ if (toc[book]) {
738
+ orderedToc[book] = toc[book]
739
+ }
740
+ })
741
+
742
+ return orderedToc
743
+ }
744
+
696
745
  _isValid(passage, reference) {
697
746
  const singleChapterBook = this.singleChapterBook.find((bible) => bible[passage.book])
698
747
  if (!passage.verses) {