codexparser 0.1.56 → 0.1.58
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/README.md +94 -38
- package/package.json +1 -1
- package/src/CodexParser.js +14 -2
- package/src/abbr/sbl.js +70 -0
package/README.md
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
# CodexParser: The Ultimate Bible Reference Parser 📖✨
|
|
2
2
|
|
|
3
|
-
Welcome to **CodexParser**, a powerful and flexible Node.js library crafted to parse, validate, and structure Bible references with ease. Whether you're extracting verses from a sermon, building a scripture app, or analyzing biblical texts, CodexParser transforms raw references like "John 3:16" or "
|
|
3
|
+
Welcome to **CodexParser**, a powerful and flexible Node.js library crafted to parse, validate, and structure Bible references with ease. Whether you're extracting verses from a sermon, building a scripture app, or analyzing biblical texts, CodexParser transforms raw references like "John 3:16" or "Psalm 115:5,7,10" into rich, actionable data—complete with start and end points, SBL-style abbreviations, versification support, and validation. Dive into the Word like never before!
|
|
4
4
|
|
|
5
|
-
Built with precision and passion, CodexParser handles single verses, ranges, multi-chapter spans, and
|
|
5
|
+
Built with precision and passion, CodexParser handles single verses, ranges, multi-chapter spans, and single-chapter books (looking at you, Jude!). It’s your trusty companion for navigating the sacred texts, supporting English, Septuagint (LXX), and Masoretic Text (MT) versions. Let’s unleash its power!
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## Features 🌟
|
|
10
10
|
|
|
11
|
-
- **Parse Any Reference**: From "Jn 3:16" to "
|
|
12
|
-
- **Structured Output**: Get book, chapter,
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
11
|
+
- **Parse Any Reference**: From "Jn 3:16" to "Psalm 115:5,7,10", it’s got you covered.
|
|
12
|
+
- **Structured Output**: Get book, chapter, verses, testament, start/end points, SBL abbreviations, and versification data in a clean object.
|
|
13
|
+
- **SBL Abbreviations**: Formatted references (e.g., "Ps. 115:5, 7, 10", "Gen. 1:1–3") with periods, en dashes for ranges, and commas with spaces for separated verses.
|
|
14
|
+
- **Versification Support**: Handles differences between English, LXX, and MT texts, with mappings like Psalm 115 (LXX) to Psalm 116 (MT/ENG).
|
|
15
|
+
- **Validation**: Checks if verses exist, with detailed error messages for invalid references.
|
|
15
16
|
- **Combine Passages**: Merge multiple references into a single, cohesive range.
|
|
16
17
|
- **Chainable API**: Fluent, intuitive method chaining for a smooth workflow.
|
|
17
18
|
|
|
@@ -28,7 +29,7 @@ npm install codexparser
|
|
|
28
29
|
Or clone it from GitHub and dive into the source:
|
|
29
30
|
|
|
30
31
|
```bash
|
|
31
|
-
git clone https://github.com/
|
|
32
|
+
git clone https://github.com/jeremyam/CodexParser.git
|
|
32
33
|
cd CodexParser
|
|
33
34
|
npm install
|
|
34
35
|
```
|
|
@@ -40,28 +41,58 @@ npm install
|
|
|
40
41
|
Here’s how to wield CodexParser’s might:
|
|
41
42
|
|
|
42
43
|
```javascript
|
|
43
|
-
const CodexParser = require("
|
|
44
|
+
const CodexParser = require("codexparser")
|
|
44
45
|
|
|
45
46
|
const parser = new CodexParser()
|
|
46
47
|
|
|
47
|
-
// Parse
|
|
48
|
-
parser.parse("
|
|
48
|
+
// Parse comma-separated verses with LXX version
|
|
49
|
+
parser.bibleVersion("lxx").parse("Psalm 115:5,7,10")
|
|
49
50
|
console.log(parser.getPassages().first())
|
|
50
51
|
// Output: {
|
|
51
|
-
// original: "
|
|
52
|
-
// book: "
|
|
53
|
-
// chapter:
|
|
54
|
-
// verses: [
|
|
55
|
-
// type: "
|
|
56
|
-
// testament: "
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
//
|
|
52
|
+
// original: "Psalm 115:5,7,10",
|
|
53
|
+
// book: "Psalms",
|
|
54
|
+
// chapter: 115,
|
|
55
|
+
// verses: [5, 7, 10],
|
|
56
|
+
// type: "comma_separated_verses",
|
|
57
|
+
// testament: "old",
|
|
58
|
+
// index: 0,
|
|
59
|
+
// version: { name: "Septuagint", value: "LXX", abbreviation: "lxx" },
|
|
60
|
+
// passages: [
|
|
61
|
+
// {
|
|
62
|
+
// book: "Psalms",
|
|
63
|
+
// chapter: 115,
|
|
64
|
+
// verse: 5,
|
|
65
|
+
// versification: { lxx: "115:5", mt: "116:14", eng: "116:14" }
|
|
66
|
+
// },
|
|
67
|
+
// {
|
|
68
|
+
// book: "Psalms",
|
|
69
|
+
// chapter: 115,
|
|
70
|
+
// verse: 7,
|
|
71
|
+
// versification: { lxx: "115:7", mt: "116:16", eng: "116:16" }
|
|
72
|
+
// },
|
|
73
|
+
// {
|
|
74
|
+
// book: "Psalms",
|
|
75
|
+
// chapter: 115,
|
|
76
|
+
// verse: 10,
|
|
77
|
+
// versification: { lxx: "115:10", mt: "116:19", eng: "116:19" }
|
|
78
|
+
// }
|
|
79
|
+
// ],
|
|
80
|
+
// scripture: {
|
|
81
|
+
// passage: "Psalms 115:5,7,10",
|
|
82
|
+
// cv: "115:5,7,10",
|
|
83
|
+
// hash: "psalms_115.5,7,10"
|
|
84
|
+
// },
|
|
61
85
|
// valid: true,
|
|
62
|
-
//
|
|
86
|
+
// start: { book: "Psalms", chapter: 115, verse: 5 },
|
|
87
|
+
// end: { book: "Psalms", chapter: 115, verse: 10 },
|
|
88
|
+
// abbr: "Ps. 115:5, 7, 10",
|
|
89
|
+
// reference: [Function]
|
|
63
90
|
// }
|
|
64
91
|
|
|
92
|
+
// Parse a verse range
|
|
93
|
+
console.log(parser.bibleVersion("eng").parse("Genesis 1:1-5").getPassages().first().abbr)
|
|
94
|
+
// Output: "Gen. 1:1–5"
|
|
95
|
+
|
|
65
96
|
// Chain it up!
|
|
66
97
|
console.log(parser.parse("Genesis 1:1-5, 10; 2:1-3").getPassages().combine())
|
|
67
98
|
// Combines into a single passage with start/end spanning the range!
|
|
@@ -87,17 +118,17 @@ Here’s the breakdown of CodexParser’s key methods—your tools for mastering
|
|
|
87
118
|
|
|
88
119
|
### `.parse(reference)`
|
|
89
120
|
|
|
90
|
-
- **What it does**: Takes a reference string, scans it, and builds structured passage objects with `start`, `end`, `passages`, and
|
|
91
|
-
- **Args**: `reference` (string) - The Bible reference (e.g., "
|
|
121
|
+
- **What it does**: Takes a reference string, scans it, and builds structured passage objects with `start`, `end`, `passages`, SBL abbreviations, versification, and validation. This is your main parsing powerhouse.
|
|
122
|
+
- **Args**: `reference` (string) - The Bible reference (e.g., "Psalm 115:5,7,10").
|
|
92
123
|
- **Returns**: The parser instance for chaining.
|
|
93
124
|
- **Example**: `parser.parse("Exodus 20:1-5").getPassages();`
|
|
94
125
|
|
|
95
126
|
### `.bibleVersion(version)`
|
|
96
127
|
|
|
97
|
-
- **What it does**: Sets the Bible version (e.g., "lxx", "mt", "
|
|
98
|
-
- **Args**: `version` (string) - Version code ("lxx", "mt", "
|
|
128
|
+
- **What it does**: Sets the Bible version (e.g., "lxx", "mt", "eng") to adjust versification. Great for Old Testament nerds!
|
|
129
|
+
- **Args**: `version` (string) - Version code ("lxx", "mt", "eng", etc.).
|
|
99
130
|
- **Returns**: The parser instance for chaining.
|
|
100
|
-
- **Example**: `parser.bibleVersion("lxx").parse("Psalm
|
|
131
|
+
- **Example**: `parser.bibleVersion("lxx").parse("Psalm 115:5,7,10");`
|
|
101
132
|
|
|
102
133
|
### `.getPassages()`
|
|
103
134
|
|
|
@@ -136,19 +167,44 @@ Each parsed passage looks like this:
|
|
|
136
167
|
|
|
137
168
|
```javascript
|
|
138
169
|
{
|
|
139
|
-
original: "
|
|
140
|
-
book: "
|
|
141
|
-
chapter:
|
|
142
|
-
verses: [
|
|
143
|
-
type: "
|
|
144
|
-
testament: "
|
|
170
|
+
original: "Psalm 115:5,7,10", // Original input
|
|
171
|
+
book: "Psalms", // Full book name
|
|
172
|
+
chapter: 115, // Starting chapter
|
|
173
|
+
verses: [5, 7, 10], // Verse list
|
|
174
|
+
type: "comma_separated_verses", // Reference type
|
|
175
|
+
testament: "old", // Old or New Testament
|
|
145
176
|
index: 0, // Position in text
|
|
146
|
-
version: { name: "
|
|
147
|
-
passages: [
|
|
148
|
-
|
|
177
|
+
version: { name: "Septuagint", value: "LXX", abbreviation: "lxx" }, // Version info
|
|
178
|
+
passages: [ // Expanded verses
|
|
179
|
+
{
|
|
180
|
+
book: "Psalms",
|
|
181
|
+
chapter: 115,
|
|
182
|
+
verse: 5,
|
|
183
|
+
versification: { lxx: "115:5", mt: "116:14", eng: "116:14" }
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
book: "Psalms",
|
|
187
|
+
chapter: 115,
|
|
188
|
+
verse: 7,
|
|
189
|
+
versification: { lxx: "115:7", mt: "116:16", eng: "116:16" }
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
book: "Psalms",
|
|
193
|
+
chapter: 115,
|
|
194
|
+
verse: 10,
|
|
195
|
+
versification: { lxx: "115:10", mt: "116:19", eng: "116:19" }
|
|
196
|
+
}
|
|
197
|
+
],
|
|
198
|
+
scripture: { // Formatted output
|
|
199
|
+
passage: "Psalms 115:5,7,10",
|
|
200
|
+
cv: "115:5,7,10",
|
|
201
|
+
hash: "psalms_115.5,7,10"
|
|
202
|
+
},
|
|
149
203
|
valid: true, // Validation status
|
|
150
|
-
start: { book: "
|
|
151
|
-
end: { book: "
|
|
204
|
+
start: { book: "Psalms", chapter: 115, verse: 5 }, // First verse
|
|
205
|
+
end: { book: "Psalms", chapter: 115, verse: 10 }, // Last verse
|
|
206
|
+
abbr: "Ps. 115:5, 7, 10", // SBL-style abbreviation with period, comma spaces
|
|
207
|
+
reference: [Function] // Method to get scripture.passage
|
|
152
208
|
}
|
|
153
209
|
```
|
|
154
210
|
|
|
@@ -159,7 +215,7 @@ Each parsed passage looks like this:
|
|
|
159
215
|
- **Single Chapter**: `Jude 1` (whole chapter of a single-chapter book).
|
|
160
216
|
- **Chapter Verse**: `John 3:16` (one verse).
|
|
161
217
|
- **Chapter Verse Range**: `Genesis 1:1-5` (verse range in one chapter).
|
|
162
|
-
- **Comma Separated Verses**: `
|
|
218
|
+
- **Comma Separated Verses**: `Psalm 115:5,7,10` (multiple verses in one chapter).
|
|
163
219
|
- **Chapter Range**: `Exodus 20-22` (full chapters).
|
|
164
220
|
- **Multi-Chapter Verse Range**: `Psalm 119:1-120:5` (spans chapters).
|
|
165
221
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codexparser",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.58",
|
|
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,7 +1,8 @@
|
|
|
1
1
|
const versified = require("./versified")
|
|
2
2
|
const bible = require("./bible")
|
|
3
3
|
const { bookRegex, chapterRegex, verseRegex, scripturesRegex } = require("./regex")
|
|
4
|
-
const
|
|
4
|
+
const abbreviations = require("./abbr")
|
|
5
|
+
const sblAbbreviations = require("./abbr/sbl")
|
|
5
6
|
const dump = require("./functions").dump
|
|
6
7
|
const dd = require("./functions").dd
|
|
7
8
|
const sch = require("./functions").sch
|
|
@@ -16,7 +17,8 @@ class CodexParser {
|
|
|
16
17
|
this.chapterRegex = chapterRegex
|
|
17
18
|
this.verseRegex = verseRegex
|
|
18
19
|
this.scripturesRegex = scripturesRegex
|
|
19
|
-
this.abbreviations =
|
|
20
|
+
this.abbreviations = abbreviations
|
|
21
|
+
this.sblAbbreviations = sblAbbreviations
|
|
20
22
|
this.versificationDifferences = versified
|
|
21
23
|
this.singleChapterBook = [
|
|
22
24
|
sch("Jude", 25),
|
|
@@ -193,6 +195,16 @@ class CodexParser {
|
|
|
193
195
|
parsedPassage.scripture = this.scripturize(parsedPassage)
|
|
194
196
|
parsedPassage.valid = this._isValid(parsedPassage, passage.reference)
|
|
195
197
|
|
|
198
|
+
// Add SBL abbreviation as full reference with en dashes and space after commas for comma-separated verses
|
|
199
|
+
const sblEntry = this.sblAbbreviations[book] || { value: book, abbr: false }
|
|
200
|
+
const sblBook = sblEntry.value + (sblEntry.abbr ? "." : "")
|
|
201
|
+
let abbr = parsedPassage.scripture.passage.replace(book, sblBook).replace(/-/g, "–")
|
|
202
|
+
if (parsedPassage.type === "comma_separated_verses") {
|
|
203
|
+
const versePart = parsedPassage.verses.map((v) => `${v}`).join(", ")
|
|
204
|
+
abbr = `${sblBook} ${parsedPassage.chapter}:${versePart}`
|
|
205
|
+
}
|
|
206
|
+
parsedPassage.abbr = abbr
|
|
207
|
+
|
|
196
208
|
if (parsedPassage.type === this.MULTI_CHAPTER_RANGE) {
|
|
197
209
|
this.handleMultiChapterRange(parsedPassage, passage.reference)
|
|
198
210
|
} else {
|
package/src/abbr/sbl.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const sblAbbreviations = {
|
|
2
|
+
Genesis: { value: "Gen", abbr: true },
|
|
3
|
+
Exodus: { value: "Exod", abbr: true },
|
|
4
|
+
Leviticus: { value: "Lev", abbr: true },
|
|
5
|
+
Numbers: { value: "Num", abbr: true },
|
|
6
|
+
Deuteronomy: { value: "Deut", abbr: true },
|
|
7
|
+
Joshua: { value: "Josh", abbr: true },
|
|
8
|
+
Judges: { value: "Judg", abbr: true },
|
|
9
|
+
Ruth: { value: "Ruth", abbr: false },
|
|
10
|
+
"1 Samuel": { value: "1 Sam", abbr: true },
|
|
11
|
+
"2 Samuel": { value: "2 Sam", abbr: true },
|
|
12
|
+
"1 Kings": { value: "1 Kgs", abbr: true },
|
|
13
|
+
"2 Kings": { value: "2 Kgs", abbr: true },
|
|
14
|
+
"1 Chronicles": { value: "1 Chr", abbr: true },
|
|
15
|
+
"2 Chronicles": { value: "2 Chr", abbr: true },
|
|
16
|
+
Ezra: { value: "Ezra", abbr: false },
|
|
17
|
+
Nehemiah: { value: "Neh", abbr: true },
|
|
18
|
+
Esther: { value: "Esth", abbr: true },
|
|
19
|
+
Job: { value: "Job", abbr: false },
|
|
20
|
+
Psalms: { value: "Ps", abbr: true },
|
|
21
|
+
Proverbs: { value: "Prov", abbr: true },
|
|
22
|
+
Ecclesiastes: { value: "Eccl", abbr: true },
|
|
23
|
+
"Song of Solomon": { value: "Song", abbr: true },
|
|
24
|
+
Isaiah: { value: "Isa", abbr: true },
|
|
25
|
+
Jeremiah: { value: "Jer", abbr: true },
|
|
26
|
+
Lamentations: { value: "Lam", abbr: true },
|
|
27
|
+
Ezekiel: { value: "Ezek", abbr: true },
|
|
28
|
+
Daniel: { value: "Dan", abbr: true },
|
|
29
|
+
Hosea: { value: "Hos", abbr: true },
|
|
30
|
+
Joel: { value: "Joel", abbr: false },
|
|
31
|
+
Amos: { value: "Amos", abbr: false },
|
|
32
|
+
Obadiah: { value: "Obad", abbr: true },
|
|
33
|
+
Jonah: { value: "Jonah", abbr: false },
|
|
34
|
+
Micah: { value: "Mic", abbr: true },
|
|
35
|
+
Nahum: { value: "Nah", abbr: true },
|
|
36
|
+
Habakkuk: { value: "Hab", abbr: true },
|
|
37
|
+
Zephaniah: { value: "Zeph", abbr: true },
|
|
38
|
+
Haggai: { value: "Hag", abbr: true },
|
|
39
|
+
Zechariah: { value: "Zech", abbr: true },
|
|
40
|
+
Malachi: { value: "Mal", abbr: true },
|
|
41
|
+
Matthew: { value: "Matt", abbr: true },
|
|
42
|
+
Mark: { value: "Mark", abbr: false },
|
|
43
|
+
Luke: { value: "Luke", abbr: false },
|
|
44
|
+
John: { value: "John", abbr: false },
|
|
45
|
+
Acts: { value: "Acts", abbr: false },
|
|
46
|
+
Romans: { value: "Rom", abbr: true },
|
|
47
|
+
"1 Corinthians": { value: "1 Cor", abbr: true },
|
|
48
|
+
"2 Corinthians": { value: "2 Cor", abbr: true },
|
|
49
|
+
Galatians: { value: "Gal", abbr: true },
|
|
50
|
+
Ephesians: { value: "Eph", abbr: true },
|
|
51
|
+
Philippians: { value: "Phil", abbr: true },
|
|
52
|
+
Colossians: { value: "Col", abbr: true },
|
|
53
|
+
"1 Thessalonians": { value: "1 Thess", abbr: true },
|
|
54
|
+
"2 Thessalonians": { value: "2 Thess", abbr: true },
|
|
55
|
+
"1 Timothy": { value: "1 Tim", abbr: true },
|
|
56
|
+
"2 Timothy": { value: "2 Tim", abbr: true },
|
|
57
|
+
Titus: { value: "Titus", abbr: false },
|
|
58
|
+
Philemon: { value: "Phlm", abbr: true },
|
|
59
|
+
Hebrews: { value: "Heb", abbr: true },
|
|
60
|
+
James: { value: "Jas", abbr: true },
|
|
61
|
+
"1 Peter": { value: "1 Pet", abbr: true },
|
|
62
|
+
"2 Peter": { value: "2 Pet", abbr: true },
|
|
63
|
+
"1 John": { value: "1 John", abbr: false },
|
|
64
|
+
"2 John": { value: "2 John", abbr: false },
|
|
65
|
+
"3 John": { value: "3 John", abbr: false },
|
|
66
|
+
Jude: { value: "Jude", abbr: false },
|
|
67
|
+
Revelation: { value: "Rev", abbr: true },
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = sblAbbreviations
|