free-use-bible-api 0.3.0 → 0.4.0

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 CHANGED
@@ -1,253 +1,269 @@
1
- # Free Use Bible API
2
-
3
- TypeScript and JavaScript client for the public Free Use Bible API:
4
-
5
- - `https://bible.helloao.org`
6
-
7
- ## Installation
8
-
9
- ```bash
10
- npm install free-use-bible-api
11
- ```
12
-
13
- ```bash
14
- pnpm add free-use-bible-api
15
- ```
16
-
17
- ```bash
18
- yarn add free-use-bible-api
19
- ```
20
-
21
- ## Quick Start
22
-
23
- ```ts
24
- import { FreeUseBibleApi } from 'free-use-bible-api';
25
-
26
- const api = new FreeUseBibleApi();
27
-
28
- const available = await api.getAvailableTranslations();
29
- console.log('Total translations:', available.translations.length);
30
-
31
- const books = await api.getTranslationBooks('BSB');
32
- console.log('Books in BSB:', books.books.length);
33
-
34
- const chapter = await api.getTranslationBookChapter('BSB', 'GEN', 1);
35
- console.log('Verses in Genesis 1:', chapter.numberOfVerses);
36
- ```
37
-
38
- ## Client Options
39
-
40
- You can customize the client with `FreeUseBibleApiOptions`:
41
-
42
- ```ts
43
- import { FreeUseBibleApi } from 'free-use-bible-api';
44
-
45
- const api = new FreeUseBibleApi({
46
- endpoint: 'https://bible.helloao.org/',
47
- useCache: true,
48
- });
49
- ```
50
-
51
- - `endpoint`: Base API endpoint.
52
- - `useCache`: Enables in-memory response caching (default: `true`).
53
-
54
- ## API Methods
55
-
56
- ### Translations
57
-
58
- - `getAvailableTranslations(endpoint?)`
59
- - `getTranslationBooks(translation, endpoint?)`
60
- - `getTranslationBookChapter(translation, book, chapter, endpoint?)`
61
- - `getTranslationBookChapterWords(translation, book, chapter, endpoint?)`
62
- - `getCompleteTranslation(translation, endpoint?)`
63
- - `getSimpleTranslationBookChapter(translation, book, chapter, endpoint?)`
64
- - `getSimpleTranslationBookChapterWords(translation, book, chapter, endpoint?)`
65
- - `getSimpleCompleteTranslation(translation, endpoint?)`
66
-
67
- `getCompleteTranslation()` and `getSimpleCompleteTranslation()` disable per-request cache internally because payloads are typically large.
68
-
69
- ### Commentaries
70
-
71
- - `getAvailableCommentaries(endpoint?)`
72
- - `getCommentaryBooks(commentary, endpoint?)`
73
- - `getCommentaryBookChapter(commentary, book, chapter, endpoint?)`
74
- - `getSimpleCommentaryBookChapter(commentary, book, chapter, endpoint?)`
75
-
76
- ### Datasets
77
-
78
- - `getAvailableDatasets(endpoint?)`
79
- - `getDatasetBooks(dataset, endpoint?)`
80
- - `getDatasetBookChapter(dataset, book, chapter, endpoint?)`
81
-
82
- ### Chapter Navigation Helpers
83
-
84
- - `getNextChapter(chapter, endpoint?)`
85
- - `getPreviousChapter(chapter, endpoint?)`
86
-
87
- ### Chapter & Verse Helpers
88
-
89
- - `getVerseText(verse)`
90
- - `getChapterVerseText(chapter)`
91
-
92
- These helpers work with translation, commentary, and dataset chapter responses, as well as simplified translation and commentary chapter responses.
93
-
94
- ### Word Annotations
95
-
96
- Some translations include word-level annotations (Strong's numbers and related source data) for their chapters.
97
-
98
- - `getChapterWords(chapter, endpoint?)` - gets the annotations for a chapter you already loaded, or `null` if it doesn't have any.
99
- - `getWordText(verse, word)` - gets the text that a single annotation applies to.
100
- - `getVerseWords(verse, words)` - gets the annotations for a verse, each paired with the text it applies to.
101
-
102
- Each annotation is anchored to a range of characters in a single item of a verse's `content` array: `contentIndex` is the index of the item, and `start`/`end` are character offsets into that item's text (`end` is exclusive). Anchoring per content item keeps the offsets correct for verses whose content is split into multiple items, such as poem lines and the words of Jesus.
103
-
104
- `getWordText()` and `getVerseWords()` resolve those offsets for you, so you don't have to walk the content array yourself.
105
-
106
- ### Simplified Chapters
107
-
108
- Every translation and commentary chapter can also be fetched in a simplified format, where each verse's content is a single string instead of a list of formatted content. Footnotes, inline headings, the Words of Jesus, and poetry are represented as offset ranges into that string instead of being split across multiple content items.
109
-
110
- - `getSimpleTranslationBookChapter(translation, book, chapter, endpoint?)`
111
- - `getSimpleCommentaryBookChapter(commentary, book, chapter, endpoint?)`
112
- - `getSimpleCompleteTranslation(translation, endpoint?)`
113
- - `getSimpleChapter(chapter, endpoint?)` - follows a chapter's `simpleChapterApiLink`, or `null` if simplified chapters aren't available for it.
114
- - `getSimpleTranslationBookChapterWords(translation, book, chapter, endpoint?)` / `getSimpleChapterWords(chapter, endpoint?)` - the same as the regular word annotations, but with offsets into the simplified verse text instead of a verse's content array.
115
- - `getSimpleWordText(verse, word)` / `getSimpleVerseWords(verse, words)` - the same as `getWordText()`/`getVerseWords()`, but for simplified verses and annotations.
116
- - `getSimpleChapterVerseText(chapter, options?)` - the same as `getChapterVerseText()`, but for a simplified chapter.
117
-
118
- `getNextChapter()` and `getPreviousChapter()` also accept simplified chapters, returning the next/previous simplified chapter.
119
-
120
- Datasets don't have a simplified format.
121
-
122
- ## Examples
123
-
124
- ### Get a complete translation
125
-
126
- ```ts
127
- const complete = await api.getCompleteTranslation('BSB');
128
- console.log(complete.translation.id);
129
- console.log(complete.books.length);
130
- ```
131
-
132
- ### Read a commentary chapter
133
-
134
- ```ts
135
- const comm = await api.getCommentaryBookChapter('matthew_henry', 'GEN', 1);
136
- console.log(comm.book.name);
137
- ```
138
-
139
- ### Read a dataset chapter
140
-
141
- ```ts
142
- const dataChapter = await api.getDatasetBookChapter(
143
- 'cross_references',
144
- 'JHN',
145
- 3
146
- );
147
- console.log(dataChapter.book.name);
148
- ```
149
-
150
- ### Navigate to next/previous chapter
151
-
152
- ```ts
153
- const current = await api.getTranslationBookChapter('BSB', 'GEN', 1);
154
-
155
- const next = await api.getNextChapter(current);
156
- const previous = await api.getPreviousChapter(current);
157
-
158
- console.log(next?.chapter.number);
159
- console.log(previous?.chapter.number);
160
- ```
161
-
162
- ### Read the Strong's numbers for a chapter
163
-
164
- ```ts
165
- const chapter = await api.getTranslationBookChapter('engwebp', 'JHN', 1);
166
- const words = await api.getChapterWords(chapter);
167
-
168
- if (!words) {
169
- // This translation has no word-level annotations for the chapter.
170
- return;
171
- }
172
-
173
- for (const content of chapter.chapter.content) {
174
- if (content.type !== 'verse') {
175
- continue;
176
- }
177
-
178
- for (const word of api.getVerseWords(content, words)) {
179
- console.log(word.text, word.strongs);
180
- }
181
- }
182
-
183
- // In [ 'G1722' ]
184
- // the [ 'G1722' ]
185
- // beginning [ 'G0746' ]
186
- // ...
187
- ```
188
-
189
- ### Read a simplified chapter
190
-
191
- ```ts
192
- const chapter = await api.getSimpleTranslationBookChapter('BSB', 'JHN', 1);
193
-
194
- for (const content of chapter.chapter.content) {
195
- if (content.type !== 'verse') {
196
- continue;
197
- }
198
- console.log(content.number, content.text);
199
- }
200
- ```
201
-
202
- ## Direct HTTP Endpoints
203
-
204
- ### Translation endpoints
205
-
206
- - `GET /api/available_translations.json`
207
- - `GET /api/{translation}/books.json`
208
- - `GET /api/{translation}/{book}/{chapter}.json`
209
- - `GET /api/{translation}/{book}/{chapter}.words.json`
210
- - `GET /api/{translation}/complete.json`
211
- - `GET /api/{translation}/{book}/{chapter}.simple.json`
212
- - `GET /api/{translation}/{book}/{chapter}.words.simple.json`
213
- - `GET /api/{translation}/complete.simple.json`
214
-
215
- ### Commentary endpoints
216
-
217
- - `GET /api/available_commentaries.json`
218
- - `GET /api/c/{commentary}/books.json`
219
- - `GET /api/c/{commentary}/{book}/{chapter}.json`
220
- - `GET /api/c/{commentary}/{book}/{chapter}.simple.json`
221
-
222
- ### Dataset endpoints
223
-
224
- - `GET /api/available_datasets.json`
225
- - `GET /api/d/{dataset}/books.json`
226
- - `GET /api/d/{dataset}/{book}/{chapter}.json`
227
-
228
- Example requests:
229
-
230
- ```bash
231
- curl https://bible.helloao.org/api/available_translations.json
232
- curl https://bible.helloao.org/api/BSB/books.json
233
- curl https://bible.helloao.org/api/BSB/GEN/1.json
234
- curl https://bible.helloao.org/api/available_commentaries.json
235
- curl https://bible.helloao.org/api/available_datasets.json
236
- ```
237
-
238
- ## Error Handling
239
-
240
- Methods throw on non-2xx responses.
241
-
242
- A 404 response usually means one of the path values is invalid, for example:
243
-
244
- - translation
245
- - commentary
246
- - dataset
247
- - book
248
- - chapter
249
-
250
- ## Notes
251
-
252
- - Uses the global `fetch` API.
253
- - For Node.js, use a runtime that provides `fetch` (Node 18+ recommended) or polyfill it.
1
+ # Free Use Bible API
2
+
3
+ TypeScript and JavaScript client for the public Free Use Bible API:
4
+
5
+ - `https://bible.helloao.org`
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install free-use-bible-api
11
+ ```
12
+
13
+ ```bash
14
+ pnpm add free-use-bible-api
15
+ ```
16
+
17
+ ```bash
18
+ yarn add free-use-bible-api
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ```ts
24
+ import { FreeUseBibleApi } from 'free-use-bible-api';
25
+
26
+ const api = new FreeUseBibleApi();
27
+
28
+ const available = await api.getAvailableTranslations();
29
+ console.log('Total translations:', available.translations.length);
30
+
31
+ const books = await api.getTranslationBooks('BSB');
32
+ console.log('Books in BSB:', books.books.length);
33
+
34
+ const chapter = await api.getTranslationBookChapter('BSB', 'GEN', 1);
35
+ console.log('Verses in Genesis 1:', chapter.numberOfVerses);
36
+ ```
37
+
38
+ ## Client Options
39
+
40
+ You can customize the client with `FreeUseBibleApiOptions`:
41
+
42
+ ```ts
43
+ import { FreeUseBibleApi } from 'free-use-bible-api';
44
+
45
+ const api = new FreeUseBibleApi({
46
+ endpoint: 'https://bible.helloao.org/',
47
+ useCache: true,
48
+ });
49
+ ```
50
+
51
+ - `endpoint`: Base API endpoint.
52
+ - `useCache`: Enables in-memory response caching (default: `true`).
53
+
54
+ ## API Methods
55
+
56
+ ### Translations
57
+
58
+ - `getAvailableTranslations(endpoint?)`
59
+ - `getTranslationBooks(translation, endpoint?)`
60
+ - `getTranslationBookChapter(translation, book, chapter, endpoint?)`
61
+ - `getTranslationBookChapterWords(translation, book, chapter, endpoint?)`
62
+ - `getCompleteTranslation(translation, endpoint?)`
63
+ - `getSimpleTranslationBookChapter(translation, book, chapter, endpoint?)`
64
+ - `getSimpleTranslationBookChapterWords(translation, book, chapter, endpoint?)`
65
+ - `getSimpleCompleteTranslation(translation, endpoint?)`
66
+
67
+ `getCompleteTranslation()` and `getSimpleCompleteTranslation()` disable per-request cache internally because payloads are typically large.
68
+
69
+ ### Commentaries
70
+
71
+ - `getAvailableCommentaries(endpoint?)`
72
+ - `getCommentaryBooks(commentary, endpoint?)`
73
+ - `getCommentaryBookChapter(commentary, book, chapter, endpoint?)`
74
+ - `getSimpleCommentaryBookChapter(commentary, book, chapter, endpoint?)`
75
+
76
+ ### Datasets
77
+
78
+ - `getAvailableDatasets(endpoint?)`
79
+ - `getDatasetBooks(dataset, endpoint?)`
80
+ - `getDatasetBookChapter(dataset, book, chapter, endpoint?)` - returns cross references for cross reference datasets, or the people, places, and events that appear in the chapter for entity datasets (such as `theographic`)
81
+ - `getDatasetPeople(dataset, endpoint?)`
82
+ - `getDatasetPerson(dataset, person, endpoint?)`
83
+ - `getDatasetPlaces(dataset, endpoint?)`
84
+ - `getDatasetPlace(dataset, place, endpoint?)`
85
+ - `getDatasetEvents(dataset, endpoint?)`
86
+ - `getDatasetEvent(dataset, event, endpoint?)`
87
+ - `getDatasetPeopleGroups(dataset, endpoint?)`
88
+ - `getDatasetPeopleGroup(dataset, group, endpoint?)`
89
+
90
+ ### Chapter Navigation Helpers
91
+
92
+ - `getNextChapter(chapter, endpoint?)`
93
+ - `getPreviousChapter(chapter, endpoint?)`
94
+
95
+ ### Chapter & Verse Helpers
96
+
97
+ - `getVerseText(verse)`
98
+ - `getChapterVerseText(chapter)`
99
+
100
+ These helpers work with translation, commentary, and dataset chapter responses, as well as simplified translation and commentary chapter responses.
101
+
102
+ ### Word Annotations
103
+
104
+ Some translations include word-level annotations (Strong's numbers and related source data) for their chapters.
105
+
106
+ - `getChapterWords(chapter, endpoint?)` - gets the annotations for a chapter you already loaded, or `null` if it doesn't have any.
107
+ - `getWordText(verse, word)` - gets the text that a single annotation applies to.
108
+ - `getVerseWords(verse, words)` - gets the annotations for a verse, each paired with the text it applies to.
109
+
110
+ Each annotation is anchored to a range of characters in a single item of a verse's `content` array: `contentIndex` is the index of the item, and `start`/`end` are character offsets into that item's text (`end` is exclusive). Anchoring per content item keeps the offsets correct for verses whose content is split into multiple items, such as poem lines and the words of Jesus.
111
+
112
+ `getWordText()` and `getVerseWords()` resolve those offsets for you, so you don't have to walk the content array yourself.
113
+
114
+ ### Simplified Chapters
115
+
116
+ Every translation and commentary chapter can also be fetched in a simplified format, where each verse's content is a single string instead of a list of formatted content. Footnotes, inline headings, the Words of Jesus, and poetry are represented as offset ranges into that string instead of being split across multiple content items.
117
+
118
+ - `getSimpleTranslationBookChapter(translation, book, chapter, endpoint?)`
119
+ - `getSimpleCommentaryBookChapter(commentary, book, chapter, endpoint?)`
120
+ - `getSimpleCompleteTranslation(translation, endpoint?)`
121
+ - `getSimpleChapter(chapter, endpoint?)` - follows a chapter's `simpleChapterApiLink`, or `null` if simplified chapters aren't available for it.
122
+ - `getSimpleTranslationBookChapterWords(translation, book, chapter, endpoint?)` / `getSimpleChapterWords(chapter, endpoint?)` - the same as the regular word annotations, but with offsets into the simplified verse text instead of a verse's content array.
123
+ - `getSimpleWordText(verse, word)` / `getSimpleVerseWords(verse, words)` - the same as `getWordText()`/`getVerseWords()`, but for simplified verses and annotations.
124
+ - `getSimpleChapterVerseText(chapter, options?)` - the same as `getChapterVerseText()`, but for a simplified chapter.
125
+
126
+ `getNextChapter()` and `getPreviousChapter()` also accept simplified chapters, returning the next/previous simplified chapter.
127
+
128
+ Datasets don't have a simplified format.
129
+
130
+ ## Examples
131
+
132
+ ### Get a complete translation
133
+
134
+ ```ts
135
+ const complete = await api.getCompleteTranslation('BSB');
136
+ console.log(complete.translation.id);
137
+ console.log(complete.books.length);
138
+ ```
139
+
140
+ ### Read a commentary chapter
141
+
142
+ ```ts
143
+ const comm = await api.getCommentaryBookChapter('matthew_henry', 'GEN', 1);
144
+ console.log(comm.book.name);
145
+ ```
146
+
147
+ ### Read a dataset chapter
148
+
149
+ ```ts
150
+ const dataChapter = await api.getDatasetBookChapter(
151
+ 'cross_references',
152
+ 'JHN',
153
+ 3
154
+ );
155
+ console.log(dataChapter.book.name);
156
+ ```
157
+
158
+ ### Navigate to next/previous chapter
159
+
160
+ ```ts
161
+ const current = await api.getTranslationBookChapter('BSB', 'GEN', 1);
162
+
163
+ const next = await api.getNextChapter(current);
164
+ const previous = await api.getPreviousChapter(current);
165
+
166
+ console.log(next?.chapter.number);
167
+ console.log(previous?.chapter.number);
168
+ ```
169
+
170
+ ### Read the Strong's numbers for a chapter
171
+
172
+ ```ts
173
+ const chapter = await api.getTranslationBookChapter('engwebp', 'JHN', 1);
174
+ const words = await api.getChapterWords(chapter);
175
+
176
+ if (!words) {
177
+ // This translation has no word-level annotations for the chapter.
178
+ return;
179
+ }
180
+
181
+ for (const content of chapter.chapter.content) {
182
+ if (content.type !== 'verse') {
183
+ continue;
184
+ }
185
+
186
+ for (const word of api.getVerseWords(content, words)) {
187
+ console.log(word.text, word.strongs);
188
+ }
189
+ }
190
+
191
+ // In [ 'G1722' ]
192
+ // the [ 'G1722' ]
193
+ // beginning [ 'G0746' ]
194
+ // ...
195
+ ```
196
+
197
+ ### Read a simplified chapter
198
+
199
+ ```ts
200
+ const chapter = await api.getSimpleTranslationBookChapter('BSB', 'JHN', 1);
201
+
202
+ for (const content of chapter.chapter.content) {
203
+ if (content.type !== 'verse') {
204
+ continue;
205
+ }
206
+ console.log(content.number, content.text);
207
+ }
208
+ ```
209
+
210
+ ## Direct HTTP Endpoints
211
+
212
+ ### Translation endpoints
213
+
214
+ - `GET /api/available_translations.json`
215
+ - `GET /api/{translation}/books.json`
216
+ - `GET /api/{translation}/{book}/{chapter}.json`
217
+ - `GET /api/{translation}/{book}/{chapter}.words.json`
218
+ - `GET /api/{translation}/complete.json`
219
+ - `GET /api/{translation}/{book}/{chapter}.simple.json`
220
+ - `GET /api/{translation}/{book}/{chapter}.words.simple.json`
221
+ - `GET /api/{translation}/complete.simple.json`
222
+
223
+ ### Commentary endpoints
224
+
225
+ - `GET /api/available_commentaries.json`
226
+ - `GET /api/c/{commentary}/books.json`
227
+ - `GET /api/c/{commentary}/{book}/{chapter}.json`
228
+ - `GET /api/c/{commentary}/{book}/{chapter}.simple.json`
229
+
230
+ ### Dataset endpoints
231
+
232
+ - `GET /api/available_datasets.json`
233
+ - `GET /api/d/{dataset}/books.json`
234
+ - `GET /api/d/{dataset}/{book}/{chapter}.json`
235
+ - `GET /api/d/{dataset}/people.json`
236
+ - `GET /api/d/{dataset}/people/{person}.json`
237
+ - `GET /api/d/{dataset}/places.json`
238
+ - `GET /api/d/{dataset}/places/{place}.json`
239
+ - `GET /api/d/{dataset}/events.json`
240
+ - `GET /api/d/{dataset}/events/{event}.json`
241
+ - `GET /api/d/{dataset}/groups.json`
242
+ - `GET /api/d/{dataset}/groups/{group}.json`
243
+
244
+ Example requests:
245
+
246
+ ```bash
247
+ curl https://bible.helloao.org/api/available_translations.json
248
+ curl https://bible.helloao.org/api/BSB/books.json
249
+ curl https://bible.helloao.org/api/BSB/GEN/1.json
250
+ curl https://bible.helloao.org/api/available_commentaries.json
251
+ curl https://bible.helloao.org/api/available_datasets.json
252
+ ```
253
+
254
+ ## Error Handling
255
+
256
+ Methods throw on non-2xx responses.
257
+
258
+ A 404 response usually means one of the path values is invalid, for example:
259
+
260
+ - translation
261
+ - commentary
262
+ - dataset
263
+ - book
264
+ - chapter
265
+
266
+ ## Notes
267
+
268
+ - Uses the global `fetch` API.
269
+ - For Node.js, use a runtime that provides `fetch` (Node 18+ recommended) or polyfill it.