codexparser 0.0.14 → 0.0.18
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/package.json +1 -1
- package/src/CodexParser.js +45 -9
- package/src/regex.js +7 -12
- package/test.js +5 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codexparser",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
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/src/CodexParser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const bible = require("./bible")
|
|
2
|
-
const { bookRegex,
|
|
2
|
+
const { bookRegex, chapterRegex, verseRegex, scripturesRegex } = require("./regex")
|
|
3
3
|
const abbrevations = require("./abbr")
|
|
4
4
|
const toc = require("./toc")
|
|
5
5
|
|
|
@@ -9,11 +9,9 @@ class CodexParser {
|
|
|
9
9
|
this.passages = []
|
|
10
10
|
this.bible = bible
|
|
11
11
|
this.bookRegex = bookRegex
|
|
12
|
-
this.bookAbbrRegex = bookAbbrRegex
|
|
13
12
|
this.chapterRegex = chapterRegex
|
|
14
13
|
this.verseRegex = verseRegex
|
|
15
14
|
this.scripturesRegex = scripturesRegex
|
|
16
|
-
this.abbrScripturesRegex = abbrScripturesRegex
|
|
17
15
|
this.abbrevations = abbrevations
|
|
18
16
|
this.toc = toc
|
|
19
17
|
}
|
|
@@ -41,26 +39,49 @@ class CodexParser {
|
|
|
41
39
|
}
|
|
42
40
|
this.passages = []
|
|
43
41
|
this.scan(reference)
|
|
44
|
-
console.log(this.found)
|
|
45
42
|
for (let i = 0; i < this.found.length; i++) {
|
|
43
|
+
const hasChapterRange = this.found[i].match(/(?<=-\s?)\b\d+[.:].+\b/)
|
|
46
44
|
const book = this.found[i].match(this.bookRegex)
|
|
47
45
|
const chapter = this.found[i].replace(book[0], "").match(this.chapterRegex)
|
|
46
|
+
const verse = this.found[i].match(this.verseRegex)[0].replace(/[:.]/, "").trim()
|
|
48
47
|
const passage = {
|
|
49
48
|
original: this.found[i],
|
|
50
|
-
book: this.bookify(book
|
|
51
|
-
chapter:
|
|
52
|
-
verses:
|
|
49
|
+
book: this.bookify(book),
|
|
50
|
+
chapter: this.chapterify(chapter),
|
|
51
|
+
verses: verse,
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (hasChapterRange) {
|
|
55
|
+
passage.to = {
|
|
56
|
+
book: passage.book,
|
|
57
|
+
chapter: this.chapterify(hasChapterRange[0].match(this.chapterRegex)),
|
|
58
|
+
verses: hasChapterRange[0].match(this.verseRegex)[0].replace(/[:.]/, "").trim(),
|
|
59
|
+
}
|
|
60
|
+
passage.to.verses = passage.to.verses.split(/,/).filter(Boolean)
|
|
61
|
+
passage.to.testament = this.bible.old.includes(passage.to.book) ? "old" : "new"
|
|
53
62
|
}
|
|
54
63
|
passage.verses = passage.verses.split(/,/).filter(Boolean)
|
|
55
64
|
passage.testament = this.bible.old.includes(passage.book) ? "old" : "new"
|
|
65
|
+
passage.scripture = this.scripturize(passage)
|
|
56
66
|
this.passages.push(passage)
|
|
57
67
|
}
|
|
68
|
+
|
|
58
69
|
this.found = []
|
|
59
70
|
return this.passages
|
|
60
71
|
}
|
|
72
|
+
chapterify(chapter) {
|
|
73
|
+
return chapter[0].replace(/[:\.]/, "").trim()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Converts a book name to its corresponding full name from the bible.
|
|
78
|
+
*
|
|
79
|
+
* @param {string} book - The abbreviated or partial name of the book.
|
|
80
|
+
* @return {string|undefined} The full name of the book if found, otherwise undefined.
|
|
81
|
+
*/
|
|
61
82
|
bookify(book) {
|
|
62
83
|
let bookified
|
|
63
|
-
|
|
84
|
+
book = book[0].charAt(0).toUpperCase() + book[0].slice(1)
|
|
64
85
|
bookified = this.abbrevations[book]
|
|
65
86
|
|
|
66
87
|
if (!bookified) {
|
|
@@ -79,7 +100,7 @@ class CodexParser {
|
|
|
79
100
|
}
|
|
80
101
|
return bookified
|
|
81
102
|
}
|
|
82
|
-
|
|
103
|
+
|
|
83
104
|
/**
|
|
84
105
|
* Returns the passages stored in the object.
|
|
85
106
|
*
|
|
@@ -88,6 +109,21 @@ class CodexParser {
|
|
|
88
109
|
getPassages() {
|
|
89
110
|
return this.passages
|
|
90
111
|
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @param {object} passage - A passage object
|
|
115
|
+
*/
|
|
116
|
+
scripturize(passage) {
|
|
117
|
+
const { book, chapter, verses, to } = passage
|
|
118
|
+
const parts = [book, chapter, ":", verses]
|
|
119
|
+
if (to) {
|
|
120
|
+
parts.push("-", to.chapter, ":", to.verses)
|
|
121
|
+
}
|
|
122
|
+
return parts
|
|
123
|
+
.join(" ")
|
|
124
|
+
.replace(/\s+:\s+/g, ":")
|
|
125
|
+
.trim()
|
|
126
|
+
}
|
|
91
127
|
}
|
|
92
128
|
|
|
93
129
|
module.exports = CodexParser
|
package/src/regex.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
const bookRegex =
|
|
2
|
-
/(?:(?:[gG]e(?:[a-zA-Z]+)?|[eE]x(?:[a-zA-Z]+)?|[lL]e(?:[a-zA-Z]+)?|[nN]u(?:[a-zA-Z]+)?|[dD]e(?:[a-zA-Z]+)?|[jJ]o(?:[a-zA-Z]+)?|[jJ]u(?:[a-zA-Z]+)?|[rR]u(?:[a-zA-Z]+)?|1\s?[sS](?:[a-zA-Z]+)?|2\s?[sS](?:[a-zA-Z]+)?|1\s?[kK](?:[a-zA-Z]+)?|2\s?[kK](?:[a-zA-Z]+)?|1\s?[cC]hr(?:[a-zA-Z]+)?|2\s?[cC]hr(?:[a-zA-Z]+)?|[eE]z(?:[a-zA-Z]+)?|[nN]e(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|[mM](?:[a-zA-Z]+)?|[lL](?:[a-zA-Z]+)?|[jJ](?:[a-zA-Z]+)?|[aA](?:[a-zA-Z]+)?|[rR](?:[a-zA-Z]+)?|1\s?[cC]o(?:[a-zA-Z]+)?|2\s?[cC]o(?:[a-zA-Z]+)?|[gG](?:[a-zA-Z]+)?|[eE](?:[a-zA-Z]+)?|[pP]h(?:[a-zA-Z]+)?|[cC](?:[a-zA-Z]+)?|1\s?[tT]h(?:[a-zA-Z]+)?|2\s?[tT]h(?:[a-zA-Z]+)?|1\s?[tT](?:[a-zA-Z]+)?|2\s?[tT](?:[a-zA-Z]+)?|[tT](?:[a-zA-Z]+)?|[pP]h(?:[a-zA-Z]+)?|[hH](?:[a-zA-Z]+)?|[jJ]a(?:[a-zA-Z]+)?|1\s?[pP](?:[a-zA-Z]+)?|2\s?[pP](?:[a-zA-Z]+)?|1\s?[jJ](?:[a-zA-Z]+)?|2\s?[jJ](?:[a-zA-Z]+)?|3\s?[jJ](?:[a-zA-Z]+)?|[jJ](:[a-zA-Z]+)?|[Rr|Aa](?:[a-zA-Z]+)?))?/gim
|
|
3
|
+
const chapterRegex = /\b(?:\.?\s?\d+[:|\.]?)\b/gm
|
|
4
|
+
const verseRegex = /\b[:.](\d+(?:,?\s*?\d+?|-|–|—\d+)*)?\d+\b/gm
|
|
5
|
+
const chapterRange = /\s?(?:[-|—|–])\s?/gm
|
|
6
|
+
const chapterRangeVerseRegex = /.\d+/gm
|
|
9
7
|
const scripturesRegex = new RegExp(
|
|
10
|
-
`(${bookRegex.source})(${chapterRegex.source})?(${verseRegex.source})(${chapterRange.source})?(
|
|
11
|
-
"
|
|
8
|
+
`(${bookRegex.source})(${chapterRegex.source})?(${verseRegex.source})(${chapterRange.source}?)?(${chapterRangeVerseRegex.source})?(${chapterRegex.source})?(${chapterRangeVerseRegex.source})?`,
|
|
9
|
+
"gmi"
|
|
12
10
|
)
|
|
13
|
-
const abbrScripturesRegex = new RegExp(`(${bookAbbrRegex.source})(${chapterRegex.source})?(${verseRegex.source})`, "gm")
|
|
14
11
|
|
|
15
12
|
module.exports.bookRegex = bookRegex
|
|
16
|
-
module.exports.bookAbbrRegex = bookAbbrRegex
|
|
17
13
|
module.exports.chapterRegex = chapterRegex
|
|
18
14
|
module.exports.scripturesRegex = scripturesRegex
|
|
19
|
-
module.exports.abbrScripturesRegex = abbrScripturesRegex
|
|
20
15
|
module.exports.verseRegex = verseRegex
|
package/test.js
CHANGED
|
@@ -2,8 +2,8 @@ const CodexParser = require("./src/CodexParser.js")
|
|
|
2
2
|
|
|
3
3
|
const parser = new CodexParser()
|
|
4
4
|
const text =
|
|
5
|
-
"The passages that we are looking at tonight are found in 1 John 3:16-17, 1 Peter 1:1, and Romans 10:13, 15, 17. Please turn in your Bibles."
|
|
6
|
-
const single = "
|
|
7
|
-
parser.parse(
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
"The passages that we are looking at tonight are found in 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."
|
|
6
|
+
const single = "Ge 27.27-29,89-40 Heb 11.20"
|
|
7
|
+
const passages = parser.parse(text)
|
|
8
|
+
console.log(passages)
|
|
9
|
+
|