codexparser 0.0.79 → 0.0.81

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codexparser",
3
- "version": "0.0.79",
3
+ "version": "0.0.81",
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/scan-test.js CHANGED
@@ -4,20 +4,7 @@ const util = require("util")
4
4
  const dump = (item) => {
5
5
  console.log(util.inspect(item, { depth: null, colors: true }))
6
6
  }
7
- 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
8
-
9
- Ge 27.27-29,89-40 Heb 11.20 Heb. 12.17 Jonah 3
10
-
11
- Jd. 5
12
- Jd 6
13
-
14
- 1 Cor 12:34 2 Cor 3:4. He 4.12 Re 1.16
15
-
16
- Leviticus 16:6 He 5.3 He 7.27
17
-
18
- Hos 10:1-3, 8 and 1 John 2:23
19
-
20
- exod15.18. 2 Cor 12:23 Malachi 3:32`
7
+ let text = `Psalm 94:4-100:6 MT`
21
8
  const parser = new BibleParser()
22
- const result = parser.find(text)
9
+ const result = parser.find(text).enhance()
23
10
  dump(result)
@@ -22,6 +22,35 @@ class CodexParser {
22
22
  this.EzraAbbrv = EzraAbbrv
23
23
  //this.toc = toc
24
24
  this.crawler = new crawler()
25
+ this.preStrings = ["III", "II", "I", "1st", "2nd", "3rd", "First", "Second", "Third", "1", "2", "3"]
26
+ this.preStringed = [
27
+ "Sam",
28
+ "Samuel",
29
+ "Kings",
30
+ "Kgs",
31
+ "Kin",
32
+ "Chron",
33
+ "Chronicles",
34
+ "Corinthians",
35
+ "Co",
36
+ "Cor",
37
+ "Thessalonians",
38
+ "Th",
39
+ "Thes",
40
+ "Thess",
41
+ "Timothy",
42
+ "Ti",
43
+ "Tim",
44
+ "Peter",
45
+ "Pe",
46
+ "Pet",
47
+ "Pt",
48
+ "John",
49
+ "Jn",
50
+ "Jhn",
51
+ ]
52
+
53
+ this.text = String
25
54
  }
26
55
 
27
56
  /**
@@ -90,6 +119,7 @@ class CodexParser {
90
119
  }
91
120
  this.passages = []
92
121
  this.scan(reference)
122
+ const books = []
93
123
  for (let i = 0; i < this.found.length; i++) {
94
124
  const result = this.found[i]
95
125
  if (result.type === "range" && result.start.b !== result.end.b) {
@@ -138,13 +168,14 @@ class CodexParser {
138
168
  }
139
169
  passage.original = result.osis
140
170
  passage.scripture = this.scripturize(passage)
171
+ passage.passages = this.populate(result.entities[0], passage.verses)
141
172
  passage.indices = result.indices
142
- passage.entities = result.entities
143
- if (passage.entities[0].translations) {
173
+ passage.entities = result.entities[0]
174
+ if (passage.entities.translations) {
144
175
  passage.version = {
145
- name: passage.entities[0].translations[0].translation,
146
- alias: passage.entities[0].translations[0].alias,
147
- abbreviation: passage.entities[0].translations[0].osis,
176
+ name: passage.entities.translations[0].translation,
177
+ alias: passage.entities.translations[0].alias,
178
+ abbreviation: passage.entities.translations[0].osis,
148
179
  }
149
180
  }
150
181
  this.passages.push(passage)
@@ -152,6 +183,37 @@ class CodexParser {
152
183
  this.found = []
153
184
  return this
154
185
  }
186
+
187
+ populate(entities, verses) {
188
+ let passages = []
189
+ for (let i = entities.start.v; i <= entities.end.v; i++) {
190
+ passages.push({
191
+ book: entities.start.b,
192
+ chapter: entities.start.c,
193
+ verse: i,
194
+ })
195
+ }
196
+
197
+ if (verses.length > 1) {
198
+ for (let i = 0; i < verses.length; i++) {
199
+ const passage = {
200
+ book: entities.start.b,
201
+ chapter: entities.start.c,
202
+ verse: verses[i],
203
+ }
204
+ if (
205
+ !passages.find(
206
+ (p) => p.book === passage.book && p.chapter === passage.chapter && p.verse === passage.verse
207
+ )
208
+ ) {
209
+ passages.push(passage)
210
+ }
211
+ }
212
+ }
213
+
214
+ return [...new Set(passages)]
215
+ }
216
+
155
217
  chapterify(chapter) {
156
218
  return chapter.start.c
157
219
  }
@@ -229,262 +291,18 @@ class CodexParser {
229
291
  return parts
230
292
  .join(" ")
231
293
  .replace(/\s+:\s+/g, ":")
294
+ .replace(/\s[-–—]\s/, "-")
232
295
  .trim()
233
296
  }
234
297
  find(text) {
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
- ]
298
+ const books = [...Object.keys(this.abbrevations), ...this.bible.new, ...this.bible.old]
454
299
 
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
300
  let newText = ""
483
301
 
484
302
  //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])
303
+ for (let b = 0; b < this.preStringed.length; b++) {
304
+ for (let pre = 0; pre < this.preStrings.length; pre++) {
305
+ books.push(this.preStrings[pre] + " " + this.preStringed[b])
488
306
  }
489
307
  }
490
308
  // add the book name with . at the end as this seems to be added sometimes, at least to the shortened forms
@@ -529,29 +347,67 @@ class CodexParser {
529
347
  newText += "<span class='passage'>" + booksAt[b][0]
530
348
  let passage = booksAt[b][0]
531
349
  chNoInText += booksAt[b][0].length //skip the 'fill-in characters
350
+ let abbr
351
+ let index = []
532
352
  for (let i = 0; i < 100; i++) {
533
353
  chNoInText++
534
- const nextCh = text.charAt(chNoInText)
354
+ let nextCh = text.charAt(chNoInText)
355
+ const testStr = text.substring(chNoInText - passage.length, chNoInText + 5).toLowerCase()
356
+ if (testStr.includes("lxx")) abbr = "lxx"
357
+ if (testStr.includes("na")) abbr = "na"
358
+ if (testStr.includes("ubs")) abbr = "ubs"
359
+ if (testStr.includes("mt")) abbr = "mt"
360
+ if (testStr.includes("bhs")) abbr = "bhs"
361
+ if (testStr.includes("lxx")) abbr = "lxx"
362
+ if (testStr.includes("na")) abbr = "na"
363
+ if (testStr.includes("ubs")) abbr = "ubs"
364
+ if (testStr.includes("mt")) abbr = "mt"
365
+ if (testStr.includes("bhs")) abbr = "bhs"
535
366
  //test whether are at the end of the chapter(s) and verse(s)
536
- if (nextCh.match(/^[a-z]+$/) && nextCh !== "f" && nextCh !== "ff") break
367
+ if (nextCh.match(/^[a-z]+$/) && nextCh !== "f" && nextCh !== "ff" && nextCh !== "a") break
537
368
  if (nextCh.match(/^[A-Z]+$/)) break
538
369
  newText += text.charAt(chNoInText - 1)
539
370
  passage += text.charAt(chNoInText - 1)
371
+ index.push(chNoInText - 1)
540
372
  }
541
- this.found.push(passage.trim())
373
+
374
+ index = [index[0], index[index.length - 1]]
375
+ console.log(index)
376
+ this.found.push(passage.trim() + (abbr ? " " + abbr.toUpperCase() : ""))
542
377
  newText += "</span>&nbsp;"
543
378
  }
379
+ this.text = newText
544
380
  return this
545
381
  }
546
382
 
383
+ getText() {
384
+ return this.text
385
+ }
386
+
547
387
  enhance() {
548
388
  if (this.found.length > 0) {
549
389
  for (let i = 0; i < this.found.length; i++) {
390
+ const found = this.found[i]
391
+ const book = this.bookify(this.found[i].match(this.bookRegex)[0])
392
+ const passageWithoutBook = found.replace(book, "")
393
+ let chapter, verse
394
+ if (/[:\.]/.test(passageWithoutBook)) {
395
+ chapter = parseInt(passageWithoutBook.split(":").shift().trim(), 10)
396
+ verse = parseInt(passageWithoutBook.split(":").pop().trim(), 10)
397
+ } else {
398
+ if (/\d+/gim.test(passageWithoutBook)) {
399
+ chapter = parseInt(passageWithoutBook.trim())
400
+ verse = null
401
+ }
402
+ }
403
+
404
+ let type = "verseRange"
405
+
550
406
  const passage = {
551
407
  original: this.found[i],
552
408
  book: this.bookify(this.found[i].match(this.bookRegex)[0]),
553
409
  chapter: this.found[i].match(this.chapterRegex),
554
- verse: this.found[i].match(/(?<=[.:])(\d+.+)/),
410
+ verse: this.found[i].match(/(?<=[.:])(\d+.+)/)[0],
555
411
  }
556
412
  this.passages.push(passage)
557
413
  }
package/src/abbr.js CHANGED
@@ -91,7 +91,6 @@ const abbrevations = {
91
91
  "II Ch": "2 Chronicles",
92
92
  Ezra: "Ezra",
93
93
  Ezr: "Ezra",
94
- Ez: "Ezra",
95
94
  Neh: "Nehemiah",
96
95
  Ne: "Nehemiah",
97
96
  Esth: "Esther",
@@ -0,0 +1,6 @@
1
+ const util = require("util")
2
+ const dump = (item) => {
3
+ console.log(util.inspect(item, { depth: null, colors: true }))
4
+ }
5
+
6
+ module.exports.dump = dump
@@ -10,6 +10,7 @@ parser.options({
10
10
  invalid_passage_strategy: "include",
11
11
  invalid_sequence_strategy: "include",
12
12
  single_chapter_1_strategy: "verse",
13
+ sequence_combination_strategy: "combine",
13
14
  })
14
- const result = parser.parse("Isaiah 8:21-9:6")
15
+ const result = parser.parse("Jude 5-7,11 Numbers 14:29-30 Genesis 19:24-25 Genesis 4:3-8 Numbers 31:16 Numbers 16:1-50")
15
16
  dump(result.getPassages())
@@ -0,0 +1,8 @@
1
+ const BibleParser = require("../src/CodexParser.js")
2
+ const dump = require("../src/functions.js").dump
3
+ const parser = new BibleParser()
4
+ const text = "Job 1:1b"
5
+
6
+ const passages = parser.find(text).enhance()
7
+
8
+ dump(passages)
@@ -4,11 +4,12 @@ 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 = "Psalm 34:12f"
7
+ const text = "John 12:38 John 1:29,34 Isaiah 53:1 Isaiah 6:10 Isaiah 6:1 Isaiah 52:13 Isaiah 6:3 LXX Isaiah 52:13 LXX Isaiah 6:7 Isaiah 53:12 Isaiah 52:13 - 53:12"
8
8
 
9
9
  const parser = new bcv_parser({
10
10
  invalid_sequence_strategy: "include",
11
11
  invalid_passage_strategy: "include",
12
+ sequence_combination_strategy: "combine"
12
13
  })
13
14
  const textParser = parser.parse(text)
14
15
  console.log(textParser)
package/tests/find.js ADDED
@@ -0,0 +1,8 @@
1
+ const CodexParser = require("../src/CodexParser.js")
2
+
3
+ const parser = new CodexParser()
4
+
5
+ parser.find('Psalm 2:2-13; 3:2-4 30:5 LXX').enhance()
6
+
7
+ console.log(parser.getPassages())
8
+ console.log(parser.getText())
@@ -0,0 +1,10 @@
1
+ const BibleParser = require("../src/CodexParser.js")
2
+ const dump = require("../src/functions.js").dump
3
+
4
+ const parser = new BibleParser()
5
+
6
+ const text = "Job 1:1-5"
7
+
8
+ const passages = parser.parse(text).getPassages()
9
+
10
+ dump(passages)
File without changes