codexparser 0.1.34 → 0.1.36

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 +61 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codexparser",
3
- "version": "0.1.34",
3
+ "version": "0.1.36",
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": {
@@ -46,6 +46,7 @@ class CodexParser {
46
46
  ]
47
47
  this.chapterVerses = chapter_verses
48
48
  this.error = false
49
+ this.version = null
49
50
  }
50
51
 
51
52
  /**
@@ -227,15 +228,36 @@ class CodexParser {
227
228
  return this // Return this instance for method chaining
228
229
  }
229
230
 
231
+ bibleVersion(version) {
232
+ const lowerVersion = version.toLowerCase()
233
+ this.version =
234
+ lowerVersion === "lxx" || lowerVersion === "eng" || lowerVersion === "bhs" || lowerVersion === "mt"
235
+ ? lowerVersion
236
+ : null
237
+ return this
238
+ }
239
+
240
+ //TODO: set the version and adjust the versifications
241
+
242
+ /**
243
+ * Parses a given reference and returns an object with the parsed passage,
244
+ * including book, chapter, verse, type, testament, index, and version.
245
+ *
246
+ * @param {string} reference - The reference to parse.
247
+ * @returns {object} An object with the parsed passage.
248
+ */
230
249
  parse(reference) {
231
- this.scan(reference) // Call scan to populate this.found
250
+ // Call scan to populate this.found
251
+ this.scan(reference)
232
252
 
233
253
  this.passages = this.found.map((passage) => {
254
+ // Clean up spaces and remove any dots from the reference
234
255
  passage.reference =
235
256
  passage.reference.match(/[:]/g)?.length > 1 ? passage.reference.replace(/[:]/, "") : passage.reference
236
257
  const book = this.bookify(passage.book)
237
258
  const testament = this.bible.old.find((bible) => bible === book) ? "old" : "new"
238
259
  // Initialize the parsed passage object
260
+
239
261
  const parsedPassage = {
240
262
  original: passage.book + " " + passage.reference,
241
263
  book: book,
@@ -275,7 +297,6 @@ class CodexParser {
275
297
  this.chapterVerses[book][startChapter].indexOf(Number(startVerse))
276
298
  )
277
299
  }
278
-
279
300
  // Handle same-chapter ranges (e.g., "27:27-29") and multi-chapter ranges (e.g., "Ex 2:1-3:4")
280
301
  if (end.includes(separator)) {
281
302
  let [endChapter, endVerse] = end.split(separator)
@@ -319,7 +340,6 @@ class CodexParser {
319
340
  }
320
341
  } else {
321
342
  // Handle individual chapter:verse references (e.g., "27:27")
322
-
323
343
  let [chapterPart, versePart] = part.includes(separator)
324
344
  ? part.split(separator)
325
345
  : [parsedPassage.chapter, part]
@@ -335,7 +355,6 @@ class CodexParser {
335
355
  // Need to check if chapterPart is undefined
336
356
  // If it's undefined, then versePart actually is the chapter and we need to populate the
337
357
  // verses from this.chapterVerses
338
-
339
358
  if (chapterPart) {
340
359
  parsedPassage.chapter = Number(chapterPart)
341
360
  parsedPassage.verses.push(versePart) // Add single verse to array
@@ -344,6 +363,8 @@ class CodexParser {
344
363
  if (!this.chapterVerses[book][parsedPassage.chapter]) {
345
364
  parsedPassage.valid = this._isValid(parsedPassage, passage.reference)
346
365
  } else {
366
+ // Need to set the version of the passage here, i.e. LXX, MT, English
367
+ this._setVersion(parsedPassage)
347
368
  parsedPassage.verses = [
348
369
  this.chapterVerses[book][parsedPassage.chapter][0] +
349
370
  "-" +
@@ -368,6 +389,33 @@ class CodexParser {
368
389
  return this // Return this instance
369
390
  }
370
391
 
392
+ _searchVersificationDifferences(passage) {
393
+ const { book, chapter, version } = passage
394
+
395
+ // Loop through each key-value pair in the dictionary
396
+ for (const [key, value] of Object.entries(this.versificationDifferences[book])) {
397
+ // Check if the key starts with the desired chapter
398
+ if (value[version.abbreviation].startsWith(`${chapter}:`)) {
399
+ // Ensure the version exists in the value object
400
+ if (value[version.abbreviation]) {
401
+ // Extract the verse number from the value
402
+ const verse = value[version.abbreviation].split(":")[1]
403
+ this.chapterVerses[book][chapter].push(Number(verse))
404
+ }
405
+ }
406
+ }
407
+ this.chapterVerses[book][chapter] = Array.from(this.chapterVerses[book][chapter])
408
+ return this.chapterVerses // Return the array of verses
409
+ }
410
+
411
+ _setVersion(passage) {
412
+ this.version = passage.version ? passage.version.abbreviation : "eng"
413
+
414
+ if (this.version !== "eng") {
415
+ this._searchVersificationDifferences(passage)
416
+ }
417
+ }
418
+
371
419
  versification() {
372
420
  this.passages.forEach((passage) => {
373
421
  const hasVersification = this.versificationDifferences[passage.book]
@@ -416,9 +464,10 @@ class CodexParser {
416
464
  */
417
465
  populate(parsedPassage) {
418
466
  const passages = []
419
-
420
467
  // Helper function to process a parsed passage's verses
421
- const processVerses = (chapter, verses, book) => {
468
+ const processVerses = (passage) => {
469
+ const { book, chapter, verses } = passage
470
+
422
471
  if (!verses) {
423
472
  return
424
473
  }
@@ -435,11 +484,11 @@ class CodexParser {
435
484
  }
436
485
 
437
486
  // Process main passage
438
- processVerses(parsedPassage.chapter, parsedPassage.verses, parsedPassage.book)
487
+ processVerses(parsedPassage)
439
488
 
440
489
  // Process 'to' object if it exists (for cross-chapter ranges)
441
490
  if (parsedPassage.to) {
442
- processVerses(parsedPassage.to.chapter, parsedPassage.to.verses, parsedPassage.to.book)
491
+ processVerses(parsedPassage.to)
443
492
  }
444
493
 
445
494
  return passages
@@ -780,8 +829,11 @@ class CodexParser {
780
829
  return true
781
830
  }
782
831
  _handleVersion(version, testament) {
832
+ if (this.version) {
833
+ version = this.version
834
+ }
783
835
  if (!version) {
784
- return null
836
+ version = "eng"
785
837
  }
786
838
  if (version.toLowerCase() === "lxx" && testament.toLowerCase() === "old") {
787
839
  return {