codexparser 0.0.49 → 0.0.51

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.
@@ -1,13 +1,18 @@
1
1
  const CodexParser = 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
+ }
2
7
 
3
8
  const parser = new CodexParser()
4
9
  const text =
5
10
  "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
11
  const single = "Ge 27.27-29,89-40 Heb 11.20 Heb. 12.17 Jonah 3"
7
12
  const jd = "Jd. 5"
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
- const passages = parser.parse(single + " " + text + " " + jd + " " + cor)
13
+ const cor = "1 Cor 12:4 2 Cor 3:4"
14
+ const noSpace = "Re13.8"
15
+ const passages = parser.parse(text)
10
16
  passages.getPassages().forEach((passage) => {
11
- console.log(passage)
17
+ dump(passage)
12
18
  })
13
- //const passages = parser.parse('Romans 8:9,12,15,17,20,28')
@@ -0,0 +1,9 @@
1
+ const bcv_parser = require("bible-passage-reference-parser/js/en_bcv_parser").bcv_parser
2
+ const text = "Revelation 3:5; 7:14; 12:7; 13:8; 16:18; 20:1-6"
3
+
4
+ const parser = new bcv_parser()
5
+ const textParser = parser.parse(text)
6
+ const passages = textParser.parsed_entities()
7
+ passages.forEach((passage) => {
8
+ console.log(passage)
9
+ })
@@ -1,5 +1,5 @@
1
1
  const BibleParser = require("./src/CodexParser.js")
2
- const string = "Psalms 113-118"
2
+ const string = "Revelation 3:5; 7:14; 12:7; 13:8; 16:18; 20:1-6"
3
3
  const parser = new BibleParser()
4
4
  const passages = parser.parse(string)
5
- console.log(passages.getPassages()[0])
5
+ //console.log(passages.getPassages())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codexparser",
3
- "version": "0.0.49",
3
+ "version": "0.0.51",
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": {
@@ -3,6 +3,11 @@ const { bookRegex, chapterRegex, verseRegex, scripturesRegex } = require("./rege
3
3
  const abbrevations = require("./abbr")
4
4
  const toc = require("./toc")
5
5
  const crawler = require("bible-passage-reference-parser/js/en_bcv_parser").bcv_parser
6
+ const util = require("util")
7
+
8
+ const dump = (item) => {
9
+ console.log(util.inspect(item, { depth: null, colors: true }))
10
+ }
6
11
 
7
12
  class CodexParser {
8
13
  constructor() {
@@ -47,6 +52,7 @@ class CodexParser {
47
52
  text = text.substring(0, match.index) + match.book + text.substring(match.index + match.abbr.length)
48
53
  }
49
54
  const passages = this.crawler.parse(text).parsed_entities()
55
+
50
56
  for (let j = 0; j < passages.length; j++) {
51
57
  const passage = passages[j]
52
58
  for (let i = 0; i < passage.entities.length; i++) {
@@ -74,99 +80,48 @@ class CodexParser {
74
80
  books.push(this.found[i].start.b)
75
81
  }
76
82
  const uniqueBooks = [...new Set(books)]
77
- const booksWithResults = []
78
83
 
84
+ const booksWithResults = []
79
85
  for (const book of uniqueBooks) {
80
86
  const found = this.found.filter((passage) => passage.start.b === book)
81
87
  booksWithResults.push(found)
82
88
  }
89
+
83
90
  for (let i = 0; i < booksWithResults.length; i++) {
84
- const initialPassage = booksWithResults[i].shift()
85
- const shouldBeRange = initialPassage.osis.match(/[-–—]/)
86
- if (shouldBeRange && initialPassage.type !== "range") {
87
- if (initialPassage.end.v - initialPassage.start.v > 1) {
88
- initialPassage.type = "range"
91
+ const results = booksWithResults[i]
92
+ for (let j = 0; j < results.length; j++) {
93
+ const result = results[j]
94
+ const passage = {
95
+ book: this.bookify(result.start.b),
96
+ chapter: result.start.c,
97
+ verses: this.versify(result),
98
+ type: result.type,
89
99
  }
90
- }
91
- const firstPassage = {
92
- original: initialPassage.osis,
93
- book: this.bookify(initialPassage.start.b),
94
- chapter: initialPassage.start.c,
95
- type: initialPassage.type,
96
- entities: initialPassage.entities,
97
- }
98
- if (initialPassage.type === "range") {
99
- if (initialPassage.start.c !== initialPassage.end.c) {
100
- firstPassage.verses = [initialPassage.start.v]
101
- firstPassage.to = {
102
- book: this.bookify(initialPassage.end.b),
103
- chapter: initialPassage.end.c,
104
- verses: [initialPassage.end.v],
105
- }
106
- } else {
107
- firstPassage.verses = [initialPassage.start.v + "-" + initialPassage.end.v]
100
+ let next = results[j + 1]
101
+ while (next && next.type === "integer" && next.end.c === result.start.c) {
102
+ passage.verses.push(next.start.v)
103
+ passage.subType = next.type
104
+ j++
105
+ next = results[j + 1]
108
106
  }
109
- } else {
110
- firstPassage.verses =
111
- initialPassage.start.v !== initialPassage.end.v
112
- ? [initialPassage.start.v, initialPassage.end.v]
113
- : [initialPassage.start.v]
114
- }
115
- for (let j = 0; j < booksWithResults[i].length; j++) {
116
- const passage = booksWithResults[i][j]
117
- if (passage.type === "integer") {
118
- if (firstPassage.type === "range") {
119
- if (passage.start.c !== passage.end.c) {
120
- firstPassage.to.verses.push(passage.start.v)
121
- } else {
122
- firstPassage.verses.push(passage.start.v)
107
+ if (passage.type === "range") {
108
+ if (result.start.c !== result.end.c) {
109
+ passage.verses = [result.start.v]
110
+ passage.to = {
111
+ book: this.bookify(result.end.b),
112
+ chapter: result.end.c,
113
+ verses: result.end.v,
123
114
  }
124
- firstPassage.original += ", " + passage.start.v
125
- } else {
126
- if (passage.start.v !== passage.end.v) {
127
- firstPassage.verses.push(passage.start.v)
128
- firstPassage.verses.push(passage.end.v)
129
- firstPassage.original += ", " + passage.start.v + ", " + passage.end.v
130
- } else {
131
- firstPassage.verses.push(passage.start.v)
132
- firstPassage.original += ", " + passage.start.v
133
- }
134
- }
135
- } else if (passage.type === "range") {
136
- if (firstPassage.chapter === passage.start.c) {
137
- firstPassage.verses.push(passage.start.v + "-" + passage.end.v)
138
- }
139
- } else {
140
- const subPassage = {
141
- original: passage.osis,
142
- book: this.bookify(passage.start.b),
143
- chapter: passage.start.c,
144
- type: passage.type,
145
- entities: passage.entities,
146
- }
147
- if (passage.type === "range") {
148
- if (passage.start.c !== passage.end.c) {
149
- subPassage.to = {
150
- book: this.bookify(passage.end.b),
151
- chapter: passage.end.c,
152
- verses: [passage.end.v],
153
- }
154
- } else {
155
- subPassage.verses =
156
- passage.start.v !== passage.end.v ? [passage.start.v, passage.end.v] : [passage.start.v]
157
- }
158
- } else {
159
- subPassage.verses =
160
- passage.start.v !== passage.end.v ? [passage.start.v, passage.end.v] : [passage.start.v]
161
115
  }
162
- subPassage.testament = this.bible.old.includes(subPassage.book) ? "old" : "new"
163
- this.passages.push(subPassage)
164
116
  }
117
+ passage.original = result.osis
118
+ passage.scripture = this.scripturize(passage)
119
+ passage.indices = result.indices
120
+ passage.entities = result.entities
121
+ this.passages.push(passage)
165
122
  }
166
- firstPassage.testament = this.bible.old.includes(firstPassage.book) ? "old" : "new"
167
- this.passages.push(firstPassage)
168
- //console.log(this.passages)
169
123
  }
124
+ this.passages.sort((a, b) => a.chapter - b.chapter)
170
125
  this.found = []
171
126
  return this
172
127
  }
@@ -176,10 +131,25 @@ class CodexParser {
176
131
  }
177
132
  }
178
133
 
179
- versify(passage, type) {
180
- if (type !== "range")
181
- return passage.start.v !== passage.end.v ? [passage.start.v, passage.end.v] : [passage.start.v]
182
- else return [passage.start.v + "-" + passage.end.v]
134
+ versify(passage) {
135
+ const singleBooks = ["Obadiah", "Philemon", "2 John", "3 John", "Jude"]
136
+ if (passage.start.b && singleBooks.includes(passage.start.b)) {
137
+ return [passage.start.v + "-" + passage.end.v]
138
+ } else {
139
+ if (passage.start.v !== passage.end.v) {
140
+ if (passage.type === "range") {
141
+ return [`${passage.start.v}-${passage.end.v}`]
142
+ } else {
143
+ const verses = []
144
+ for (let i = passage.start.v; i <= passage.end.v; i++) {
145
+ verses.push(i)
146
+ }
147
+ return verses
148
+ }
149
+ } else {
150
+ return [passage.start.v]
151
+ }
152
+ }
183
153
  }
184
154
 
185
155
  /**
@@ -224,7 +194,6 @@ class CodexParser {
224
194
  * @param {object} passage - A passage object
225
195
  */
226
196
  scripturize(passage) {
227
- console.log(passage)
228
197
  const { book, chapter, verses, to } = passage
229
198
  const colon = verses.length !== 0 ? ":" : ""
230
199
  const parts = [book, chapter, colon, verses]
@@ -1,5 +1,10 @@
1
1
  const BibleParser = require("./src/CodexParser.js")
2
- const string = "Romans 9:32 Romans 9:33"
2
+ const util = require("util")
3
+
4
+ const dump = (item) => {
5
+ console.log(util.inspect(item, { depth: null, colors: true }))
6
+ }
7
+ const string = "Psalm 109-110"
3
8
  const parser = new BibleParser()
4
9
  const result = parser.parse(string)
5
- console.log(result.getPassages())
10
+ dump(result.getPassages())