codexparser 0.0.78 → 0.0.79

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.
@@ -4,13 +4,14 @@ const util = require("util")
4
4
  const dump = (item) => {
5
5
  console.log(util.inspect(item, { depth: null, colors: true }))
6
6
  }
7
- const text = "Ap 8:27"
7
+ const text = "Psalm 34:12f"
8
8
 
9
9
  const parser = new bcv_parser({
10
10
  invalid_sequence_strategy: "include",
11
11
  invalid_passage_strategy: "include",
12
12
  })
13
13
  const textParser = parser.parse(text)
14
+ console.log(textParser)
14
15
  const passages = textParser.parsed_entities()
15
16
  passages.forEach((passage) => {
16
17
  dump(passage)
package/find-test.js ADDED
@@ -0,0 +1,20 @@
1
+ const BibleParser = require("./src/CodexParser.js")
2
+
3
+ let text = `Joel 10:13 The passages Luke 2:32 and Lk 1:23 that we are looking at tonight 1 Cor 12:34 2 Cor 3:4 are found Jude 6, in Jude 5, Genesis 2:1 - 3:19, 1 John 3:16-17, 1 Peter 1:1, and Romans 10:13, 15, 17. Please turn in your Bibles. Ps 109:4,5,6,8. Isaiah 61.2-3 Mt 5.4
4
+
5
+ Ge 27.27-29,89-40 Heb 11.20 Heb. 12.17 Jonah 3
6
+
7
+ Jd. 5
8
+ Jd 6
9
+
10
+ 1 Cor 12:34 2 Cor 3:4. He 4.12 Re 1.16
11
+
12
+ Leviticus 16:6 He 5.3 He 7.27
13
+
14
+ Hos 10:1-3, 8 and 1 John 2:23f
15
+
16
+ exod15.18. 2 Cor 12:23 Malachi 3:32`
17
+
18
+ const parser = new BibleParser()
19
+ const result = parser.find("Isaiah 29:16; 45:9 // Romans 9:20").enhance()
20
+ console.log(result)
package/jstester.js CHANGED
@@ -1,3 +1,5 @@
1
+ const BibleParser = require("./src/CodexParser.js")
2
+ const parser = new BibleParser()
1
3
  const books = [
2
4
  "Gen",
3
5
  "Ge",
@@ -298,13 +300,16 @@ booksAt.sort(function (a, b) {
298
300
  })
299
301
  newText = ""
300
302
  let chNoInText = 0
303
+
304
+ let passages = []
301
305
  for (let b = 0; b < booksAt.length; b++) {
302
306
  while (chNoInText < booksAt[b][1]) {
303
307
  //copy across characters to start of book
304
308
  newText += text.charAt(chNoInText)
305
309
  chNoInText++
306
310
  }
307
- newText += booksAt[b][0]
311
+ newText += "<span class='passage'>" + booksAt[b][0]
312
+ let passage = booksAt[b][0]
308
313
  chNoInText += booksAt[b][0].length //skip the 'fill-in characters
309
314
  for (let i = 0; i < 100; i++) {
310
315
  chNoInText++
@@ -313,8 +318,12 @@ for (let b = 0; b < booksAt.length; b++) {
313
318
  if (nextCh.match(/^[a-z]+$/)) break
314
319
  if (nextCh.match(/^[A-Z]+$/)) break
315
320
  newText += text.charAt(chNoInText - 1)
321
+ passage += text.charAt(chNoInText - 1)
316
322
  }
317
- newText += " "
323
+ passages.push(passage.trim())
324
+ newText += "</span>&nbsp;"
318
325
  }
319
326
 
320
- console.log(newText)
327
+ const found = parser.find(text)
328
+
329
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codexparser",
3
- "version": "0.0.78",
3
+ "version": "0.0.79",
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": {
@@ -125,7 +125,8 @@ class CodexParser {
125
125
  next = this.found[i + 1]
126
126
  }
127
127
  }
128
- if (passage.type === "range" && passage.book === result.end.b) {
128
+
129
+ if (passage.type === "range" && result.start.b === result.end.b) {
129
130
  if (result.start.c !== result.end.c) {
130
131
  passage.verses = [result.start.v]
131
132
  passage.to = {
@@ -231,62 +232,331 @@ class CodexParser {
231
232
  .trim()
232
233
  }
233
234
  find(text) {
234
- const bookNames = this.bookRegex.toString().split("|").slice(8)
235
- const books = [...this.bible.old, ...this.bible.new, ...bookNames]
236
- for (let i = 0; i < books.length; i++) {
237
- const book = books[i].toLowerCase()
238
- const index = text.toLowerCase().indexOf(book)
239
- // Checks to see if the previous character is a colon. If it is, skip.
240
- // This makes sure that if you have a case like Genesis 1:1 John 1:1, the code knows that
241
- // the book cannot be 1 John.
242
- if (text[index - 1] && text[index - 1].includes(":") && text[index - 1].match(/[a-zA-Z]/)) continue
235
+ const books = [
236
+ "Gen",
237
+ "Ge",
238
+ "Gn",
239
+ "Exo",
240
+ "Ex",
241
+ "Exod",
242
+ "Lev",
243
+ "Le",
244
+ "Lv",
245
+ "Num",
246
+ "Nu",
247
+ "Nm",
248
+ "Nb",
249
+ "Deut",
250
+ "Dt",
251
+ "Josh",
252
+ "Jos",
253
+ "Jsh",
254
+ "Judg",
255
+ "Jdg",
256
+ "Jg",
257
+ "Jdgs",
258
+ "Rth",
259
+ "Ru",
260
+ "Sam",
261
+ "Samuel",
262
+ "Kings",
263
+ "Kgs",
264
+ "Kin",
265
+ "Chron",
266
+ "Chronicles",
267
+ "Ezra",
268
+ "Ezr",
269
+ "Ez",
270
+ "Neh",
271
+ "Ne",
272
+ "Esth",
273
+ "Es",
274
+ "Job",
275
+ "Job",
276
+ "Jb",
277
+ "Pslm",
278
+ "Ps",
279
+ "Psalms",
280
+ "Psa",
281
+ "Psm",
282
+ "Pss",
283
+ "Prov",
284
+ "Pr",
285
+ "Prv",
286
+ "Eccles",
287
+ "Ec",
288
+ "Song",
289
+ "So",
290
+ "Canticles",
291
+ "Song of Songs",
292
+ "SOS",
293
+ "Isa",
294
+ "Is",
295
+ "Jer",
296
+ "Je",
297
+ "Jr",
298
+ "Lam",
299
+ "La",
300
+ "Ezek",
301
+ "Eze",
302
+ "Ezk",
303
+ "Dan",
304
+ "Da",
305
+ "Dn",
306
+ "Hos",
307
+ "Ho",
308
+ "Joel",
309
+ "Joe",
310
+ "Jl",
311
+ "Amos",
312
+ "Am",
313
+ "Obad",
314
+ "Ob",
315
+ "Jnh",
316
+ "Jon",
317
+ "Micah",
318
+ "Mic",
319
+ "Nah",
320
+ "Na",
321
+ "Hab",
322
+ "Zeph",
323
+ "Zep",
324
+ "Zp",
325
+ "Haggai",
326
+ "Hag",
327
+ "Hg",
328
+ "Zech",
329
+ "Zec",
330
+ "Zc",
331
+ "Mal",
332
+ "Mal",
333
+ "Ml",
334
+ "Matt",
335
+ "Mt",
336
+ "Mrk",
337
+ "Mk",
338
+ "Mr",
339
+ "Luk",
340
+ "Lk",
341
+ "John",
342
+ "Jn",
343
+ "Jhn",
344
+ "Acts",
345
+ "Ac",
346
+ "Rom",
347
+ "Ro",
348
+ "Rm",
349
+ "Co",
350
+ "Cor",
351
+ "Corinthians",
352
+ "Gal",
353
+ "Ga",
354
+ "Ephes",
355
+ "Eph",
356
+ "Phil",
357
+ "Php",
358
+ "Col",
359
+ "Col",
360
+ "Th",
361
+ "Thes",
362
+ "Thess",
363
+ "Thessalonians",
364
+ "Ti",
365
+ "Tim",
366
+ "Timothy",
367
+ "Titus",
368
+ "Tit",
369
+ "Philem",
370
+ "Phm",
371
+ "Hebrews",
372
+ "Heb",
373
+ "He",
374
+ "James",
375
+ "Jas",
376
+ "Jm",
377
+ "Pe",
378
+ "Pet",
379
+ "Pt",
380
+ "Peter",
381
+ "Jn",
382
+ "Jo",
383
+ "Joh",
384
+ "Jhn",
385
+ "John",
386
+ "Jude",
387
+ "Jd",
388
+ "Jud",
389
+ "Jud",
390
+ "Rev",
391
+ "The Revelation",
392
+ "Genesis",
393
+ "Exodus",
394
+ "Leviticus",
395
+ "Numbers",
396
+ "Deuteronomy",
397
+ "Joshua",
398
+ "Judges",
399
+ "Ruth",
400
+ "Samuel",
401
+ "Kings",
402
+ "Chronicles",
403
+ "Ezra",
404
+ "Nehemiah",
405
+ "Esther",
406
+ "Job",
407
+ "Psalms",
408
+ "Psalm",
409
+ "Proverbs",
410
+ "Ecclesiastes",
411
+ "Song of Solomon",
412
+ "Isaiah",
413
+ "Jeremiah",
414
+ "Lamentations",
415
+ "Ezekiel",
416
+ "Daniel",
417
+ "Hosea",
418
+ "Joel",
419
+ "Amos",
420
+ "Obadiah",
421
+ "Jonah",
422
+ "Micah",
423
+ "Nahum",
424
+ "Habakkuk",
425
+ "Zephaniah",
426
+ "Haggai",
427
+ "Zechariah",
428
+ "Malachi",
429
+ "Matthew",
430
+ "Mark",
431
+ "Luke",
432
+ "John",
433
+ "Acts",
434
+ "Romans",
435
+ "Corinthians",
436
+ "Galatians",
437
+ "Ephesians",
438
+ "Philippians",
439
+ "Colossians",
440
+ "Thessalonians",
441
+ "Timothy",
442
+ "Titus",
443
+ "Philemon",
444
+ "Hebrews",
445
+ "James",
446
+ "Peter",
447
+ "John",
448
+ "Revelation",
449
+ "Re",
450
+ "Ap",
451
+ "Jd.",
452
+ "Heb.",
453
+ ]
243
454
 
244
- // Get the book and chapter
245
- if (index > -1) {
246
- const bookEndIndex = index + book.length - 1
247
- const passage = {
248
- book: text.substring(index, bookEndIndex + 1),
249
- }
250
- let chapter = 0
251
- let chapterStartIndex = null
252
- let chapterEndIndex = null
253
- let j = bookEndIndex + 1
254
- while (j < text.length && !text[j].match(/[a-zA-Z]/)) {
255
- const match = text.substring(j).match(/^\s*(\d+)/)
256
- if (match) {
257
- chapter = parseInt(match[1])
258
- chapterStartIndex = j
259
- chapterEndIndex = j + match[0].length
260
- break
261
- }
262
- j++
263
- }
455
+ const preStrings = ["III", "II", "I", "1st", "2nd", "3rd", "First", "Second", "Third", "1", "2", "3"]
456
+ const preStringed = [
457
+ "Sam",
458
+ "Samuel",
459
+ "Kings",
460
+ "Kgs",
461
+ "Kin",
462
+ "Chron",
463
+ "Chronicles",
464
+ "Corinthians",
465
+ "Co",
466
+ "Cor",
467
+ "Thessalonians",
468
+ "Th",
469
+ "Thes",
470
+ "Thess",
471
+ "Timothy",
472
+ "Ti",
473
+ "Tim",
474
+ "Peter",
475
+ "Pe",
476
+ "Pet",
477
+ "Pt",
478
+ "John",
479
+ "Jn",
480
+ "Jhn",
481
+ ]
482
+ let newText = ""
264
483
 
265
- let verseIndex = chapterEndIndex + 1
266
- let verseStartIndex = null
267
- let verseEndIndex = null
268
- let verse
269
- while (verseIndex < text.length && !text[verseIndex].match(/[a-zA-Z]/)) {
270
- const match = text.substring(verseIndex).match(/^\s*?(\d+)[^a-zA-Z]*/)
271
- if (match) {
272
- verseStartIndex = verseIndex
273
- verseEndIndex = verseIndex + match[0].length
274
- break
484
+ //add the prestringed versions e.g. 1 Peter
485
+ for (let b = 0; b < preStringed.length; b++) {
486
+ for (let pre = 0; pre < preStrings.length; pre++) {
487
+ books.push(preStrings[pre] + " " + preStringed[b])
488
+ }
489
+ }
490
+ // add the book name with . at the end as this seems to be added sometimes, at least to the shortened forms
491
+ const length = books.length
492
+ for (let b = 0; b < length; b++) {
493
+ books.push(books[b] + ".")
494
+ }
495
+
496
+ // sort descending - longer items first
497
+ books.sort((a, b) => b.length - a.length)
498
+ let booksAt = []
499
+ // go thro' each book finding where it matches in text
500
+ for (let b = 0; b < books.length; b++) {
501
+ const book = books[b]
502
+ let chNoInText = 0
503
+ while (chNoInText < text.length) {
504
+ let j = text.indexOf(book, chNoInText)
505
+ if (j < 0) break
506
+ if (j + book.length < text.length && !text.charAt(j + book.length).match(/^[a-z]+$/)) {
507
+ booksAt.push([book, j])
508
+ let replacement = book
509
+ for (let k = 0; k < book.length; k++) {
510
+ replacement = replacement.replace(book.charAt(k), "X")
275
511
  }
276
- verseIndex++
512
+ text = text.replace(book, replacement) // to prevent a shorter version matching
277
513
  }
278
- verse = parseInt(text.substring(verseStartIndex, verseEndIndex))
279
-
280
- if (chapter > 0) passage.chapter = chapter
281
- if (verse > 0) passage.verse = verse
514
+ chNoInText = j + book.length + 1
515
+ }
516
+ }
517
+ // into ascending order of start position
518
+ booksAt.sort(function (a, b) {
519
+ return a[1] - b[1]
520
+ })
521
+ newText = ""
522
+ let chNoInText = 0
523
+ for (let b = 0; b < booksAt.length; b++) {
524
+ while (chNoInText < booksAt[b][1]) {
525
+ //copy across characters to start of book
526
+ newText += text.charAt(chNoInText)
527
+ chNoInText++
528
+ }
529
+ newText += "<span class='passage'>" + booksAt[b][0]
530
+ let passage = booksAt[b][0]
531
+ chNoInText += booksAt[b][0].length //skip the 'fill-in characters
532
+ for (let i = 0; i < 100; i++) {
533
+ chNoInText++
534
+ const nextCh = text.charAt(chNoInText)
535
+ //test whether are at the end of the chapter(s) and verse(s)
536
+ if (nextCh.match(/^[a-z]+$/) && nextCh !== "f" && nextCh !== "ff") break
537
+ if (nextCh.match(/^[A-Z]+$/)) break
538
+ newText += text.charAt(chNoInText - 1)
539
+ passage += text.charAt(chNoInText - 1)
540
+ }
541
+ this.found.push(passage.trim())
542
+ newText += "</span>&nbsp;"
543
+ }
544
+ return this
545
+ }
282
546
 
283
- passage.index = {
284
- start: index,
547
+ enhance() {
548
+ if (this.found.length > 0) {
549
+ for (let i = 0; i < this.found.length; i++) {
550
+ const passage = {
551
+ original: this.found[i],
552
+ book: this.bookify(this.found[i].match(this.bookRegex)[0]),
553
+ chapter: this.found[i].match(this.chapterRegex),
554
+ verse: this.found[i].match(/(?<=[.:])(\d+.+)/),
285
555
  }
286
556
  this.passages.push(passage)
287
557
  }
288
558
  }
289
- return this
559
+ return this.passages
290
560
  }
291
561
 
292
562
  regex(text) {
@@ -11,5 +11,5 @@ parser.options({
11
11
  invalid_sequence_strategy: "include",
12
12
  single_chapter_1_strategy: "verse",
13
13
  })
14
- const result = parser.parse("Psalm 34:12f")
14
+ const result = parser.parse("Isaiah 8:21-9:6")
15
15
  dump(result.getPassages())