codexparser 0.1.68 → 0.1.70

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 +29 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codexparser",
3
- "version": "0.1.68",
3
+ "version": "0.1.70",
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": {
@@ -52,6 +52,21 @@ class CodexParser {
52
52
  this.COMMA_SEPARATED = "comma_separated_verses"
53
53
  this.CHAPTER_RANGE = "chapter_range"
54
54
  this.MULTI_CHAPTER_RANGE = "multi_chapter_verse_range"
55
+ this.config = {
56
+ booksOnly: false,
57
+ }
58
+ }
59
+ /**
60
+ * Sets configuration options for the parser.
61
+ * @param {Object} config - Configuration options.
62
+ * @param {boolean} [config.booksOnly=false] - Whether to capture book names without references.
63
+ * @returns {CodexParser} The parser instance for method chaining.
64
+ */
65
+ options(config) {
66
+ this.config = {
67
+ booksOnly: config.booksOnly ?? false,
68
+ }
69
+ return this
55
70
  }
56
71
 
57
72
  /**
@@ -130,6 +145,15 @@ class CodexParser {
130
145
  }
131
146
 
132
147
  if (foundBook) {
148
+ // Check if book is followed by a number when booksOnly is false
149
+ const nextCharIndex = i + matchedLength
150
+ const isFollowedByNumber =
151
+ nextCharIndex < lowerCaseText.length && /\d/.test(lowerCaseText[nextCharIndex])
152
+ if (!this.config.booksOnly && !isFollowedByNumber && !hasOpeningParen) {
153
+ i++
154
+ continue
155
+ }
156
+
133
157
  i += matchedLength
134
158
  let chapterVerse = ""
135
159
  let hasColon = false
@@ -153,8 +177,8 @@ class CodexParser {
153
177
  i++
154
178
  }
155
179
 
156
- // Only proceed if valid reference
157
- if (hasColon && chapterVerse.trim().length > 0) {
180
+ // Only proceed if valid reference or booksOnly is true
181
+ if ((hasColon && chapterVerse.trim().length > 0) || this.config.booksOnly) {
158
182
  let endIndex = i
159
183
  let version = null
160
184
 
@@ -178,7 +202,9 @@ class CodexParser {
178
202
  // Determine type
179
203
  let type
180
204
  const ref = chapterVerse.trim()
181
- if (ref.includes(":")) {
205
+ if (this.config.booksOnly && !ref) {
206
+ type = "book_only"
207
+ } else if (ref.includes(":")) {
182
208
  if (ref.includes("-")) {
183
209
  const [start, end] = ref.split("-")
184
210
  const startParts = start.split(":")
@@ -217,7 +243,6 @@ class CodexParser {
217
243
  }
218
244
  }
219
245
 
220
- console.log("Found references:", JSON.stringify(this.found, null, 2)) // Debug
221
246
  return this
222
247
  }
223
248
 
@@ -1098,7 +1123,6 @@ class CodexParser {
1098
1123
  */
1099
1124
  replace(text, useAbbreviations = true) {
1100
1125
  if (!this.passages.length) {
1101
- console.log("No parsed passages to replace")
1102
1126
  return text
1103
1127
  }
1104
1128
 
@@ -1123,11 +1147,8 @@ class CodexParser {
1123
1147
  // Preserve parentheses if present in the match
1124
1148
  const hasParens = match[1] === "(" && match[2] === ")"
1125
1149
  const replacement = hasParens ? `(${newReference})` : newReference
1126
- console.log(`Replacing "${match[0]}" with "${replacement}" at [${startIndex}, ${endIndex}]`)
1127
1150
  result = result.slice(0, startIndex) + replacement + result.slice(endIndex)
1128
1151
  }
1129
- } else {
1130
- console.log(`No match found for originalText "${originalText}"`)
1131
1152
  }
1132
1153
  }
1133
1154