codexparser 0.1.3 → 0.1.5
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 +1 -1
- package/src/CodexParser.js +55 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codexparser",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
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": {
|
package/src/CodexParser.js
CHANGED
|
@@ -96,6 +96,12 @@ class CodexParser {
|
|
|
96
96
|
return false
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
// Function to detect suffixes like "LXX" or "MT"
|
|
100
|
+
const detectSuffix = (startIndex) => {
|
|
101
|
+
const suffixMatch = text.substring(startIndex).match(/\b(LXX|MT)\b/i)
|
|
102
|
+
return suffixMatch ? suffixMatch[0].toUpperCase() : null
|
|
103
|
+
}
|
|
104
|
+
|
|
99
105
|
// Loop through the text and check for full names and abbreviations
|
|
100
106
|
while (i < lowerCaseText.length) {
|
|
101
107
|
let foundBook = null
|
|
@@ -170,17 +176,25 @@ class CodexParser {
|
|
|
170
176
|
// Replace any periods within the reference with colons for easier parsing
|
|
171
177
|
const formattedReference = chapterVerse.replace(/\./g, ":")
|
|
172
178
|
|
|
179
|
+
// Detect if a suffix (LXX or MT) exists after the chapter/verse
|
|
180
|
+
const suffix = detectSuffix(i)
|
|
181
|
+
if (suffix) {
|
|
182
|
+
i += suffix.length // Move past the suffix
|
|
183
|
+
}
|
|
184
|
+
|
|
173
185
|
if (formattedReference.length > 0) {
|
|
174
186
|
this.found.push({
|
|
175
187
|
book: foundBook,
|
|
176
|
-
reference: formattedReference, // Store the
|
|
188
|
+
reference: formattedReference, // Store only the chapter/verse
|
|
177
189
|
index: foundIndex,
|
|
190
|
+
version: suffix || null, // Store the version (LXX, MT) if found, otherwise null
|
|
178
191
|
})
|
|
179
192
|
} else {
|
|
180
193
|
this.found.push({
|
|
181
194
|
book: foundBook,
|
|
182
195
|
reference: null,
|
|
183
196
|
index: foundIndex,
|
|
197
|
+
version: suffix || null, // Store the version (LXX, MT) if found, otherwise null
|
|
184
198
|
})
|
|
185
199
|
}
|
|
186
200
|
} else {
|
|
@@ -207,6 +221,7 @@ class CodexParser {
|
|
|
207
221
|
type: null, // Set type based on reference
|
|
208
222
|
testament: this.bible.old.find((bible) => bible === book) ? "old" : "new",
|
|
209
223
|
index: passage.index,
|
|
224
|
+
version: this._handleVersion(passage.version),
|
|
210
225
|
}
|
|
211
226
|
|
|
212
227
|
// Split reference by commas to handle multiple ranges or verses (e.g., "Ge 27:27-29,39-41")
|
|
@@ -310,6 +325,8 @@ class CodexParser {
|
|
|
310
325
|
parsedPassage.passages = this.populate(parsedPassage)
|
|
311
326
|
})
|
|
312
327
|
|
|
328
|
+
parsedPassage.valid = this._isValid(parsedPassage, passage.reference)
|
|
329
|
+
|
|
313
330
|
return parsedPassage
|
|
314
331
|
})
|
|
315
332
|
this.versification()
|
|
@@ -344,6 +361,9 @@ class CodexParser {
|
|
|
344
361
|
|
|
345
362
|
// Helper function to process a parsed passage's verses
|
|
346
363
|
const processVerses = (chapter, verses, book) => {
|
|
364
|
+
if (!verses) {
|
|
365
|
+
return
|
|
366
|
+
}
|
|
347
367
|
verses.forEach((verse) => {
|
|
348
368
|
if (isNaN(verse)) {
|
|
349
369
|
const [start, end] = verse.split("-").map(Number) // Handle ranges
|
|
@@ -428,6 +448,40 @@ class CodexParser {
|
|
|
428
448
|
hash,
|
|
429
449
|
}
|
|
430
450
|
}
|
|
451
|
+
|
|
452
|
+
_isValid(passage, reference) {
|
|
453
|
+
if (!passage.verses) {
|
|
454
|
+
return {
|
|
455
|
+
error: true,
|
|
456
|
+
code: 101,
|
|
457
|
+
message: {
|
|
458
|
+
chapter_exists: false,
|
|
459
|
+
content: "Possible invalid chapter: " + reference,
|
|
460
|
+
},
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return true
|
|
464
|
+
}
|
|
465
|
+
_handleVersion(version) {
|
|
466
|
+
if (!version) {
|
|
467
|
+
return null
|
|
468
|
+
}
|
|
469
|
+
if (version.toLowerCase() === "lxx") {
|
|
470
|
+
return {
|
|
471
|
+
name: "Septuagint",
|
|
472
|
+
value: "LXX",
|
|
473
|
+
abbreviation: "lxx",
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
if (version.toLowerCase() === "mt") {
|
|
478
|
+
return {
|
|
479
|
+
name: "Masoretic Text",
|
|
480
|
+
value: "MT",
|
|
481
|
+
abbreviation: "mt",
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
431
485
|
}
|
|
432
486
|
|
|
433
487
|
module.exports = CodexParser
|