codexparser 0.1.69 → 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 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codexparser",
3
- "version": "0.1.69",
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(":")