codexparser 0.0.58 → 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.
- package/bcv-single-test.js +12 -4
- package/jstester.js +320 -0
- package/package.json +1 -1
- package/regex-tester.js +21 -0
- package/scan-test.js +23 -0
- package/src/CodexParser.js +134 -1
- package/src/abbr.js +0 -3
- package/src/regex.js +4 -3
- package/sub-verse-scripture-test.js +3 -1
package/bcv-single-test.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
const bcv_parser = require("bible-passage-reference-parser/js/en_bcv_parser").bcv_parser
|
|
2
|
-
const
|
|
2
|
+
const util = require("util")
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const dump = (item) => {
|
|
5
|
+
console.log(util.inspect(item, { depth: null, colors: true }))
|
|
6
|
+
}
|
|
7
|
+
const text = "Malachi 3:23"
|
|
8
|
+
|
|
9
|
+
const parser = new bcv_parser({
|
|
10
|
+
invalid_sequence_strategy: "include",
|
|
11
|
+
invalid_passage_strategy: "include",
|
|
12
|
+
})
|
|
5
13
|
const textParser = parser.parse(text)
|
|
6
14
|
const passages = textParser.parsed_entities()
|
|
7
15
|
passages.forEach((passage) => {
|
|
8
|
-
|
|
9
|
-
})
|
|
16
|
+
dump(passage)
|
|
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.
|
|
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": {
|
package/regex-tester.js
ADDED
|
@@ -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
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const BibleParser = require("./src/CodexParser.js")
|
|
2
|
+
const util = require("util")
|
|
3
|
+
|
|
4
|
+
const dump = (item) => {
|
|
5
|
+
console.log(util.inspect(item, { depth: null, colors: true }))
|
|
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`
|
|
21
|
+
const parser = new BibleParser()
|
|
22
|
+
const result = parser.find(text)
|
|
23
|
+
dump(result)
|
package/src/CodexParser.js
CHANGED
|
@@ -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
|
-
|
|
81
|
+
this.passages = []
|
|
82
|
+
return this
|
|
75
83
|
}
|
|
76
84
|
this.passages = []
|
|
77
85
|
this.scan(reference)
|
|
@@ -204,6 +212,131 @@ class CodexParser {
|
|
|
204
212
|
.replace(/\s+:\s+/g, ":")
|
|
205
213
|
.trim()
|
|
206
214
|
}
|
|
215
|
+
find(text) {
|
|
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
|
|
226
|
+
|
|
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
|
+
}
|
|
247
|
+
|
|
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]*/)
|
|
254
|
+
|
|
255
|
+
if (match) {
|
|
256
|
+
verseStartIndex = verseIndex
|
|
257
|
+
verseEndIndex = verseIndex + match[0].length
|
|
258
|
+
break
|
|
259
|
+
}
|
|
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,
|
|
269
|
+
}
|
|
270
|
+
found.push(passage)
|
|
271
|
+
}
|
|
272
|
+
}
|
|
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()
|
|
306
|
+
}
|
|
307
|
+
if (!verse && this.found[i].match(/\d+/)) {
|
|
308
|
+
chapter = this.found[i].match(/\d+/)[0]
|
|
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)
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
this.found = []
|
|
338
|
+
return this
|
|
339
|
+
}
|
|
207
340
|
}
|
|
208
341
|
|
|
209
342
|
module.exports = CodexParser
|
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 =
|
|
4
|
-
const verseRegex =
|
|
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 =
|
|
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,7 +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 = "
|
|
7
|
+
const string = "Malachi 3:32"
|
|
8
8
|
const parser = new BibleParser()
|
|
9
|
+
parser.options({ invalid_passage_strategy: "include", invalid_sequence_strategy: "include" })
|
|
10
|
+
console.log(parser)
|
|
9
11
|
const result = parser.parse(string)
|
|
10
12
|
dump(result.getPassages())
|