codexparser 0.1.4 → 0.1.6
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 +53 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codexparser",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
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
|
|
@@ -128,20 +134,30 @@ class CodexParser {
|
|
|
128
134
|
isBoundaryOrNonAlphabetic(i - 1, lowerCaseText) &&
|
|
129
135
|
isBoundaryOrNonAlphabetic(i + abbreviationWithDot.length, lowerCaseText)
|
|
130
136
|
) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
137
|
+
// Look ahead to check if a number or space + number follows the abbreviation
|
|
138
|
+
const afterAbbreviation = lowerCaseText.substring(i + abbreviationWithDot.length).trim()
|
|
139
|
+
if (/^\d+/.test(afterAbbreviation)) {
|
|
140
|
+
// Check if there is a number (chapter/verse)
|
|
141
|
+
foundBook = abbreviations[k] // Store the abbreviation without the dot
|
|
142
|
+
foundIndex = i // Record the index where the abbreviation is found
|
|
143
|
+
matchedLength = abbreviationWithDot.length // Update the length of the match to include the dot
|
|
144
|
+
break // Exit once found
|
|
145
|
+
}
|
|
135
146
|
}
|
|
136
147
|
} else if (lowerCaseText.startsWith(abbreviation, i)) {
|
|
137
148
|
if (
|
|
138
149
|
isBoundaryOrNonAlphabetic(i - 1, lowerCaseText) &&
|
|
139
150
|
isBoundaryOrNonAlphabetic(i + abbreviation.length, lowerCaseText)
|
|
140
151
|
) {
|
|
141
|
-
if
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
152
|
+
// Look ahead to check if a number or space + number follows the abbreviation
|
|
153
|
+
const afterAbbreviation = lowerCaseText.substring(i + abbreviation.length).trim()
|
|
154
|
+
if (/^\d+/.test(afterAbbreviation)) {
|
|
155
|
+
// Check if there is a number (chapter/verse)
|
|
156
|
+
if (abbreviation.length > matchedLength) {
|
|
157
|
+
foundBook = abbreviations[k] // Store the abbreviation without the dot
|
|
158
|
+
foundIndex = i // Record the index where the abbreviation is found
|
|
159
|
+
matchedLength = abbreviation.length // Update the length of the match
|
|
160
|
+
}
|
|
145
161
|
}
|
|
146
162
|
}
|
|
147
163
|
}
|
|
@@ -170,17 +186,22 @@ class CodexParser {
|
|
|
170
186
|
// Replace any periods within the reference with colons for easier parsing
|
|
171
187
|
const formattedReference = chapterVerse.replace(/\./g, ":")
|
|
172
188
|
|
|
189
|
+
// Detect if a suffix (LXX or MT) exists after the chapter/verse
|
|
190
|
+
const suffix = detectSuffix(i)
|
|
191
|
+
|
|
173
192
|
if (formattedReference.length > 0) {
|
|
174
193
|
this.found.push({
|
|
175
194
|
book: foundBook,
|
|
176
|
-
reference: formattedReference, // Store the
|
|
195
|
+
reference: formattedReference, // Store only the chapter/verse
|
|
177
196
|
index: foundIndex,
|
|
197
|
+
version: suffix || null, // Store the version (LXX, MT) if found, otherwise null
|
|
178
198
|
})
|
|
179
199
|
} else {
|
|
180
200
|
this.found.push({
|
|
181
201
|
book: foundBook,
|
|
182
202
|
reference: null,
|
|
183
203
|
index: foundIndex,
|
|
204
|
+
version: suffix || null, // Store the version (LXX, MT) if found, otherwise null
|
|
184
205
|
})
|
|
185
206
|
}
|
|
186
207
|
} else {
|
|
@@ -196,7 +217,7 @@ class CodexParser {
|
|
|
196
217
|
|
|
197
218
|
this.passages = this.found.map((passage) => {
|
|
198
219
|
const book = this.bookify(passage.book)
|
|
199
|
-
|
|
220
|
+
dump(passage)
|
|
200
221
|
// Initialize the parsed passage object
|
|
201
222
|
const parsedPassage = {
|
|
202
223
|
original: passage.book + " " + passage.reference,
|
|
@@ -207,6 +228,7 @@ class CodexParser {
|
|
|
207
228
|
type: null, // Set type based on reference
|
|
208
229
|
testament: this.bible.old.find((bible) => bible === book) ? "old" : "new",
|
|
209
230
|
index: passage.index,
|
|
231
|
+
version: this._handleVersion(passage.version),
|
|
210
232
|
}
|
|
211
233
|
|
|
212
234
|
// Split reference by commas to handle multiple ranges or verses (e.g., "Ge 27:27-29,39-41")
|
|
@@ -445,6 +467,27 @@ class CodexParser {
|
|
|
445
467
|
},
|
|
446
468
|
}
|
|
447
469
|
}
|
|
470
|
+
return true
|
|
471
|
+
}
|
|
472
|
+
_handleVersion(version) {
|
|
473
|
+
if (!version) {
|
|
474
|
+
return null
|
|
475
|
+
}
|
|
476
|
+
if (version.toLowerCase() === "lxx") {
|
|
477
|
+
return {
|
|
478
|
+
name: "Septuagint",
|
|
479
|
+
value: "LXX",
|
|
480
|
+
abbreviation: "lxx",
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
if (version.toLowerCase() === "mt") {
|
|
485
|
+
return {
|
|
486
|
+
name: "Masoretic Text",
|
|
487
|
+
value: "MT",
|
|
488
|
+
abbreviation: "mt",
|
|
489
|
+
}
|
|
490
|
+
}
|
|
448
491
|
}
|
|
449
492
|
}
|
|
450
493
|
|