codexparser 0.0.59 → 0.0.60

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,11 +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 = "Genesis 1:1 John 1:1"
7
+ const text = "Malachi 3:23"
8
8
 
9
- const parser = new bcv_parser()
9
+ const parser = new bcv_parser({
10
+ invalid_sequence_strategy: "include",
11
+ invalid_passage_strategy: "include",
12
+ })
10
13
  const textParser = parser.parse(text)
11
14
  const passages = textParser.parsed_entities()
12
15
  passages.forEach((passage) => {
13
16
  dump(passage)
14
- })
17
+ })
package/jstester.js ADDED
@@ -0,0 +1,320 @@
1
+ const books = [
2
+ "Gen",
3
+ "Ge",
4
+ "Gn",
5
+ "Exo",
6
+ "Ex",
7
+ "Exod",
8
+ "Lev",
9
+ "Le",
10
+ "Lv",
11
+ "Num",
12
+ "Nu",
13
+ "Nm",
14
+ "Nb",
15
+ "Deut",
16
+ "Dt",
17
+ "Josh",
18
+ "Jos",
19
+ "Jsh",
20
+ "Judg",
21
+ "Jdg",
22
+ "Jg",
23
+ "Jdgs",
24
+ "Rth",
25
+ "Ru",
26
+ "Sam",
27
+ "Samuel",
28
+ "Kings",
29
+ "Kgs",
30
+ "Kin",
31
+ "Chron",
32
+ "Chronicles",
33
+ "Ezra",
34
+ "Ezr",
35
+ "Ez",
36
+ "Neh",
37
+ "Ne",
38
+ "Esth",
39
+ "Es",
40
+ "Job",
41
+ "Job",
42
+ "Jb",
43
+ "Pslm",
44
+ "Ps",
45
+ "Psalms",
46
+ "Psa",
47
+ "Psm",
48
+ "Pss",
49
+ "Prov",
50
+ "Pr",
51
+ "Prv",
52
+ "Eccles",
53
+ "Ec",
54
+ "Song",
55
+ "So",
56
+ "Canticles",
57
+ "Song of Songs",
58
+ "SOS",
59
+ "Isa",
60
+ "Is",
61
+ "Jer",
62
+ "Je",
63
+ "Jr",
64
+ "Lam",
65
+ "La",
66
+ "Ezek",
67
+ "Eze",
68
+ "Ezk",
69
+ "Dan",
70
+ "Da",
71
+ "Dn",
72
+ "Hos",
73
+ "Ho",
74
+ "Joel",
75
+ "Joe",
76
+ "Jl",
77
+ "Amos",
78
+ "Am",
79
+ "Obad",
80
+ "Ob",
81
+ "Jnh",
82
+ "Jon",
83
+ "Micah",
84
+ "Mic",
85
+ "Nah",
86
+ "Na",
87
+ "Hab",
88
+ "Zeph",
89
+ "Zep",
90
+ "Zp",
91
+ "Haggai",
92
+ "Hag",
93
+ "Hg",
94
+ "Zech",
95
+ "Zec",
96
+ "Zc",
97
+ "Mal",
98
+ "Mal",
99
+ "Ml",
100
+ "Matt",
101
+ "Mt",
102
+ "Mrk",
103
+ "Mk",
104
+ "Mr",
105
+ "Luk",
106
+ "Lk",
107
+ "John",
108
+ "Jn",
109
+ "Jhn",
110
+ "Acts",
111
+ "Ac",
112
+ "Rom",
113
+ "Ro",
114
+ "Rm",
115
+ "Co",
116
+ "Cor",
117
+ "Corinthians",
118
+ "Gal",
119
+ "Ga",
120
+ "Ephes",
121
+ "Eph",
122
+ "Phil",
123
+ "Php",
124
+ "Col",
125
+ "Col",
126
+ "Th",
127
+ "Thes",
128
+ "Thess",
129
+ "Thessalonians",
130
+ "Ti",
131
+ "Tim",
132
+ "Timothy",
133
+ "Titus",
134
+ "Tit",
135
+ "Philem",
136
+ "Phm",
137
+ "Hebrews",
138
+ "Heb",
139
+ "He",
140
+ "James",
141
+ "Jas",
142
+ "Jm",
143
+ "Pe",
144
+ "Pet",
145
+ "Pt",
146
+ "Peter",
147
+ "Jn",
148
+ "Jo",
149
+ "Joh",
150
+ "Jhn",
151
+ "John",
152
+ "Jude",
153
+ "Jd",
154
+ "Jud",
155
+ "Jud",
156
+ "Rev",
157
+ "The Revelation",
158
+ "Genesis",
159
+ "Exodus",
160
+ "Leviticus",
161
+ "Numbers",
162
+ "Deuteronomy",
163
+ "Joshua",
164
+ "Judges",
165
+ "Ruth",
166
+ "Samuel",
167
+ "Kings",
168
+ "Chronicles",
169
+ "Ezra",
170
+ "Nehemiah",
171
+ "Esther",
172
+ "Job",
173
+ "Psalms",
174
+ "Psalm",
175
+ "Proverbs",
176
+ "Ecclesiastes",
177
+ "Song of Solomon",
178
+ "Isaiah",
179
+ "Jeremiah",
180
+ "Lamentations",
181
+ "Ezekiel",
182
+ "Daniel",
183
+ "Hosea",
184
+ "Joel",
185
+ "Amos",
186
+ "Obadiah",
187
+ "Jonah",
188
+ "Micah",
189
+ "Nahum",
190
+ "Habakkuk",
191
+ "Zephaniah",
192
+ "Haggai",
193
+ "Zechariah",
194
+ "Malachi",
195
+ "Matthew",
196
+ "Mark",
197
+ "Luke",
198
+ "John",
199
+ "Acts",
200
+ "Romans",
201
+ "Corinthians",
202
+ "Galatians",
203
+ "Ephesians",
204
+ "Philippians",
205
+ "Colossians",
206
+ "Thessalonians",
207
+ "Timothy",
208
+ "Titus",
209
+ "Philemon",
210
+ "Hebrews",
211
+ "James",
212
+ "Peter",
213
+ "John",
214
+ "Revelation",
215
+ "Re",
216
+ "Ap",
217
+ "Jd.",
218
+ "Heb.",
219
+ ]
220
+
221
+ const preStrings = ["III", "II", "I", "1st", "2nd", "3rd", "First", "Second", "Third", "1", "2", "3"]
222
+ const preStringed = [
223
+ "Sam",
224
+ "Samuel",
225
+ "Kings",
226
+ "Kgs",
227
+ "Kin",
228
+ "Chron",
229
+ "Chronicles",
230
+ "Corinthians",
231
+ "Co",
232
+ "Cor",
233
+ "Thessalonians",
234
+ "Th",
235
+ "Thes",
236
+ "Thess",
237
+ "Timothy",
238
+ "Ti",
239
+ "Tim",
240
+ "Peter",
241
+ "Pe",
242
+ "Pet",
243
+ "Pt",
244
+ "John",
245
+ "Jn",
246
+ "Jhn",
247
+ ]
248
+ 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
249
+
250
+ Ge 27.27-29,89-40 Heb 11.20 Heb. 12.17 Jonah 3
251
+
252
+ Jd. 5
253
+ Jd 6
254
+
255
+ 1 Cor 12:34 2 Cor 3:4. He 4.12 Re 1.16
256
+
257
+ Leviticus 16:6 He 5.3 He 7.27
258
+
259
+ Hos 10:1-3, 8 and 1 John 2:23
260
+
261
+ exod15.18. 2 Cor 12:23 Malachi 3:32`
262
+ //add the prestringed versions e.g. 1 Peter
263
+ for (let b = 0; b < preStringed.length; b++) {
264
+ for (let pre = 0; pre < preStrings.length; pre++) {
265
+ books.push(preStrings[pre] + " " + preStringed[b])
266
+ }
267
+ }
268
+ // add the book name with . at the end as this seems to be added sometimes, at least to the shortened forms
269
+ const length = books.length
270
+ for (let b = 0; b < length; b++) {
271
+ books.push(books[b] + ".")
272
+ }
273
+
274
+ // sort descending - longer items first
275
+ books.sort((a, b) => b.length - a.length)
276
+ let booksAt = []
277
+ // go thro' each book finding where it matches in text
278
+ for (let b = 0; b < books.length; b++) {
279
+ const book = books[b]
280
+ let chNoInText = 0
281
+ while (chNoInText < text.length) {
282
+ let j = text.indexOf(book, chNoInText)
283
+ if (j < 0) break
284
+ if (j + book.length < text.length && !text.charAt(j + book.length).match(/^[a-z]+$/)) {
285
+ booksAt.push([book, j])
286
+ let replacement = book
287
+ for (let k = 0; k < book.length; k++) {
288
+ replacement = replacement.replace(book.charAt(k), "X")
289
+ }
290
+ text = text.replace(book, replacement) // to prevent a shorter version matching
291
+ }
292
+ chNoInText = j + book.length + 1
293
+ }
294
+ }
295
+ // into ascending order of start position
296
+ booksAt.sort(function (a, b) {
297
+ return a[1] - b[1]
298
+ })
299
+ newText = ""
300
+ let chNoInText = 0
301
+ for (let b = 0; b < booksAt.length; b++) {
302
+ while (chNoInText < booksAt[b][1]) {
303
+ //copy across characters to start of book
304
+ newText += text.charAt(chNoInText)
305
+ chNoInText++
306
+ }
307
+ newText += booksAt[b][0]
308
+ chNoInText += booksAt[b][0].length //skip the 'fill-in characters
309
+ for (let i = 0; i < 100; i++) {
310
+ chNoInText++
311
+ const nextCh = text.charAt(chNoInText)
312
+ //test whether are at the end of the chapter(s) and verse(s)
313
+ if (nextCh.match(/^[a-z]+$/)) break
314
+ if (nextCh.match(/^[A-Z]+$/)) break
315
+ newText += text.charAt(chNoInText - 1)
316
+ }
317
+ newText += " "
318
+ }
319
+
320
+ console.log(newText)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codexparser",
3
- "version": "0.0.59",
3
+ "version": "0.0.60",
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": {
@@ -0,0 +1,21 @@
1
+ const CodexParser = require("./src/CodexParser")
2
+
3
+ const parser = new CodexParser()
4
+ const passage = "jer 9.24 1 cor 1.31 Jd 1"
5
+ 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
6
+
7
+ Ge 27.27-29,89-40 Heb 11.20 Heb. 12.17 Jonah 3
8
+
9
+ Jd. 5
10
+ Jd 6
11
+
12
+ 1 Cor 12:34 2 Cor 3:4. He 4.12 Re 1.16
13
+
14
+ Leviticus 16:6 He 5.3 He 7.27
15
+
16
+ Hos 10:1-3, 8 and 1 John 2:23
17
+
18
+ exod15.18. 2 Cor 12:23 Malachi 3:32`
19
+
20
+ parser.regex(text).regexParser()
21
+ console.log(parser.getPassages())
package/scan-test.js CHANGED
@@ -4,8 +4,20 @@ const util = require("util")
4
4
  const dump = (item) => {
5
5
  console.log(util.inspect(item, { depth: null, colors: true }))
6
6
  }
7
- const string = "Genesis 1:1 John 1:1"
8
- console.log(string)
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`
9
21
  const parser = new BibleParser()
10
- const result = parser.find(string)
22
+ const result = parser.find(text)
11
23
  dump(result)
@@ -23,8 +23,15 @@ class CodexParser {
23
23
  this.crawler = new crawler()
24
24
  }
25
25
 
26
+ /**
27
+ * Sets the options for the crawler and returns the current instance.
28
+ *
29
+ * @param {Object} options - The options to set.
30
+ * @return {Object} The current instance.
31
+ */
26
32
  options(options) {
27
33
  this.crawler.set_options(options)
34
+ return this
28
35
  }
29
36
 
30
37
  /**
@@ -71,7 +78,8 @@ class CodexParser {
71
78
  parse(reference) {
72
79
  //TODO: Need to fix chapter ranges when another verse is tacted onto the end of it.
73
80
  if (!reference) {
74
- throw new Error("Parse error (parse(): reference is undefined")
81
+ this.passages = []
82
+ return this
75
83
  }
76
84
  this.passages = []
77
85
  this.scan(reference)
@@ -205,311 +213,129 @@ class CodexParser {
205
213
  .trim()
206
214
  }
207
215
  find(text) {
208
- const books = [
209
- "Gen",
210
- "Ge",
211
- "Gn",
212
- "Exo",
213
- "Ex",
214
- "Exod",
215
- "Lev",
216
- "Le",
217
- "Lv",
218
- "Num",
219
- "Nu",
220
- "Nm",
221
- "Nb",
222
- "Deut",
223
- "Dt",
224
- "Josh",
225
- "Jos",
226
- "Jsh",
227
- "Judg",
228
- "Jdg",
229
- "Jg",
230
- "Jdgs",
231
- "Rth",
232
- "Ru",
233
- "Sam",
234
- "Samuel",
235
- "Kings",
236
- "Kgs",
237
- "Kin",
238
- "Chron",
239
- "Chronicles",
240
- "Ezra",
241
- "Ezr",
242
- "Ez",
243
- "Neh",
244
- "Ne",
245
- "Esth",
246
- "Es",
247
- "Job",
248
- "Job",
249
- "Jb",
250
- "Pslm",
251
- "Ps",
252
- "Psalms",
253
- "Psa",
254
- "Psm",
255
- "Pss",
256
- "Prov",
257
- "Pr",
258
- "Prv",
259
- "Eccles",
260
- "Ec",
261
- "Song",
262
- "So",
263
- "Canticles",
264
- "Song of Songs",
265
- "SOS",
266
- "Isa",
267
- "Is",
268
- "Jer",
269
- "Je",
270
- "Jr",
271
- "Lam",
272
- "La",
273
- "Ezek",
274
- "Eze",
275
- "Ezk",
276
- "Dan",
277
- "Da",
278
- "Dn",
279
- "Hos",
280
- "Ho",
281
- "Joel",
282
- "Joe",
283
- "Jl",
284
- "Amos",
285
- "Am",
286
- "Obad",
287
- "Ob",
288
- "Jnh",
289
- "Jon",
290
- "Micah",
291
- "Mic",
292
- "Nah",
293
- "Na",
294
- "Hab",
295
- "Zeph",
296
- "Zep",
297
- "Zp",
298
- "Haggai",
299
- "Hag",
300
- "Hg",
301
- "Zech",
302
- "Zec",
303
- "Zc",
304
- "Mal",
305
- "Mal",
306
- "Ml",
307
- "Matt",
308
- "Mt",
309
- "Mrk",
310
- "Mk",
311
- "Mr",
312
- "Luk",
313
- "Lk",
314
- "John",
315
- "Jn",
316
- "Jhn",
317
- "Acts",
318
- "Ac",
319
- "Rom",
320
- "Ro",
321
- "Rm",
322
- "Co",
323
- "Cor",
324
- "Corinthians",
325
- "Gal",
326
- "Ga",
327
- "Ephes",
328
- "Eph",
329
- "Phil",
330
- "Php",
331
- "Col",
332
- "Col",
333
- "Th",
334
- "Thes",
335
- "Thess",
336
- "Thessalonians",
337
- "Ti",
338
- "Tim",
339
- "Timothy",
340
- "Titus",
341
- "Tit",
342
- "Philem",
343
- "Phm",
344
- "Hebrews",
345
- "Heb",
346
- "He",
347
- "James",
348
- "Jas",
349
- "Jm",
350
- "Pe",
351
- "Pet",
352
- "Pt",
353
- "Peter",
354
- "Jn",
355
- "Jo",
356
- "Joh",
357
- "Jhn",
358
- "John",
359
- "Jude",
360
- "Jd",
361
- "Jud",
362
- "Jud",
363
- "Rev",
364
- "The Revelation",
365
- "Genesis",
366
- "Exodus",
367
- "Leviticus",
368
- "Numbers",
369
- "Deuteronomy",
370
- "Joshua",
371
- "Judges",
372
- "Ruth",
373
- "Samuel",
374
- "Kings",
375
- "Chronicles",
376
- "Ezra",
377
- "Nehemiah",
378
- "Esther",
379
- "Job",
380
- "Psalms",
381
- "Psalm",
382
- "Proverbs",
383
- "Ecclesiastes",
384
- "Song of Solomon",
385
- "Isaiah",
386
- "Jeremiah",
387
- "Lamentations",
388
- "Ezekiel",
389
- "Daniel",
390
- "Hosea",
391
- "Joel",
392
- "Amos",
393
- "Obadiah",
394
- "Jonah",
395
- "Micah",
396
- "Nahum",
397
- "Habakkuk",
398
- "Zephaniah",
399
- "Haggai",
400
- "Zechariah",
401
- "Malachi",
402
- "Matthew",
403
- "Mark",
404
- "Luke",
405
- "John",
406
- "Acts",
407
- "Romans",
408
- "Corinthians",
409
- "Galatians",
410
- "Ephesians",
411
- "Philippians",
412
- "Colossians",
413
- "Thessalonians",
414
- "Timothy",
415
- "Titus",
416
- "Philemon",
417
- "Hebrews",
418
- "James",
419
- "Peter",
420
- "John",
421
- "Revelation",
422
- "Re",
423
- "Ap",
424
- "Jd.",
425
- "Heb.",
426
- ]
216
+ const books = [...this.bible.old, ...this.bible.new]
217
+ const found = []
218
+ const passages = []
219
+ for (let i = 0; i < books.length; i++) {
220
+ const book = books[i].toLowerCase()
221
+ const index = text.toLowerCase().indexOf(book)
222
+ // Checks to see if the previous character is a colon. If it is, skip.
223
+ // This makes sure that if you have a case like Genesis 1:1 John 1:1, the code knows that
224
+ // the book cannot be 1 John.
225
+ if (text[index - 1] && text[index - 1].includes(":")) continue
427
226
 
428
- const preStrings = ["III", "II", "I", "1st", "2nd", "3rd", "First", "Second", "Third", "1", "2", "3"]
429
- const preStringed = [
430
- "Sam",
431
- "Samuel",
432
- "Kings",
433
- "Kgs",
434
- "Kin",
435
- "Chron",
436
- "Chronicles",
437
- "Corinthians",
438
- "Co",
439
- "Cor",
440
- "Thessalonians",
441
- "Th",
442
- "Thes",
443
- "Thess",
444
- "Timothy",
445
- "Ti",
446
- "Tim",
447
- "Peter",
448
- "Pe",
449
- "Pet",
450
- "Pt",
451
- "John",
452
- "Jn",
453
- "Jhn",
454
- ]
227
+ // Get the book and chapter
228
+ if (index > -1) {
229
+ const bookEndIndex = index + book.length - 1
230
+ const passage = {
231
+ book: text.substring(index, bookEndIndex + 1),
232
+ }
233
+ let chapter = 0
234
+ let chapterStartIndex = null
235
+ let chapterEndIndex = null
236
+ let j = bookEndIndex + 1
237
+ while (j < text.length) {
238
+ const match = text.substring(j).match(/^\s*(\d+)/)
239
+ if (match) {
240
+ chapter = match[1]
241
+ chapterStartIndex = j
242
+ chapterEndIndex = j + match[0].length
243
+ break
244
+ }
245
+ j++
246
+ }
455
247
 
456
- //add the prestringed versions e.g. 1 Peter
457
- for (let b = 0; b < preStringed.length; b++) {
458
- for (let pre = 0; pre < preStrings.length; pre++) {
459
- books.push(preStrings[pre] + " " + preStringed[b])
460
- }
461
- }
462
- // add the book name with . at the end as this seems to be added sometimes, at least to the shortened forms
463
- const length = books.length
464
- for (let b = 0; b < length; b++) {
465
- books.push(books[b] + ".")
466
- }
248
+ let verseIndex = chapterEndIndex + 1
249
+ let verseStartIndex = null
250
+ let verseEndIndex = null
251
+ let verse
252
+ while (verseIndex < text.length) {
253
+ const match = text.substring(verseIndex).match(/^\s*?(\d+)[^a-zA-Z]*/)
467
254
 
468
- // sort descending - longer items first
469
- books.sort((a, b) => b.length - a.length)
470
- let booksAt = []
471
- // go thro' each book finding where it matches in text
472
- for (let b = 0; b < books.length; b++) {
473
- const book = books[b]
474
- let chNoInText = 0
475
- while (chNoInText < text.length) {
476
- let j = text.indexOf(book, chNoInText)
477
- if (j < 0) break
478
- if (j + book.length < text.length && !text.charAt(j + book.length).match(/^[a-z]+$/)) {
479
- booksAt.push([book, j])
480
- let replacement = book
481
- for (let k = 0; k < book.length; k++) {
482
- replacement = replacement.replace(book.charAt(k), "X")
255
+ if (match) {
256
+ verseStartIndex = verseIndex
257
+ verseEndIndex = verseIndex + match[0].length
258
+ break
483
259
  }
484
- text = text.replace(book, replacement) // to prevent a shorter version matching
260
+ verseIndex++
261
+ }
262
+ verse = parseInt(text.substring(verseStartIndex, verseEndIndex))
263
+
264
+ if (chapter > 0) passage.chapter = chapter
265
+ if (verse > 0) passage.verse = verse
266
+
267
+ passage.index = {
268
+ start: index,
485
269
  }
486
- chNoInText = j + book.length + 1
270
+ found.push(passage)
487
271
  }
488
272
  }
489
- // into ascending order of start position
490
- booksAt.sort(function (a, b) {
491
- return a[1] - b[1]
492
- })
493
- let newText = ""
494
- let chNoInText = 0
495
- for (let b = 0; b < booksAt.length; b++) {
496
- while (chNoInText < booksAt[b][1]) {
497
- //copy across characters to start of book
498
- newText += text.charAt(chNoInText)
499
- chNoInText++
273
+ return found
274
+ }
275
+
276
+ regex(text) {
277
+ this.found = text.match(this.scripturesRegex)
278
+ console.log(this.found)
279
+ return this
280
+ }
281
+
282
+ regexParser() {
283
+ this.passages = []
284
+ for (let i = 0; i < this.found.length; i++) {
285
+ let verse, chapter
286
+ const hasChapterRange = this.found[i].match(/(?<=-\s?)\b\d+[.:].+\b/)
287
+ const book = this.found[i].match(this.bookRegex)
288
+ if (book === null) continue
289
+ chapter = this.found[i].replace(book[0], "").match(this.chapterRegex)
290
+
291
+ if (Array.isArray(chapter)) {
292
+ chapter = chapter[0]
293
+ }
294
+ if (
295
+ this.bookify(book).toLowerCase() === "jude" ||
296
+ this.bookify(book).toLowerCase() === "philemon" ||
297
+ this.bookify(book).toLowerCase() === "obadiah" ||
298
+ this.bookify(book).toLowerCase() === "2 john" ||
299
+ this.bookify(book).toLowerCase() === "3 john"
300
+ ) {
301
+ verse = this.found[i].split(" ")[1]
302
+ chapter = "1"
303
+ } else {
304
+ if (this.found[i].match(this.verseRegex))
305
+ verse = this.found[i].match(this.verseRegex)[0].replace(/[:.]/, "").trim()
500
306
  }
501
- newText += booksAt[b][0]
502
- chNoInText += booksAt[b][0].length //skip the 'fill-in characters
503
- for (let i = 0; i < 100; i++) {
504
- chNoInText++
505
- const nextCh = text.charAt(chNoInText)
506
- //test whether are at the end of the chapter(s) and verse(s)
507
- if (nextCh.match(/^[a-z]+$/)) break
508
- if (nextCh.match(/^[A-Z]+$/)) break
509
- newText += text.charAt(chNoInText - 1)
307
+ if (!verse && this.found[i].match(/\d+/)) {
308
+ chapter = this.found[i].match(/\d+/)[0]
510
309
  }
310
+
311
+ const passage = {
312
+ original: this.found[i].replace(/([.,])\1*$/, "").trim(),
313
+ book: this.bookify(book),
314
+ chapter: chapter,
315
+ verses: verse ?? [],
316
+ }
317
+
318
+ if (hasChapterRange) {
319
+ passage.to = {
320
+ book: passage.book,
321
+ chapter: hasChapterRange[0].match(this.chapterRegex),
322
+ verses: hasChapterRange[0].match(this.verseRegex)[0].replace(/[:.]/, "").trim(),
323
+ }
324
+ passage.to.verses = passage.to.verses.split(/,/).filter(Boolean)
325
+ passage.to.testament = this.bible.old.includes(passage.to.book) ? "old" : "new"
326
+ }
327
+ console.log(passage)
328
+ passage.verses =
329
+ typeof passage.verses !== "object"
330
+ ? passage.verses.split(/,/).filter(Boolean)
331
+ : passage.verses.filter((item) => item.trim())
332
+ passage.testament = this.bible.old.includes(passage.book) ? "old" : "new"
333
+ passage.scripture = this.scripturize(passage)
334
+ this.passages.push(passage)
511
335
  }
512
- return newText
336
+
337
+ this.found = []
338
+ return this
513
339
  }
514
340
  }
515
341
 
package/src/abbr.js CHANGED
@@ -258,10 +258,8 @@ const abbrevations = {
258
258
  L: "Luke",
259
259
  J: "John",
260
260
  Act: "Acts",
261
- R: "Romans",
262
261
  "1K": "1 Corinthians",
263
262
  "2K": "2 Corinthians",
264
- G: "Galatians",
265
263
  Ph: "Philippians",
266
264
  Kol: "Colossians",
267
265
  "1Th": "1 Thessalonians",
@@ -270,7 +268,6 @@ const abbrevations = {
270
268
  "2T": "2 Timothy",
271
269
  Tt: "Titus",
272
270
  Phm: "Philemon",
273
- H: "Hebrews",
274
271
  Jc: "James",
275
272
  "1P": "1 Peter",
276
273
  "2P": "2 Peter",
package/src/regex.js CHANGED
@@ -1,10 +1,11 @@
1
1
  const bookRegex =
2
2
  /((?:(I+|1st|2nd|3rd|First|Second|Third|[123])\s)?(Gen|Gn|Exo|Ex|Exod|Lev|Lv|Num|Nu|Nm|Nb|Deut|Dt|Josh|Jos|Jsh|Judg|Jdg|Jg|Jdgs|Rth|Ru|Sam|Samuel|Kings|Kgs|Chron|Chronicles|Ezra|Ezr|Ez|Neh|Ne|Esth|Job|Job|Jb|Pslm|Ps|Psalms|Psa|Psm|Pss|Prov|Pr|Prv|Eccles|Ec|Song|So|Canticles|Song of Songs|SOS|Isa|Is|Jer|Je|Jr|Lam|La|Ezek|Eze|Ezk|Dan|Da|Dn|Hos|Ho|Joel|Joe|Jl|Amos|Am|Obad|Ob|Jnh|Jon|Micah|Mic|Nah|Na|Hab|Zeph|Zep|Zp|Haggai|Hag|Hg|Zech|Zec|Zc|Mal|Mal|Ml|Matt|Mrk|Mk|Luk|Lk|John|Jn|Jhn|Acts|Ac|Rom|Ro|Rm|Co|Cor|Corinthians|Gal|Ga|Ephes|Eph|Phil|Php|Col|Col|Thes|Thess|Thessalonians|Ti|Tim|Timothy|Titus|Tit|Philem|Phm|Hebrews|Heb|He|James|Jas|Jm|Pe|Pet|Pt|Peter|Jn|Jo|Joh|Jhn|John|Jude|Jd|Jud|Jud|Rev|The Revelation|Genesis|Exodus|Leviticus|Numbers|Deuteronomy|Joshua|Judges|Ruth|Samuel|Kings|Chronicles|Ezra|Nehemiah|Esther|Job|Psalms|Psalm|Proverbs|Ecclesiastes|Song of Solomon|Isaiah|Jeremiah|Lamentations|Ezekiel|Daniel|Hosea|Joel|Amos|Obadiah|Jonah|Micah|Nahum|Habakkuk|Zephaniah|Haggai|Zechariah|Malachi|Matthew|Mark|Luke|John|Acts|Romans|Corinthians|Galatians|Ephesians|Philippians|Colossians|Thessalonians|Timothy|Titus|Philemon|Hebrews|James|Peter|John|Revelation|Re|Ap))/gim
3
- const chapterRegex = /\b(?:\.?\s?\d+[:|\.]?)\b/gm
4
- const verseRegex = /\b[:.].+\b/gm
3
+ const chapterRegex = /(\d+)(?=[:.])/gim
4
+ const verseRegex = /(?<=[:.])[\d: .\-]+(?:, ?[\d\-]+)*(?<![ .])/gim
5
5
  const chapterRange = /.?\s?(?:[-—–])\s?/gm
6
6
  const chapterRangeVerseRegex = /(?:.\d+)?/gm
7
- const chapterVerseRange = /.?\s?(?:\d+[:.])?\d+[a-e]?(?:(?:\s?[-–—]|,)(?!\s[1-3]\s+[A-Z])\s?(?:\d+[:.])?\d+[a-e]?)*/gim
7
+ const chapterVerseRange =
8
+ /(.?\s?\d+((?:[:.]\d+)?(\s?[-–—]\s?)?(?:\d+)(?:(,\s?\d+)*)?\S([:.]?\d+)?(,?\s?\d+[–—-]\s?\d+,?\d+)?)?(?:[:.]\d+)?(?:[abcde])?(?:,\d+)*(?:[-–—]\d?\s?)?)(?:[:.]\d+[–-—]\s?\d+,?\s?\d+)?/gim
8
9
  const scripturesRegex = new RegExp(`(${bookRegex.source})(${chapterVerseRange.source})`, "gmi")
9
10
  module.exports.bookRegex = bookRegex
10
11
  module.exports.chapterRegex = chapterRegex
@@ -4,8 +4,9 @@ const util = require("util")
4
4
  const dump = (item) => {
5
5
  console.log(util.inspect(item, { depth: null, colors: true }))
6
6
  }
7
- const string = "Genesis 1:1 John 1:1"
8
- console.log(string)
7
+ const string = "Malachi 3:32"
9
8
  const parser = new BibleParser()
9
+ parser.options({ invalid_passage_strategy: "include", invalid_sequence_strategy: "include" })
10
+ console.log(parser)
10
11
  const result = parser.parse(string)
11
12
  dump(result.getPassages())