codexparser 0.0.1

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/.babelrc ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "presets": [
3
+ "@babel/preset-env",
4
+ "@babel/preset-react"
5
+ ],
6
+ "plugins": []
7
+ }
package/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import CodexParser from './src/CodexParser.js'
2
+
3
+ const parser = new CodexParser();
4
+ const text = '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.'
5
+ const single = 'Revelation 16:8'
6
+ parser.parse(text)
7
+ parser.parse(single)
8
+ console.log(parser.getPassages())
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "codexparser",
3
+ "version": "0.0.1",
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
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "build": "webpack --mode=production"
9
+ },
10
+ "author": "Jeremy Menicucci",
11
+ "license": "ISC",
12
+ "type": "module",
13
+ "devDependencies": {
14
+ "@babel/cli": "^7.23.9",
15
+ "@babel/core": "^7.24.0",
16
+ "@babel/preset-env": "^7.24.0",
17
+ "@babel/preset-react": "^7.23.3",
18
+ "babel-loader": "^9.1.3",
19
+ "path": "^0.12.7",
20
+ "webpack": "^5.90.3",
21
+ "webpack-cli": "^5.1.4"
22
+ }
23
+ }
@@ -0,0 +1,67 @@
1
+ import { bible } from "./bible.js"
2
+ import { bookRegex, bookAbbrRegex, chapterRegex, verseRegex, scripturesRegex, abbrScripturesRegex } from "./regex.js"
3
+
4
+ class CodexParser {
5
+ constructor() {
6
+ this.found = []
7
+ this.passages = []
8
+ this.bible = bible
9
+ this.bookRegex = bookRegex
10
+ this.bookAbbrRegex = bookAbbrRegex
11
+ this.chapterRegex = chapterRegex
12
+ this.verseRegex = verseRegex
13
+ this.scripturesRegex = scripturesRegex
14
+ this.abbrScripturesRegex = abbrScripturesRegex
15
+ }
16
+
17
+ /**
18
+ * Scans the input text using the specified scriptures regex.
19
+ *
20
+ * @param {string} text - The text to scan.
21
+ * @return {array} The found passages from the text.
22
+ */
23
+ scan(text) {
24
+ this.found = text.match(this.scripturesRegex)
25
+ return this.found
26
+ }
27
+
28
+ /**
29
+ * Parses the given reference to extract passages.
30
+ *
31
+ * @param {string} reference - The reference to parse.
32
+ * @return {array} An array of parsed passages.
33
+ */
34
+ parse(reference) {
35
+ if (!reference) {
36
+ return null // return null if no reference is provided
37
+ }
38
+ this.passages = []
39
+ this.scan(reference)
40
+ for (let i = 0; i < this.found.length; i++) {
41
+ const book = this.found[i].match(this.bookRegex)
42
+ const chapter = this.found[i].replace(book[0], "").match(this.chapterRegex)
43
+ const passage = {
44
+ original: this.found[i],
45
+ book: book[0].charAt(0).toUpperCase() + book[0].slice(1),
46
+ chapter: chapter[0].replace(":", "").trim(),
47
+ verse: this.found[i].match(this.verseRegex)[0].replace(":", "").trim(),
48
+ }
49
+ passage.verse = passage.verse.split(/,/).filter(Boolean)
50
+ passage.testament = this.bible.old.includes(passage.book) ? "old" : "new"
51
+ this.passages.push(passage)
52
+ }
53
+ this.found = []
54
+ return this.passages
55
+ }
56
+
57
+ /**
58
+ * Returns the passages stored in the object.
59
+ *
60
+ * @return {array} The passages stored in the object.
61
+ */
62
+ getPassages() {
63
+ return this.passages
64
+ }
65
+ }
66
+
67
+ export default CodexParser
package/src/bible.js ADDED
@@ -0,0 +1,72 @@
1
+ export const bible = {
2
+ old: [
3
+ "Genesis",
4
+ "Exodus",
5
+ "Leviticus",
6
+ "Numbers",
7
+ "Deuteronomy",
8
+ "Joshua",
9
+ "Judges",
10
+ "Ruth",
11
+ "1 Samuel",
12
+ "2 Samuel",
13
+ "1 Kings",
14
+ "2 Kings",
15
+ "1 Chronicles",
16
+ "2 Chronicles",
17
+ "Ezra",
18
+ "Nehemiah",
19
+ "Esther",
20
+ "Job",
21
+ "Psalms",
22
+ "Proverbs",
23
+ "Ecclesiastes",
24
+ "Song of Solomon",
25
+ "Isaiah",
26
+ "Jeremiah",
27
+ "Lamentations",
28
+ "Ezekiel",
29
+ "Daniel",
30
+ "Hosea",
31
+ "Joel",
32
+ "Amos",
33
+ "Obadiah",
34
+ "Jonah",
35
+ "Micah",
36
+ "Nahum",
37
+ "Habakkuk",
38
+ "Zephaniah",
39
+ "Haggai",
40
+ "Zechariah",
41
+ "Malachi",
42
+ ],
43
+ new: [
44
+ "Matthew",
45
+ "Mark",
46
+ "Luke",
47
+ "John",
48
+ "Acts",
49
+ "Romans",
50
+ "1 Corinthians",
51
+ "2 Corinthians",
52
+ "Galatians",
53
+ "Ephesians",
54
+ "Philippians",
55
+ "Colossians",
56
+ "1 Thessalonians",
57
+ "2 Thessalonians",
58
+ "1 Timothy",
59
+ "2 Timothy",
60
+ "Titus",
61
+ "Philemon",
62
+ "Hebrews",
63
+ "James",
64
+ "1 Peter",
65
+ "2 Peter",
66
+ "1 John",
67
+ "2 John",
68
+ "3 John",
69
+ "Jude",
70
+ "Revelation",
71
+ ],
72
+ }
package/src/regex.js ADDED
@@ -0,0 +1,14 @@
1
+ export const bookRegex =
2
+ /(?:(?:[gG]en(?:esis)?|[eE]xod(?:us)?|[lL]ev(?:iticus)?|[nN]um(?:bers)?|[dD]eu(?:teronomy)?|[jJ]os(?:hua)?|[jJ]dg(?:es)?|[rR]ut(?:h)?|1 [sS]a(?:muel)?|2 [sS]a(?:muel)?|1 [kK]gs(?:on)?|2 [kK]gs(?:on)?|1 [cC]hr(?:onicles)?|2 [cC]hr(?:onicles)?|[eE]zr(?:a)?|[nN]eh(?:emiah)?|[eE]st(?:her)?|[jJ]ob|[pP]sa(?:lms)?|[pP]ro(?:verbs)?|[eE]cc(?:lesiastes)?|[sS]on(?:g)?|[iI]sa(?:iah)?|[jJ]er(?:emiah)?|[lL]am(?:entations)?|[eE]ze(?:riah)?|[dD]an(?:iel)?|[hH]o(?:sea)?|[jJ]oe(?:l)?|[aA]mo(?:s)?|[oO]ba(?:h)?|[jJ]on(?:ah)?|[mM]i(?:cah)?|[nN]ah(?:um)?|[hH]ab(?:akkuk)?|[zZ]ep(?:haniah)?|[hH]ag(?:gai)?|[zZ]ec(?:hariah)?|[mM]al(?:achi)?|[mM]at(?:thew)?|[mM]ar(?:k)?|[lL]uk(?:e)?|[jJ]oh(?:n)?|[aA]ct(?:s)?|[rR]om(?:s)?|1 [cC]or(?:inthians)?|2 [cC]or(?:inthians)?|[gG]al(?:atians)?|[eE]ph(?:esians)?|[pP]hi(?:lippians)?|[cC]ol(?:ossians)?|1 [tT]hess(?:alonians)?|2 [tT]hess(?:alonians)?|1 [tT]i(?:mothy)?|2 [tT]i(?:mothy)?|[tT]it(?:us)?|[pP]h(?:ilemon)?|[hH]eb(?:rews)?|[jJ]am(?:es)?|1 [pP]e(?:ter)?|2 [pP]e(?:ter)?|1 [jJ]o(?:n)?|2 [jJ]o(?:n)?|3 [jJ]o(?:n)?|[jJ]ude?|Rev(?:elation)?))/gim
3
+ export const bookAbbrRegex =
4
+ /(?:(?:[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
+ export const chapterRegex = /(?:\s?\d+:?)/g
6
+ export const verseRegex = /\b:\s*?(\d+(?:,?\s*?\d+?|-|–|—\d+)*)?\d+(?!p|j|k|s|c|t)\b/g
7
+ export const scripturesRegex = new RegExp(
8
+ `(${bookRegex.source})(${chapterRegex.source})?(${verseRegex.source})`,
9
+ "gm"
10
+ )
11
+ export const abbrScripturesRegex = new RegExp(
12
+ `(${bookAbbrRegex.source})(${chapterRegex.source})?(${verseRegex.source})`,
13
+ "gm"
14
+ )
@@ -0,0 +1,32 @@
1
+ import path from "path"
2
+ import { fileURLToPath } from "url"
3
+
4
+ const __filename = fileURLToPath(import.meta.url)
5
+ const __dirname = path.dirname(__filename)
6
+
7
+ export default {
8
+ entry: {
9
+ main: "./src/CodexParser.js",
10
+ },
11
+ output: {
12
+ filename: "CodexParser.js",
13
+ path: path.resolve(__dirname, "dist"),
14
+ library: {
15
+ name: "CodexParser",
16
+ type: "umd",
17
+ export: "default",
18
+ },
19
+ globalObject: "typeof self !== 'undefined' ? self : this",
20
+ },
21
+ module: {
22
+ rules: [
23
+ {
24
+ test: /\.m?js$/,
25
+ exclude: /node_modules/,
26
+ use: {
27
+ loader: "babel-loader",
28
+ },
29
+ },
30
+ ],
31
+ },
32
+ }