codexparser 0.1.34 → 0.1.35

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 +44 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codexparser",
3
- "version": "0.1.34",
3
+ "version": "0.1.35",
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 = "eng"
49
50
  }
50
51
 
51
52
  /**
@@ -227,10 +228,21 @@ class CodexParser {
227
228
  return this // Return this instance for method chaining
228
229
  }
229
230
 
231
+ //TODO: set the version and adjust the versifications
232
+
233
+ /**
234
+ * Parses a given reference and returns an object with the parsed passage,
235
+ * including book, chapter, verse, type, testament, index, and version.
236
+ *
237
+ * @param {string} reference - The reference to parse.
238
+ * @returns {object} An object with the parsed passage.
239
+ */
230
240
  parse(reference) {
231
- this.scan(reference) // Call scan to populate this.found
241
+ // Call scan to populate this.found
242
+ this.scan(reference)
232
243
 
233
244
  this.passages = this.found.map((passage) => {
245
+ // Clean up spaces and remove any dots from the reference
234
246
  passage.reference =
235
247
  passage.reference.match(/[:]/g)?.length > 1 ? passage.reference.replace(/[:]/, "") : passage.reference
236
248
  const book = this.bookify(passage.book)
@@ -275,7 +287,6 @@ class CodexParser {
275
287
  this.chapterVerses[book][startChapter].indexOf(Number(startVerse))
276
288
  )
277
289
  }
278
-
279
290
  // Handle same-chapter ranges (e.g., "27:27-29") and multi-chapter ranges (e.g., "Ex 2:1-3:4")
280
291
  if (end.includes(separator)) {
281
292
  let [endChapter, endVerse] = end.split(separator)
@@ -319,7 +330,6 @@ class CodexParser {
319
330
  }
320
331
  } else {
321
332
  // Handle individual chapter:verse references (e.g., "27:27")
322
-
323
333
  let [chapterPart, versePart] = part.includes(separator)
324
334
  ? part.split(separator)
325
335
  : [parsedPassage.chapter, part]
@@ -335,7 +345,6 @@ class CodexParser {
335
345
  // Need to check if chapterPart is undefined
336
346
  // If it's undefined, then versePart actually is the chapter and we need to populate the
337
347
  // verses from this.chapterVerses
338
-
339
348
  if (chapterPart) {
340
349
  parsedPassage.chapter = Number(chapterPart)
341
350
  parsedPassage.verses.push(versePart) // Add single verse to array
@@ -344,6 +353,8 @@ class CodexParser {
344
353
  if (!this.chapterVerses[book][parsedPassage.chapter]) {
345
354
  parsedPassage.valid = this._isValid(parsedPassage, passage.reference)
346
355
  } else {
356
+ // Need to set the version of the passage here, i.e. LXX, MT, English
357
+ this._setVersion(parsedPassage)
347
358
  parsedPassage.verses = [
348
359
  this.chapterVerses[book][parsedPassage.chapter][0] +
349
360
  "-" +
@@ -368,6 +379,30 @@ class CodexParser {
368
379
  return this // Return this instance
369
380
  }
370
381
 
382
+ _searchVersificationDifferences(passage) {
383
+ const { book, chapter, version } = passage
384
+
385
+ // Loop through each key-value pair in the dictionary
386
+ for (const [key, value] of Object.entries(this.versificationDifferences[book])) {
387
+ // Check if the key starts with the desired chapter
388
+ if (value[version.abbreviation].startsWith(`${chapter}:`)) {
389
+ // Ensure the version exists in the value object
390
+ if (value[version.abbreviation]) {
391
+ // Extract the verse number from the value
392
+ const verse = value[version.abbreviation].split(":")[1]
393
+ this.chapterVerses[book][chapter].push(Number(verse))
394
+ }
395
+ }
396
+ }
397
+ this.chapterVerses[book][chapter] = Array.from(this.chapterVerses[book][chapter])
398
+ return this.chapterVerses // Return the array of verses
399
+ }
400
+
401
+ _setVersion(passage) {
402
+ this.version = passage.version.abbreviation
403
+ this._searchVersificationDifferences(passage)
404
+ }
405
+
371
406
  versification() {
372
407
  this.passages.forEach((passage) => {
373
408
  const hasVersification = this.versificationDifferences[passage.book]
@@ -416,9 +451,10 @@ class CodexParser {
416
451
  */
417
452
  populate(parsedPassage) {
418
453
  const passages = []
419
-
420
454
  // Helper function to process a parsed passage's verses
421
- const processVerses = (chapter, verses, book) => {
455
+ const processVerses = (passage) => {
456
+ const { book, chapter, verses } = passage
457
+
422
458
  if (!verses) {
423
459
  return
424
460
  }
@@ -435,11 +471,11 @@ class CodexParser {
435
471
  }
436
472
 
437
473
  // Process main passage
438
- processVerses(parsedPassage.chapter, parsedPassage.verses, parsedPassage.book)
474
+ processVerses(parsedPassage)
439
475
 
440
476
  // Process 'to' object if it exists (for cross-chapter ranges)
441
477
  if (parsedPassage.to) {
442
- processVerses(parsedPassage.to.chapter, parsedPassage.to.verses, parsedPassage.to.book)
478
+ processVerses(parsedPassage.to)
443
479
  }
444
480
 
445
481
  return passages