codexparser 0.0.13 → 0.0.17

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codexparser",
3
- "version": "0.0.13",
3
+ "version": "0.0.17",
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": {
@@ -14,9 +14,10 @@
14
14
  "@babel/core": "^7.24.0",
15
15
  "@babel/preset-env": "^7.24.0",
16
16
  "@babel/preset-react": "^7.23.3",
17
+ "axios": "^1.7.2",
17
18
  "babel-loader": "^9.1.3",
18
19
  "path": "^0.12.7",
19
20
  "webpack": "^5.90.3",
20
21
  "webpack-cli": "^5.1.4"
21
22
  }
22
- }
23
+ }
@@ -1,6 +1,7 @@
1
1
  const bible = require("./bible")
2
- const { bookRegex, bookAbbrRegex, chapterRegex, verseRegex, scripturesRegex, abbrScripturesRegex } = require("./regex")
2
+ const { bookRegex, chapterRegex, verseRegex, scripturesRegex } = require("./regex")
3
3
  const abbrevations = require("./abbr")
4
+ const toc = require("./toc")
4
5
 
5
6
  class CodexParser {
6
7
  constructor() {
@@ -8,12 +9,11 @@ class CodexParser {
8
9
  this.passages = []
9
10
  this.bible = bible
10
11
  this.bookRegex = bookRegex
11
- this.bookAbbrRegex = bookAbbrRegex
12
12
  this.chapterRegex = chapterRegex
13
13
  this.verseRegex = verseRegex
14
14
  this.scripturesRegex = scripturesRegex
15
- this.abbrScripturesRegex = abbrScripturesRegex
16
15
  this.abbrevations = abbrevations
16
+ this.toc = toc
17
17
  }
18
18
 
19
19
  /**
@@ -39,26 +39,49 @@ class CodexParser {
39
39
  }
40
40
  this.passages = []
41
41
  this.scan(reference)
42
- console.log(this.found)
43
42
  for (let i = 0; i < this.found.length; i++) {
43
+ const hasChapterRange = this.found[i].match(/(?<=-\s?)\b\d+[.:].+\b/)
44
44
  const book = this.found[i].match(this.bookRegex)
45
45
  const chapter = this.found[i].replace(book[0], "").match(this.chapterRegex)
46
+ const verse = this.found[i].match(this.verseRegex)[0].replace(/[:.]/, "").trim()
46
47
  const passage = {
47
48
  original: this.found[i],
48
- book: this.bookify(book[0].charAt(0).toUpperCase() + book[0].slice(1)),
49
- chapter: chapter[0].replace(/[:.]/, "").trim(),
50
- verses: this.found[i].match(this.verseRegex)[0].replace(/[:.]/, "").trim(),
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"
51
62
  }
52
63
  passage.verses = passage.verses.split(/,/).filter(Boolean)
53
64
  passage.testament = this.bible.old.includes(passage.book) ? "old" : "new"
65
+ passage.scripture = this.scripturize(passage)
54
66
  this.passages.push(passage)
55
67
  }
68
+
56
69
  this.found = []
57
70
  return this.passages
58
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
+ */
59
82
  bookify(book) {
60
83
  let bookified
61
-
84
+ book = book[0].charAt(0).toUpperCase() + book[0].slice(1)
62
85
  bookified = this.abbrevations[book]
63
86
 
64
87
  if (!bookified) {
@@ -77,7 +100,7 @@ class CodexParser {
77
100
  }
78
101
  return bookified
79
102
  }
80
- //TODO: Need to create a bookfiy function that will convert abbreviated books into full books
103
+
81
104
  /**
82
105
  * Returns the passages stored in the object.
83
106
  *
@@ -86,6 +109,21 @@ class CodexParser {
86
109
  getPassages() {
87
110
  return this.passages
88
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
+ }
89
127
  }
90
128
 
91
129
  module.exports = CodexParser
package/src/esv.js ADDED
@@ -0,0 +1,19 @@
1
+ const axios = require("axios")
2
+
3
+ // Get all books
4
+ axios
5
+ .get("https://api.esv.org/v3/passage/text/", {
6
+ params: {
7
+ q: "John+3:16",
8
+ },
9
+ headers: {
10
+ Authorization: "Token c117111babd413bd8a22b09ebfe84342dc792781",
11
+ },
12
+ })
13
+ .then((response) => {
14
+ const books = response
15
+ console.log(books.data.passage_meta)
16
+ })
17
+ .catch((error) => {
18
+ console.error(error)
19
+ })
package/src/regex.js CHANGED
@@ -1,20 +1,15 @@
1
1
  const bookRegex =
2
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(?:[a-zA-Z]+)?|[eE]s(?:[a-zA-Z]+)?|[jJ](?:[a-zA-Z]+)?|[pP]s(?:[a-zA-Z]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?:[gG]en|[eE]xo|[lL]ev|[nN]um|[dD]eu|[jJ]os|[jJ]dg|[rR]ut|1 [sS]a|2 [sS]a|1 [kK]gs|2 [kK]gs|1 [cC]hr|2 [cC]hr|[eE]zr|[nN]eh|[eE]st|[jJ]ob|[pP]sa|[pP]ro|[eE]cc|[sS]on|[iI]sa|[jJ]er|[lL]am|[eE]ze|[dD]an|[hH]os|[jJ]oe|[aA]mo|[oO]ba|[jJ]on|[mM]ic|[nN]ah|[hH]ab|[zZ]ep|[hH]ag|[zZ]ec|[mM]al|[mM]att|[mM]ar|[lL]uk|[jJ]oh|[aA]ct|[rR]om|1 [cC]or|2 [cC]or|[gG]al|[eE]ph|[pP]hi|[cC]ol|1 [tT]hess|2 [tT]hess|1 [tT]i|2 [tT]i|[tT]it|[pP]hm|[hH]eb|[jJ]am|1 [pP]e|2 [pP]e|1 [jJ]o|2 [jJ]o|3 [jJ]o|[jJ]ud|[rR]ev))/gim
5
- const chapterRegex = /(?:\s?\d+:?)/g
6
- const verseRegex = /\b[:|\.]\s*?(\d+(?:,?\s*?\d+?|-|–|—\d+)*)?\d+(?!p|j|k|s|c|t)\b/g
7
- const chapterRange = /\s?(?:[-|—|–])\s?/g
8
- const chapterRangeVerseRegex = /./gm
3
+ const chapterRegex = /\b(?:\s?\d+[:|\.]?)\b/gm
4
+ const verseRegex = /\b[:.]\s*?(\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})?((${chapterRegex.source})?(${verseRegex.source})?)(${chapterRangeVerseRegex.source})?`,
11
- "gm"
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/src/toc.js ADDED
@@ -0,0 +1,5 @@
1
+ const fs = require("fs")
2
+
3
+ const bible = JSON.parse(fs.readFileSync(__dirname + "/../bibles/updated_kjv.json", "utf8"))
4
+
5
+ module.exports.bible = bible
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 = "Ge 2:9-3:3-2 and 2 Cor 2:2"
7
- parser.parse(single)
8
- //parser.parse(single)
9
- console.log(parser.getPassages())
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 4.24 - 5.32,33"
7
+ const passages = parser.parse(text)
8
+ console.log(passages)
9
+