codexparser 0.5.3 → 0.5.4

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codexparser",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
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
  "files": [
@@ -71,7 +71,7 @@ class ReferenceParser {
71
71
  * @returns {Array} Array of parsed passage objects
72
72
  */
73
73
  parse(foundReferences, currentVersion = null) {
74
- return foundReferences.map((reference) => {
74
+ return this.#splitChapterSwitchingRefs(foundReferences).map((reference) => {
75
75
  const book = this.#normalizeBookName(reference.book)
76
76
  const testament = bible.old.includes(book) ? "old" : "new"
77
77
 
@@ -136,6 +136,64 @@ class ReferenceParser {
136
136
  })
137
137
  }
138
138
 
139
+ /**
140
+ * Splits a chapter-switching comma reference (e.g. "Daniel 8:16-18,9:21,23,10:8-10")
141
+ * into one reference per chapter group, so each is parsed by the single-chapter path.
142
+ * Single-chapter comma lists ("9:21,23") and bare-verse lists ("1:1,2,3") are left as-is.
143
+ * @private
144
+ */
145
+ #splitChapterSwitchingRefs(foundReferences) {
146
+ const out = []
147
+ for (const reference of foundReferences) {
148
+ const groups = this.#chapterGroups(reference.reference)
149
+ if (!groups) {
150
+ out.push(reference)
151
+ } else {
152
+ for (const groupRef of groups) {
153
+ // Force the general parse path; #parseReferenceParts re-derives the real type.
154
+ out.push({
155
+ ...reference,
156
+ reference: groupRef,
157
+ type: ReferenceParser.REFERENCE_TYPES.CHAPTER_VERSE_RANGE,
158
+ })
159
+ }
160
+ }
161
+ }
162
+ return out
163
+ }
164
+
165
+ /**
166
+ * Groups a post-book reference string by chapter. Returns one ref string per chapter group
167
+ * (e.g. ["8:16-18", "9:21,23", "10:8-10"]) only when the list actually switches chapters;
168
+ * returns null otherwise (no comma, single chapter, or a leading bare verse).
169
+ * @private
170
+ */
171
+ #chapterGroups(reference) {
172
+ if (typeof reference !== "string" || !reference.includes(",")) return null
173
+ const parts = reference
174
+ .split(",")
175
+ .map((p) => p.trim())
176
+ .filter(Boolean)
177
+ const groups = []
178
+ let current = null
179
+ for (const part of parts) {
180
+ const match = part.match(/^(\d+)\s*[:.]/)
181
+ if (match) {
182
+ const chapter = match[1]
183
+ if (!current || current.chapter !== chapter) {
184
+ current = { chapter, parts: [] }
185
+ groups.push(current)
186
+ }
187
+ current.parts.push(part)
188
+ } else {
189
+ if (!current) return null // leading bare verse — leave to normal parsing
190
+ current.parts.push(part)
191
+ }
192
+ }
193
+ if (groups.length < 2) return null
194
+ return groups.map((g) => g.parts.join(","))
195
+ }
196
+
139
197
  /**
140
198
  * Normalizes book names using abbreviations or full names
141
199
  * @private