codexparser 0.0.41 → 0.0.43

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.
@@ -5,7 +5,9 @@ const text =
5
5
  "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
6
  const single = "Ge 27.27-29,32-40 Heb 11.20 Heb. 12.17 Jonah 3"
7
7
  const jd = "Jd. 5"
8
- const cor = "Hos 1:1-3, 8 Song of Solomon 1:2, Song of Songs 2:2. Ezek 17:3. Ezekiel 17:3 He 12:13-15"
8
+ const cor = "Song of Solomon 1:2, Song of Songs 2:2. Ezek 17:3. He 12:13-15 Hos 1:1-3, 8 "
9
9
  const passages = parser.parse(single + " " + text + " " + jd + " " + cor)
10
- console.log(passages.getPassages())
10
+ passages.getPassages().forEach(passage => {
11
+ console.log(passage)
12
+ })
11
13
  //const passages = parser.parse('Romans 8:9,12,15,17,20,28')
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "codexparser",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
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": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1",
8
- "webpack": "webpack --mode=production",
8
+ "webpack": "webpack --mode=production",
9
9
  "build": "browserify src/CodexParser.js -t | uglifyjs > dist/CodexParser.js"
10
10
  },
11
11
  "author": "Jeremy Menicucci",
@@ -22,11 +22,12 @@
22
22
  "glob": "^10.4.1",
23
23
  "path": "^0.12.7",
24
24
  "uglify-es": "^3.3.9",
25
- "uglifyify": "^5.0.2",
25
+ "uglifyify": "^5.0.0",
26
26
  "webpack": "^5.90.3",
27
27
  "webpack-cli": "^5.1.4"
28
28
  },
29
29
  "dependencies": {
30
- "bible-passage-reference-parser": "^2.0.1"
30
+ "bible-passage-reference-parser": "^2.0.1",
31
+ "unidecode": "^1.1.0"
31
32
  }
32
33
  }
package/quicktest.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const BibleParser = require("./src/CodexParser.js")
2
- const string = "He 4.4"
2
+ const string = "Genesis 1:1 He 4.4"
3
3
  const parser = new BibleParser()
4
4
  const result = parser.parse(string)
5
5
  console.log(result.getPassages())
@@ -0,0 +1,317 @@
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
+ //add the prestringed versions e.g. 1 Peter
261
+ for (let b = 0; b < preStringed.length; b++) {
262
+ for (let pre = 0; pre < preStrings.length; pre++) {
263
+ books.push(preStrings[pre] + " " + preStringed[b])
264
+ }
265
+ }
266
+ // add the book name with . at the end as this seems to be added sometimes, at least to the shortened forms
267
+ const length = books.length
268
+ for (let b = 0; b < length; b++) {
269
+ books.push(books[b] + ".")
270
+ }
271
+
272
+ // sort descending - longer items first
273
+ books.sort((a, b) => b.length - a.length)
274
+ let booksAt = []
275
+ // go thro' each book finding where it matches in text
276
+ for (let b = 0; b < books.length; b++) {
277
+ const book = books[b]
278
+ let chNoInText = 0
279
+ while (chNoInText < text.length) {
280
+ let j = text.indexOf(book, chNoInText)
281
+ if (j < 0) break
282
+ if (j + book.length < text.length && !text.charAt(j + book.length).match(/^[a-z]+$/)) {
283
+ booksAt.push([book, j])
284
+ let replacement = book
285
+ for (let k = 0; k < book.length; k++) {
286
+ replacement = replacement.replace(book.charAt(k), "X")
287
+ }
288
+ text = text.replace(book, replacement) // to prevent a shorter version matching
289
+ }
290
+ chNoInText = j + book.length + 1
291
+ }
292
+ }
293
+ // into ascending order of start position
294
+ booksAt.sort(function (a, b) {
295
+ return a[1] - b[1]
296
+ })
297
+ newText = ""
298
+ let chNoInText = 0
299
+ for (let b = 0; b < booksAt.length; b++) {
300
+ while (chNoInText < booksAt[b][1]) {
301
+ //copy across characters to start of book
302
+ newText += text.charAt(chNoInText)
303
+ chNoInText++
304
+ }
305
+ newText += "<span>" + booksAt[b][0] + "</span><span>"
306
+ chNoInText += booksAt[b][0].length //skip the 'fill-in characters
307
+ for (let i = 0; i < 100; i++) {
308
+ chNoInText++
309
+ const nextCh = text.charAt(chNoInText)
310
+ //test whether are at the end of the chapter(s) and verse(s)
311
+ if (nextCh.match(/^[a-z]+$/)) break
312
+ if (nextCh.match(/^[A-Z]+$/)) break
313
+ newText += text.charAt(chNoInText - 1)
314
+ }
315
+ newText += "</span>&nbsp;"
316
+ }
317
+ document.querySelector("div").innerHTML = newText
@@ -27,25 +27,31 @@ class CodexParser {
27
27
  * @return {array} The found passages from the text.
28
28
  */
29
29
  scan(text) {
30
- text = text.trim()
31
- console.log(text)
32
- const abbrs = text.matchAll(/He(?=.\d)/gim)
33
- if (abbrs) {
34
- const matches = [...abbrs].map((match) => {
35
- return {
36
- abbr: match[0],
37
- book: this.bookify(match[0]),
38
- index: match.index,
39
- }
30
+ const regex = /(?:He(?=\s?\d+))/g
31
+ let match
32
+ const matches = []
33
+
34
+ while ((match = regex.exec(text)) !== null) {
35
+ const index = match.index
36
+ const book = this.bookify(match[0])
37
+ matches.push({
38
+ abbr: match[0],
39
+ book: book,
40
+ index: index,
40
41
  })
41
- console.log(matches)
42
- for (let i = matches.length - 1; i >= 0; i--) {
43
- const match = matches[i]
44
- text = text.substring(0, match.index) + match.book + text.substring(match.index + match.abbr.length)
45
- }
42
+ }
43
+ for (let i = matches.length - 1; i >= 0; i--) {
44
+ const match = matches[i]
45
+ text = text.substring(0, match.index) + match.book + text.substring(match.index + match.abbr.length)
46
46
  }
47
47
  const passages = this.crawler.parse(text).parsed_entities()
48
- this.found.push(...passages.flatMap((passage) => passage.entities))
48
+ for (let j = 0; j < passages.length; j++) {
49
+ const passage = passages[j]
50
+ for (let i = 0; i < passage.entities.length; i++) {
51
+ const entity = passage.entities[i]
52
+ this.found.push(entity)
53
+ }
54
+ }
49
55
  }
50
56
 
51
57
  /**
@@ -55,8 +61,9 @@ class CodexParser {
55
61
  * @return {array} An array of parsed passages.
56
62
  */
57
63
  parse(reference) {
64
+ //TODO: Need to fix chapter ranges when another verse is tacted onto the end of it.
58
65
  if (!reference) {
59
- throw new Error("Parse error (parse(), line 46): reference is undefined")
66
+ throw new Error("Parse error (parse(): reference is undefined")
60
67
  }
61
68
  this.passages = []
62
69
  this.scan(reference)
@@ -74,6 +81,10 @@ class CodexParser {
74
81
  //console.log(booksWithResults)
75
82
  for (let i = 0; i < booksWithResults.length; i++) {
76
83
  const initialPassage = booksWithResults[i].shift()
84
+ const shouldBeRange = initialPassage.osis.match(/[-–—]/)
85
+ if(shouldBeRange && initialPassage.type !== "range") {
86
+ initialPassage.type = "range"
87
+ }
77
88
  const firstPassage = {
78
89
  original: initialPassage.osis,
79
90
  book: this.bookify(initialPassage.start.b),
@@ -155,50 +166,6 @@ class CodexParser {
155
166
  }
156
167
  this.found = []
157
168
  return this
158
- //console.log(booksWithResults)
159
- /* for (let i = 0; i < this.found.length; i++) {
160
- const hasChapterRange = this.found[i].match(/(?<=-\s?)\b\d+[.:].+\b/)
161
- const book = this.found[i].match(this.bookRegex)
162
- if (book === null) continue
163
- let verse,
164
- chapter = this.found[i].replace(book[0], "").match(this.chapterRegex)
165
- if (this.found[i].match(this.verseRegex))
166
- verse = this.found[i].match(this.verseRegex)[0].replace(/[:.]/, "").trim()
167
- else {
168
- if (this.bookify(book).toLowerCase() === "jude" || this.bookify(book).toLowerCase() === "philemon") {
169
- verse = chapter
170
- chapter = "1"
171
- } else {
172
- verse = []
173
- }
174
- }
175
- const passage = {
176
- original: this.found[i].replace(/([.,])\1*$/, "").trim(),
177
- book: this.bookify(book),
178
- chapter: this.chapterify(chapter),
179
- verses: verse,
180
- }
181
-
182
- if (hasChapterRange) {
183
- passage.to = {
184
- book: passage.book,
185
- chapter: this.chapterify(hasChapterRange[0].match(this.chapterRegex)),
186
- verses: hasChapterRange[0].match(this.verseRegex)[0].replace(/[:.]/, "").trim(),
187
- }
188
- passage.to.verses = passage.to.verses.split(/,/).filter(Boolean)
189
- passage.to.testament = this.bible.old.includes(passage.to.book) ? "old" : "new"
190
- }
191
- passage.verses =
192
- typeof passage.verses !== "object"
193
- ? passage.verses.split(/,/).filter(Boolean)
194
- : passage.verses.filter((item) => item.trim())
195
- passage.testament = this.bible.old.includes(passage.book) ? "old" : "new"
196
- passage.scripture = this.scripturize(passage)
197
- this.passages.push(passage)
198
- }
199
-
200
- this.found = []
201
- return this.passages */
202
169
  }
203
170
  chapterify(chapter) {
204
171
  if (chapter.type === "range") {
package/src/regex.js CHANGED
@@ -4,7 +4,7 @@ const verseRegex = /\b[:.].+\b/gm
4
4
  const chapterRange = /.?\s?(?:[-—–])\s?/gm
5
5
  const chapterRangeVerseRegex = /(?:.\d+)?/gm
6
6
  const chapterVerseRange =
7
- /\.?\s(?:\d+[:.])?\d+[a-e]?(?:(?:\s?[-–—]|,)(?!\s[1-3]\s+[A-Z])\s?(?:\d+[:.])?\d+[a-e]?)*/gim
7
+ /.?\s?(?:\d+[:.])?\d+[a-e]?(?:(?:\s?[-–—]|,)(?!\s[1-3]\s+[A-Z])\s?(?:\d+[:.])?\d+[a-e]?)*/gim
8
8
  const scripturesRegex = new RegExp(`(${bookRegex.source})(${chapterVerseRange.source})`, "gmi")
9
9
  module.exports.bookRegex = bookRegex
10
10
  module.exports.chapterRegex = chapterRegex
@@ -1,5 +1,5 @@
1
1
  const BibleParser = require("./src/CodexParser.js")
2
+ const string = "Ps 109:4,5,6,8"
2
3
  const parser = new BibleParser()
3
- const string = "Genesis 1.1 He 4.4"
4
4
  const result = parser.parse(string)
5
- console.log(result.getPassages())
5
+ console.log(result.getPassages())