free-use-bible-api 0.2.0 → 0.3.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 +253 -170
- package/dist/cjs/FreeUseBibleApi.cjs +205 -2
- package/dist/cjs/FreeUseBibleApi.cjs.map +2 -2
- package/dist/cjs/types.gen.cjs.map +1 -1
- package/dist/esm/FreeUseBibleApi.js +205 -2
- package/dist/esm/FreeUseBibleApi.js.map +2 -2
- package/dist/types/FreeUseBibleApi.d.ts +162 -1
- package/dist/types/types.gen.d.ts +912 -37
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,170 +1,253 @@
|
|
|
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
|
-
- `
|
|
62
|
-
|
|
63
|
-
`
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
- `
|
|
74
|
-
- `
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
- `
|
|
80
|
-
- `
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
###
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
###
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
-
|
|
170
|
-
|
|
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.
|
|
@@ -54,6 +54,21 @@ class FreeUseBibleApi {
|
|
|
54
54
|
false
|
|
55
55
|
);
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Gets the complete content of a specific Bible translation, using the simplified chapter format.
|
|
59
|
+
*
|
|
60
|
+
* The results of this endpoint are very large, so the response is not cached.
|
|
61
|
+
* @param translation The ID of the translation to get the complete content for.
|
|
62
|
+
* @param endpoint The API endpoint to use for the request. If not provided, the default endpoint will be used.
|
|
63
|
+
*/
|
|
64
|
+
async getSimpleCompleteTranslation(translation, endpoint) {
|
|
65
|
+
const encodedTranslation = encodeURIComponent(translation);
|
|
66
|
+
return this._getJson(
|
|
67
|
+
`api/${encodedTranslation}/complete.simple.json`,
|
|
68
|
+
endpoint,
|
|
69
|
+
false
|
|
70
|
+
);
|
|
71
|
+
}
|
|
57
72
|
/**
|
|
58
73
|
* Gets the list of available Bible commentaries from the API.
|
|
59
74
|
* @param endpoint The API endpoint to use for the request. If not provided, the default endpoint will be used.
|
|
@@ -94,7 +109,7 @@ class FreeUseBibleApi {
|
|
|
94
109
|
async getCommentaryBooks(commentary, endpoint) {
|
|
95
110
|
const encodedCommentary = encodeURIComponent(commentary);
|
|
96
111
|
return this._getJson(
|
|
97
|
-
`api/${encodedCommentary}/books.json`,
|
|
112
|
+
`api/c/${encodedCommentary}/books.json`,
|
|
98
113
|
endpoint
|
|
99
114
|
);
|
|
100
115
|
}
|
|
@@ -126,6 +141,98 @@ class FreeUseBibleApi {
|
|
|
126
141
|
endpoint
|
|
127
142
|
);
|
|
128
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Gets the word-level annotations (Strong's numbers and related source data) for a specific chapter of a specific book for a specific Bible translation.
|
|
146
|
+
*
|
|
147
|
+
* Only some translations have word-level annotations. This request will fail for chapters that don't have any.
|
|
148
|
+
* Use `getChapterWords()` to get the annotations for a chapter that you have already loaded, which returns null instead of failing.
|
|
149
|
+
* @param translation The ID of the translation to get the annotations for.
|
|
150
|
+
* @param book The ID of the book to get the annotations for.
|
|
151
|
+
* @param chapter The chapter number to get the annotations for.
|
|
152
|
+
* @param endpoint The API endpoint to use for the request. If not provided, the default endpoint will be used.
|
|
153
|
+
*/
|
|
154
|
+
async getTranslationBookChapterWords(translation, book, chapter, endpoint) {
|
|
155
|
+
const encodedTranslation = encodeURIComponent(translation);
|
|
156
|
+
const encodedBook = encodeURIComponent(book);
|
|
157
|
+
const encodedChapter = encodeURIComponent(String(chapter));
|
|
158
|
+
return this._getJson(
|
|
159
|
+
`api/${encodedTranslation}/${encodedBook}/${encodedChapter}.words.json`,
|
|
160
|
+
endpoint
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Gets the word-level annotations for the given chapter, if it has any.
|
|
165
|
+
* @param chapter The chapter to get the annotations for.
|
|
166
|
+
* @param endpoint The API endpoint to use for the request. If not provided, the default endpoint will be used.
|
|
167
|
+
* @returns The annotations for the chapter, or null if the chapter doesn't have any.
|
|
168
|
+
*/
|
|
169
|
+
async getChapterWords(chapter, endpoint) {
|
|
170
|
+
if (!chapter.thisChapterWordsLink) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
return this._getJson(
|
|
174
|
+
chapter.thisChapterWordsLink,
|
|
175
|
+
endpoint
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Gets the content of a specific chapter of a specific book for a specific Bible translation, using the simplified chapter format.
|
|
180
|
+
*
|
|
181
|
+
* In the simplified format, each verse's content is a single string instead of a list of formatted content, and footnotes, inline headings, the Words of Jesus, and poetry are represented as offset ranges into that string.
|
|
182
|
+
* @param translation The ID of the translation to get the chapter for.
|
|
183
|
+
* @param book The ID of the book to get the chapter for.
|
|
184
|
+
* @param chapter The chapter number to get.
|
|
185
|
+
* @param endpoint The API endpoint to use for the request. If not provided, the default endpoint will be used.
|
|
186
|
+
*/
|
|
187
|
+
async getSimpleTranslationBookChapter(translation, book, chapter, endpoint) {
|
|
188
|
+
const encodedTranslation = encodeURIComponent(translation);
|
|
189
|
+
const encodedBook = encodeURIComponent(book);
|
|
190
|
+
const encodedChapter = encodeURIComponent(String(chapter));
|
|
191
|
+
return this._getJson(
|
|
192
|
+
`api/${encodedTranslation}/${encodedBook}/${encodedChapter}.simple.json`,
|
|
193
|
+
endpoint
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Gets the word-level annotations (Strong's numbers and related source data) for a specific chapter of a specific book for a specific Bible translation, with their offsets remapped onto the text of each simplified verse.
|
|
198
|
+
*
|
|
199
|
+
* Use this instead of `getTranslationBookChapterWords()` when working with the simplified chapter format, since the offsets in the regular annotations are anchored to a verse's content array instead of its plain text.
|
|
200
|
+
* Use `getSimpleChapterWords()` to get the annotations for a simplified chapter that you have already loaded, which returns null instead of failing.
|
|
201
|
+
* @param translation The ID of the translation to get the annotations for.
|
|
202
|
+
* @param book The ID of the book to get the annotations for.
|
|
203
|
+
* @param chapter The chapter number to get the annotations for.
|
|
204
|
+
* @param endpoint The API endpoint to use for the request. If not provided, the default endpoint will be used.
|
|
205
|
+
*/
|
|
206
|
+
async getSimpleTranslationBookChapterWords(translation, book, chapter, endpoint) {
|
|
207
|
+
const encodedTranslation = encodeURIComponent(translation);
|
|
208
|
+
const encodedBook = encodeURIComponent(book);
|
|
209
|
+
const encodedChapter = encodeURIComponent(String(chapter));
|
|
210
|
+
return this._getJson(
|
|
211
|
+
`api/${encodedTranslation}/${encodedBook}/${encodedChapter}.words.simple.json`,
|
|
212
|
+
endpoint
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
async getSimpleChapter(chapter, endpoint) {
|
|
216
|
+
if (!chapter.simpleChapterApiLink) {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
return this._getJson(chapter.simpleChapterApiLink, endpoint);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Gets the word-level annotations for the given simplified chapter, if it has any.
|
|
223
|
+
* @param chapter The simplified chapter to get the annotations for.
|
|
224
|
+
* @param endpoint The API endpoint to use for the request. If not provided, the default endpoint will be used.
|
|
225
|
+
* @returns The annotations for the chapter, or null if the chapter doesn't have any.
|
|
226
|
+
*/
|
|
227
|
+
async getSimpleChapterWords(chapter, endpoint) {
|
|
228
|
+
if (!chapter.thisChapterWordsLink) {
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
return this._getJson(
|
|
232
|
+
chapter.thisChapterWordsLink,
|
|
233
|
+
endpoint
|
|
234
|
+
);
|
|
235
|
+
}
|
|
129
236
|
/**
|
|
130
237
|
* Gets the content of a specific chapter of a specific book for a specific Bible commentary.
|
|
131
238
|
* @param commentary The ID of the commentary to get the chapter for.
|
|
@@ -138,7 +245,23 @@ class FreeUseBibleApi {
|
|
|
138
245
|
const encodedBook = encodeURIComponent(book);
|
|
139
246
|
const encodedChapter = encodeURIComponent(String(chapter));
|
|
140
247
|
return this._getJson(
|
|
141
|
-
`api/${encodedCommentary}/${encodedBook}/${encodedChapter}.json`,
|
|
248
|
+
`api/c/${encodedCommentary}/${encodedBook}/${encodedChapter}.json`,
|
|
249
|
+
endpoint
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Gets the content of a specific chapter of a specific book for a specific Bible commentary, using the simplified chapter format.
|
|
254
|
+
* @param commentary The ID of the commentary to get the chapter for.
|
|
255
|
+
* @param book The ID of the book to get the chapter for.
|
|
256
|
+
* @param chapter The chapter number to get.
|
|
257
|
+
* @param endpoint The API endpoint to use for the request. If not provided, the default endpoint will be used.
|
|
258
|
+
*/
|
|
259
|
+
async getSimpleCommentaryBookChapter(commentary, book, chapter, endpoint) {
|
|
260
|
+
const encodedCommentary = encodeURIComponent(commentary);
|
|
261
|
+
const encodedBook = encodeURIComponent(book);
|
|
262
|
+
const encodedChapter = encodeURIComponent(String(chapter));
|
|
263
|
+
return this._getJson(
|
|
264
|
+
`api/c/${encodedCommentary}/${encodedBook}/${encodedChapter}.simple.json`,
|
|
142
265
|
endpoint
|
|
143
266
|
);
|
|
144
267
|
}
|
|
@@ -259,6 +382,86 @@ ${content.trim()}`;
|
|
|
259
382
|
}
|
|
260
383
|
return content.trim();
|
|
261
384
|
}
|
|
385
|
+
/**
|
|
386
|
+
* Gets the verse text for the given simplified chapter.
|
|
387
|
+
* By default, the returned text includes markers for verse numbers and a reference to the chapter, but these can be omitted by passing options to the `options` parameter.
|
|
388
|
+
* @param chapter The simplified chapter to get the text for.
|
|
389
|
+
* @param options Options for getting the chapter text.
|
|
390
|
+
*/
|
|
391
|
+
getSimpleChapterVerseText(chapter, options = {}) {
|
|
392
|
+
let content = "";
|
|
393
|
+
for (let chapterContent of chapter.chapter.content) {
|
|
394
|
+
if (chapterContent.type === "verse") {
|
|
395
|
+
if (!options.omitVerseNumbers) {
|
|
396
|
+
content += `[${chapterContent.number}] `;
|
|
397
|
+
}
|
|
398
|
+
content += chapterContent.text.trim() + " ";
|
|
399
|
+
} else if (chapterContent.type === "line_break") {
|
|
400
|
+
content = content.trim() + "\n";
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
if (!options.omitReference) {
|
|
404
|
+
content = `${this.formatReference(chapter.book, {
|
|
405
|
+
chapter: chapter.chapter.number
|
|
406
|
+
})}
|
|
407
|
+
${content.trim()}`;
|
|
408
|
+
}
|
|
409
|
+
return content.trim();
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Gets the text that the given word-level annotation applies to.
|
|
413
|
+
*
|
|
414
|
+
* Annotations are anchored to a range of characters in a single item of the verse's content,
|
|
415
|
+
* so that the ranges stay correct for verses whose content is split into multiple items,
|
|
416
|
+
* such as poem lines and the words of Jesus.
|
|
417
|
+
* @param verse The verse that the annotation is in.
|
|
418
|
+
* @param word The annotation to get the text for.
|
|
419
|
+
* @returns The annotated text, or an empty string if the annotation doesn't point at any text.
|
|
420
|
+
*/
|
|
421
|
+
getWordText(verse, word) {
|
|
422
|
+
const content = verse.content[word.contentIndex];
|
|
423
|
+
if (typeof content === "string") {
|
|
424
|
+
return content.slice(word.start, word.end);
|
|
425
|
+
} else if (typeof content === "object" && content !== null && "text" in content) {
|
|
426
|
+
return content.text.slice(word.start, word.end);
|
|
427
|
+
}
|
|
428
|
+
return "";
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Gets the word-level annotations for the given verse, paired with the text that each one applies to.
|
|
432
|
+
* @param verse The verse to get the annotations for.
|
|
433
|
+
* @param words The annotations for the chapter that the verse is in.
|
|
434
|
+
* @returns The annotations for the verse, in the order that they occur. Empty if the verse has no annotations.
|
|
435
|
+
*/
|
|
436
|
+
getVerseWords(verse, words) {
|
|
437
|
+
const verseWords = words.verses[verse.number.toString()] ?? [];
|
|
438
|
+
return verseWords.map((word) => ({
|
|
439
|
+
...word,
|
|
440
|
+
text: this.getWordText(verse, word)
|
|
441
|
+
}));
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Gets the text that the given simplified word-level annotation applies to.
|
|
445
|
+
* @param verse The simplified verse that the annotation is in.
|
|
446
|
+
* @param word The annotation to get the text for.
|
|
447
|
+
* @returns The annotated text.
|
|
448
|
+
*/
|
|
449
|
+
getSimpleWordText(verse, word) {
|
|
450
|
+
return verse.text.slice(word.start, word.end);
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Gets the word-level annotations for the given simplified verse, paired with the text that each one applies to.
|
|
454
|
+
* @param verse The simplified verse to get the annotations for.
|
|
455
|
+
* @param words The simplified annotations for the chapter that the verse is in.
|
|
456
|
+
* @returns The annotations for the verse, in the order that they occur. Empty if the verse has no annotations.
|
|
457
|
+
*/
|
|
458
|
+
getSimpleVerseWords(verse, words) {
|
|
459
|
+
const verseWords = words.verses[verse.number.toString()] ?? [];
|
|
460
|
+
return verseWords.map((word) => ({
|
|
461
|
+
...word,
|
|
462
|
+
text: this.getSimpleWordText(verse, word)
|
|
463
|
+
}));
|
|
464
|
+
}
|
|
262
465
|
_getJson(path, endpoint, useCache = true) {
|
|
263
466
|
const url = this._buildUrl(path, endpoint);
|
|
264
467
|
const existing = this._responseCache.get(url);
|