codexparser 0.1.10 → 0.1.13

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 +18 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codexparser",
3
- "version": "0.1.10",
3
+ "version": "0.1.13",
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": {
@@ -137,7 +137,6 @@ class CodexParser {
137
137
  // Look ahead to check if a number or space + number follows the abbreviation
138
138
  const afterAbbreviation = lowerCaseText.substring(i + abbreviationWithDot.length).trim()
139
139
  if (/^\d+/.test(afterAbbreviation)) {
140
- // Check if there is a number (chapter/verse)
141
140
  foundBook = abbreviations[k] // Store the abbreviation without the dot
142
141
  foundIndex = i // Record the index where the abbreviation is found
143
142
  matchedLength = abbreviationWithDot.length // Update the length of the match to include the dot
@@ -152,7 +151,6 @@ class CodexParser {
152
151
  // Look ahead to check if a number or space + number follows the abbreviation
153
152
  const afterAbbreviation = lowerCaseText.substring(i + abbreviation.length).trim()
154
153
  if (/^\d+/.test(afterAbbreviation)) {
155
- // Check if there is a number (chapter/verse)
156
154
  if (abbreviation.length > matchedLength) {
157
155
  foundBook = abbreviations[k] // Store the abbreviation without the dot
158
156
  foundIndex = i // Record the index where the abbreviation is found
@@ -170,6 +168,11 @@ class CodexParser {
170
168
  let chapterVerse = ""
171
169
  const references = []
172
170
 
171
+ // Function to decide if we should split the reference (based on finding a colon with space or semicolon)
172
+ const shouldSplitReference = (nextChar) => {
173
+ return nextChar === ":" && text[i - 1] === " " // Split if a space is found with a colon
174
+ }
175
+
173
176
  // Loop to find all chapter and verse references in the current book
174
177
  while (i < text.length && isValidChapterVerseChar(text[i])) {
175
178
  // Look ahead to see if the next characters form a new Bible book
@@ -177,8 +180,8 @@ class CodexParser {
177
180
  break // Stop adding to chapterVerse if a new Bible book is found
178
181
  }
179
182
 
180
- // If we hit a semicolon, it means a new reference starts
181
- if (text[i] === ";" || text[i] === " ") {
183
+ // If we hit a semicolon or space with a new reference, process the current reference
184
+ if (text[i] === ";" || shouldSplitReference(text[i + 1])) {
182
185
  const formattedReference = chapterVerse
183
186
  .trim()
184
187
  .replace(/\./g, ":")
@@ -479,6 +482,17 @@ class CodexParser {
479
482
  },
480
483
  }
481
484
  }
485
+ if (!this.chapterVerses[passage.book][passage.chapter]) {
486
+ return {
487
+ error: true,
488
+ code: 102,
489
+ message: {
490
+ chapter_exists: false,
491
+ content: `Chapter ${passage.chapter} does not exist in ${passage.book}`,
492
+ },
493
+ }
494
+ }
495
+
482
496
  return true
483
497
  }
484
498
  _handleVersion(version) {