codexparser 0.0.69 → 0.0.72

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_test.js CHANGED
@@ -6,7 +6,7 @@ const jd = "Jd. 5"
6
6
  const cor = "Hos 1:1-3, 8 Song of Solomon 1:2, Song of Songs 2:2. Ezek 17:3. Ezekiel 17:3 He 10:13 Rev 12:13"
7
7
 
8
8
  const parser = new bcv_parser()
9
- const textParser = parser.parse(text + single + jd + cor.replace(/He/, "Hebrews"))
9
+ const textParser = parser.parse("Gen 13:14-16 Clement of Letter to the Romanse, Letter to the Corinthians [51; 77; 111] 10:4-5; Jubilees [14; 43; 46; 118; 175; 179] 13:19-20; Genesis Apocryphon 21:8-10, 13 // Gen 13:15 Gal 3:16; Pseudo-Philo 8:3 Allusions - Jub 19:21-22; QapGn 21:8-10 // Gen 13:15 - Ac 7:5")
10
10
  const passages = textParser.parsed_entities()
11
11
 
12
12
  passages.forEach((passage) => {
package/mcleanTest.js ADDED
@@ -0,0 +1,14 @@
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
+
8
+ const parser = new BibleParser()
9
+
10
+ const text =
11
+ "Gen 1:1 - Jos Ant 1:27; Just Apol 1:59, 64; Mel Pasc 47; Ph Aet 19; Her 122; Opif 26-27; Theoph 2.10 Allusions Jn 1:1; Heb 11:3; DialSav 127:20; 4Ez 6:38; Mel Pasc 104; Ph QuGen 4:215; Opif 29; Mos 2:266; Plant 86; Praem 1; Sacrif 8; PrMan 2; Prov 8:22; Tat 5"
12
+
13
+ parser.find(text)
14
+ dump(parser.getPassages())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codexparser",
3
- "version": "0.0.69",
3
+ "version": "0.0.72",
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": {
@@ -91,6 +91,20 @@ class CodexParser {
91
91
  this.scan(reference)
92
92
  for (let i = 0; i < this.found.length; i++) {
93
93
  const result = this.found[i]
94
+ if (!result.entities[0].valid.valid) {
95
+ continue
96
+ }
97
+
98
+ if (result.type === "range" && result.start.b !== result.end.b) {
99
+ console.log("=================")
100
+ const newPassageFound = result.end.b + " " + result.end.c + ":" + result.end.v
101
+ const newPassageToAdd = this.crawler.parse(newPassageFound).parsed_entities()[0].entities
102
+ this.found.splice(i + 1, 0, ...newPassageToAdd)
103
+ result.end.b = result.start.b
104
+ result.end.c = result.start.c
105
+ result.end.v = result.start.v
106
+ }
107
+
94
108
  const passage = {
95
109
  book: this.bookify(result.start.b),
96
110
  chapter: result.start.c,
@@ -106,14 +120,16 @@ class CodexParser {
106
120
  next.start.b === result.end.b &&
107
121
  next.end.c === result.start.c
108
122
  ) {
109
- passage.verses.push(next.start.v)
110
- if (next.end.v !== next.start.v) passage.verses.push(next.end.v)
111
- passage.subType = next.type
123
+ if (next.start.v > result.start.v) {
124
+ passage.verses.push(next.start.v)
125
+ if (next.end.v !== next.start.v) passage.verses.push(next.end.v)
126
+ passage.subType = next.type
127
+ }
112
128
  i++
113
129
  next = this.found[i + 1]
114
130
  }
115
131
  }
116
- if (passage.type === "range") {
132
+ if (passage.type === "range" && passage.book === result.end.b) {
117
133
  if (result.start.c !== result.end.c) {
118
134
  passage.verses = [result.start.v]
119
135
  passage.to = {
@@ -146,7 +162,11 @@ class CodexParser {
146
162
  versify(passage) {
147
163
  if (passage.start.v !== passage.end.v) {
148
164
  if (passage.type === "range") {
149
- return [`${passage.start.v}-${passage.end.v}`]
165
+ if (passage.start.b === passage.end.b) {
166
+ return [`${passage.start.v}-${passage.end.v}`]
167
+ } else {
168
+ return [passage.start.v]
169
+ }
150
170
  } else {
151
171
  if (passage.type !== "bc") {
152
172
  const verses = []
@@ -215,16 +235,15 @@ class CodexParser {
215
235
  .trim()
216
236
  }
217
237
  find(text) {
218
- const books = [...this.bible.old, ...this.bible.new]
219
- const found = []
220
- const passages = []
238
+ const bookNames = this.bookRegex.toString().split("|").slice(8)
239
+ const books = [...this.bible.old, ...this.bible.new, ...bookNames]
221
240
  for (let i = 0; i < books.length; i++) {
222
241
  const book = books[i].toLowerCase()
223
242
  const index = text.toLowerCase().indexOf(book)
224
243
  // Checks to see if the previous character is a colon. If it is, skip.
225
244
  // This makes sure that if you have a case like Genesis 1:1 John 1:1, the code knows that
226
245
  // the book cannot be 1 John.
227
- if (text[index - 1] && text[index - 1].includes(":")) continue
246
+ if (text[index - 1] && text[index - 1].includes(":") && text[index - 1].match(/[a-zA-Z]/)) continue
228
247
 
229
248
  // Get the book and chapter
230
249
  if (index > -1) {
@@ -236,10 +255,10 @@ class CodexParser {
236
255
  let chapterStartIndex = null
237
256
  let chapterEndIndex = null
238
257
  let j = bookEndIndex + 1
239
- while (j < text.length) {
258
+ while (j < text.length && !text[j].match(/[a-zA-Z]/)) {
240
259
  const match = text.substring(j).match(/^\s*(\d+)/)
241
260
  if (match) {
242
- chapter = match[1]
261
+ chapter = parseInt(match[1])
243
262
  chapterStartIndex = j
244
263
  chapterEndIndex = j + match[0].length
245
264
  break
@@ -251,9 +270,8 @@ class CodexParser {
251
270
  let verseStartIndex = null
252
271
  let verseEndIndex = null
253
272
  let verse
254
- while (verseIndex < text.length) {
273
+ while (verseIndex < text.length && !text[verseIndex].match(/[a-zA-Z]/)) {
255
274
  const match = text.substring(verseIndex).match(/^\s*?(\d+)[^a-zA-Z]*/)
256
-
257
275
  if (match) {
258
276
  verseStartIndex = verseIndex
259
277
  verseEndIndex = verseIndex + match[0].length
@@ -269,14 +287,15 @@ class CodexParser {
269
287
  passage.index = {
270
288
  start: index,
271
289
  }
272
- found.push(passage)
290
+ this.passages.push(passage)
273
291
  }
274
292
  }
275
- return found
293
+ return this
276
294
  }
277
295
 
278
296
  regex(text) {
279
297
  this.found = text.match(this.scripturesRegex)
298
+ console.log(this.found)
280
299
  return this
281
300
  }
282
301
 
@@ -339,7 +358,7 @@ class CodexParser {
339
358
  this.passages.push(passage)
340
359
  }
341
360
 
342
- this.found = []
361
+ this.found = this.passages.map((passage) => passage.scripture)
343
362
  return this
344
363
  }
345
364
  }
package/src/regex.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const bookRegex =
2
- /((?:(I+|1st|2nd|3rd|First|Second|Third|[123])\s?)?(Gen|Ge|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|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|Php|Col|Col|Thes|Thess|Thessalonians|Ti|Tim|Timothy|Titus|Tit|Philem|Phm|Phlm|Phile|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|Matt|Mt|Mc|Mark|Luke|John|Acts|Romans|Corinthians|Galatians|Ephesians|Philippians|Phil|Colossians|Thessalonians|Timothy|Titus|Philemon|Hebrews|James|Peter|John|Revelation|Re|Ap))/gim
2
+ /((?:(I+|1st|2nd|3rd|First|Second|Third|[123])\s?)?(Gen|Ge|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|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|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|Php|Col|Col|Thes|Thess|Thessalonians|Ti|Tim|Timothy|Titus|Tit|Philem|Phm|Phlm|Phile|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|Matt|Mt|Mc|Mark|Luke|John|Acts|Romans|Corinthians|Galatians|Ephesians|Philippians|Phil|Colossians|Thessalonians|Timothy|Titus|Philemon|Hebrews|James|Peter|John|Revelation|Re|Ap))/gim
3
3
  const EzraAbbrv = /(Ez)(?![a-zA-Z])/gim
4
4
  const chapterRegex = /(\d+)(?=[:.])/gim
5
5
  const verseRegex = /(?<=[:.])[\d: .\-]+(?:, ?[\d\-]+)*(?<![ .])/gim
@@ -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("Ex 9.16 LXX")
14
+ const result = parser.parse("2Cor 4:6; 4Ez 6:40")
15
15
  dump(result.getPassages())