free-use-bible-api 0.2.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 +104 -5
- package/dist/cjs/FreeUseBibleApi.cjs +306 -2
- package/dist/cjs/FreeUseBibleApi.cjs.map +2 -2
- package/dist/cjs/types.gen.cjs.map +1 -1
- package/dist/esm/FreeUseBibleApi.js +306 -2
- package/dist/esm/FreeUseBibleApi.js.map +2 -2
- package/dist/types/FreeUseBibleApi.d.ts +238 -2
- package/dist/types/types.gen.d.ts +2095 -300
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -58,28 +58,74 @@ const api = new FreeUseBibleApi({
|
|
|
58
58
|
- `getAvailableTranslations(endpoint?)`
|
|
59
59
|
- `getTranslationBooks(translation, endpoint?)`
|
|
60
60
|
- `getTranslationBookChapter(translation, book, chapter, endpoint?)`
|
|
61
|
+
- `getTranslationBookChapterWords(translation, book, chapter, endpoint?)`
|
|
61
62
|
- `getCompleteTranslation(translation, endpoint?)`
|
|
63
|
+
- `getSimpleTranslationBookChapter(translation, book, chapter, endpoint?)`
|
|
64
|
+
- `getSimpleTranslationBookChapterWords(translation, book, chapter, endpoint?)`
|
|
65
|
+
- `getSimpleCompleteTranslation(translation, endpoint?)`
|
|
62
66
|
|
|
63
|
-
`getCompleteTranslation()`
|
|
67
|
+
`getCompleteTranslation()` and `getSimpleCompleteTranslation()` disable per-request cache internally because payloads are typically large.
|
|
64
68
|
|
|
65
69
|
### Commentaries
|
|
66
70
|
|
|
67
71
|
- `getAvailableCommentaries(endpoint?)`
|
|
68
72
|
- `getCommentaryBooks(commentary, endpoint?)`
|
|
69
73
|
- `getCommentaryBookChapter(commentary, book, chapter, endpoint?)`
|
|
74
|
+
- `getSimpleCommentaryBookChapter(commentary, book, chapter, endpoint?)`
|
|
70
75
|
|
|
71
76
|
### Datasets
|
|
72
77
|
|
|
73
78
|
- `getAvailableDatasets(endpoint?)`
|
|
74
79
|
- `getDatasetBooks(dataset, endpoint?)`
|
|
75
|
-
- `getDatasetBookChapter(dataset, book, chapter, 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?)`
|
|
76
89
|
|
|
77
90
|
### Chapter Navigation Helpers
|
|
78
91
|
|
|
79
92
|
- `getNextChapter(chapter, endpoint?)`
|
|
80
93
|
- `getPreviousChapter(chapter, endpoint?)`
|
|
81
94
|
|
|
82
|
-
|
|
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.
|
|
83
129
|
|
|
84
130
|
## Examples
|
|
85
131
|
|
|
@@ -121,6 +167,46 @@ console.log(next?.chapter.number);
|
|
|
121
167
|
console.log(previous?.chapter.number);
|
|
122
168
|
```
|
|
123
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
|
+
|
|
124
210
|
## Direct HTTP Endpoints
|
|
125
211
|
|
|
126
212
|
### Translation endpoints
|
|
@@ -128,19 +214,32 @@ console.log(previous?.chapter.number);
|
|
|
128
214
|
- `GET /api/available_translations.json`
|
|
129
215
|
- `GET /api/{translation}/books.json`
|
|
130
216
|
- `GET /api/{translation}/{book}/{chapter}.json`
|
|
217
|
+
- `GET /api/{translation}/{book}/{chapter}.words.json`
|
|
131
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`
|
|
132
222
|
|
|
133
223
|
### Commentary endpoints
|
|
134
224
|
|
|
135
225
|
- `GET /api/available_commentaries.json`
|
|
136
|
-
- `GET /api/{commentary}/books.json`
|
|
137
|
-
- `GET /api/{commentary}/{book}/{chapter}.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`
|
|
138
229
|
|
|
139
230
|
### Dataset endpoints
|
|
140
231
|
|
|
141
232
|
- `GET /api/available_datasets.json`
|
|
142
233
|
- `GET /api/d/{dataset}/books.json`
|
|
143
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`
|
|
144
243
|
|
|
145
244
|
Example requests:
|
|
146
245
|
|
|
@@ -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
|
}
|
|
@@ -110,6 +125,115 @@ class FreeUseBibleApi {
|
|
|
110
125
|
endpoint
|
|
111
126
|
);
|
|
112
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Gets the list of people for a given dataset.
|
|
130
|
+
* @param dataset The ID of the dataset to get the people for.
|
|
131
|
+
* @param endpoint The endpoint to use for the request. If not provided, then the default endpoint will be used.
|
|
132
|
+
*/
|
|
133
|
+
async getDatasetPeople(dataset, endpoint) {
|
|
134
|
+
const encodedDataset = encodeURIComponent(dataset);
|
|
135
|
+
return this._getJson(
|
|
136
|
+
`api/d/${encodedDataset}/people.json`,
|
|
137
|
+
endpoint
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Gets the information about a specific person for a given dataset.
|
|
142
|
+
* Includes the Bible references that mention the person and their relationships
|
|
143
|
+
* to other people, places, events, and people groups.
|
|
144
|
+
* @param dataset The ID of the dataset to get the person for.
|
|
145
|
+
* @param person The ID of the person to get.
|
|
146
|
+
* @param endpoint The endpoint to use for the request. If not provided, then the default endpoint will be used.
|
|
147
|
+
*/
|
|
148
|
+
async getDatasetPerson(dataset, person, endpoint) {
|
|
149
|
+
const encodedDataset = encodeURIComponent(dataset);
|
|
150
|
+
const encodedPerson = encodeURIComponent(person);
|
|
151
|
+
return this._getJson(
|
|
152
|
+
`api/d/${encodedDataset}/people/${encodedPerson}.json`,
|
|
153
|
+
endpoint
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Gets the list of places for a given dataset.
|
|
158
|
+
* @param dataset The ID of the dataset to get the places for.
|
|
159
|
+
* @param endpoint The endpoint to use for the request. If not provided, then the default endpoint will be used.
|
|
160
|
+
*/
|
|
161
|
+
async getDatasetPlaces(dataset, endpoint) {
|
|
162
|
+
const encodedDataset = encodeURIComponent(dataset);
|
|
163
|
+
return this._getJson(
|
|
164
|
+
`api/d/${encodedDataset}/places.json`,
|
|
165
|
+
endpoint
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Gets the information about a specific place for a given dataset.
|
|
170
|
+
* Includes the Bible references that mention the place and its related people and events.
|
|
171
|
+
* @param dataset The ID of the dataset to get the place for.
|
|
172
|
+
* @param place The ID of the place to get.
|
|
173
|
+
* @param endpoint The endpoint to use for the request. If not provided, then the default endpoint will be used.
|
|
174
|
+
*/
|
|
175
|
+
async getDatasetPlace(dataset, place, endpoint) {
|
|
176
|
+
const encodedDataset = encodeURIComponent(dataset);
|
|
177
|
+
const encodedPlace = encodeURIComponent(place);
|
|
178
|
+
return this._getJson(
|
|
179
|
+
`api/d/${encodedDataset}/places/${encodedPlace}.json`,
|
|
180
|
+
endpoint
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Gets the list of events for a given dataset.
|
|
185
|
+
* @param dataset The ID of the dataset to get the events for.
|
|
186
|
+
* @param endpoint The endpoint to use for the request. If not provided, then the default endpoint will be used.
|
|
187
|
+
*/
|
|
188
|
+
async getDatasetEvents(dataset, endpoint) {
|
|
189
|
+
const encodedDataset = encodeURIComponent(dataset);
|
|
190
|
+
return this._getJson(
|
|
191
|
+
`api/d/${encodedDataset}/events.json`,
|
|
192
|
+
endpoint
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Gets the information about a specific event for a given dataset.
|
|
197
|
+
* Includes the Bible references that describe the event and its related people, places, and people groups.
|
|
198
|
+
* @param dataset The ID of the dataset to get the event for.
|
|
199
|
+
* @param event The ID of the event to get.
|
|
200
|
+
* @param endpoint The endpoint to use for the request. If not provided, then the default endpoint will be used.
|
|
201
|
+
*/
|
|
202
|
+
async getDatasetEvent(dataset, event, endpoint) {
|
|
203
|
+
const encodedDataset = encodeURIComponent(dataset);
|
|
204
|
+
const encodedEvent = encodeURIComponent(event);
|
|
205
|
+
return this._getJson(
|
|
206
|
+
`api/d/${encodedDataset}/events/${encodedEvent}.json`,
|
|
207
|
+
endpoint
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Gets the list of people groups for a given dataset.
|
|
212
|
+
* @param dataset The ID of the dataset to get the people groups for.
|
|
213
|
+
* @param endpoint The endpoint to use for the request. If not provided, then the default endpoint will be used.
|
|
214
|
+
*/
|
|
215
|
+
async getDatasetPeopleGroups(dataset, endpoint) {
|
|
216
|
+
const encodedDataset = encodeURIComponent(dataset);
|
|
217
|
+
return this._getJson(
|
|
218
|
+
`api/d/${encodedDataset}/groups.json`,
|
|
219
|
+
endpoint
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Gets the information about a specific people group for a given dataset.
|
|
224
|
+
* Includes the members of the group and the events that the group participated in.
|
|
225
|
+
* @param dataset The ID of the dataset to get the people group for.
|
|
226
|
+
* @param group The ID of the people group to get.
|
|
227
|
+
* @param endpoint The endpoint to use for the request. If not provided, then the default endpoint will be used.
|
|
228
|
+
*/
|
|
229
|
+
async getDatasetPeopleGroup(dataset, group, endpoint) {
|
|
230
|
+
const encodedDataset = encodeURIComponent(dataset);
|
|
231
|
+
const encodedGroup = encodeURIComponent(group);
|
|
232
|
+
return this._getJson(
|
|
233
|
+
`api/d/${encodedDataset}/groups/${encodedGroup}.json`,
|
|
234
|
+
endpoint
|
|
235
|
+
);
|
|
236
|
+
}
|
|
113
237
|
/**
|
|
114
238
|
* Gets the content of a specific chapter of a specific book for a specific Bible translation.
|
|
115
239
|
* @param translation The ID of the translation to get the chapter for.
|
|
@@ -126,6 +250,86 @@ class FreeUseBibleApi {
|
|
|
126
250
|
endpoint
|
|
127
251
|
);
|
|
128
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* 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.
|
|
255
|
+
*
|
|
256
|
+
* Only some translations have word-level annotations. This request will fail for chapters that don't have any.
|
|
257
|
+
* Use `getChapterWords()` to get the annotations for a chapter that you have already loaded, which returns null instead of failing.
|
|
258
|
+
* @param translation The ID of the translation to get the annotations for.
|
|
259
|
+
* @param book The ID of the book to get the annotations for.
|
|
260
|
+
* @param chapter The chapter number to get the annotations for.
|
|
261
|
+
* @param endpoint The API endpoint to use for the request. If not provided, the default endpoint will be used.
|
|
262
|
+
*/
|
|
263
|
+
async getTranslationBookChapterWords(translation, book, chapter, endpoint) {
|
|
264
|
+
const encodedTranslation = encodeURIComponent(translation);
|
|
265
|
+
const encodedBook = encodeURIComponent(book);
|
|
266
|
+
const encodedChapter = encodeURIComponent(String(chapter));
|
|
267
|
+
return this._getJson(
|
|
268
|
+
`api/${encodedTranslation}/${encodedBook}/${encodedChapter}.words.json`,
|
|
269
|
+
endpoint
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
async getChapterWords(chapter, endpoint) {
|
|
273
|
+
if (!chapter.thisChapterWordsLink) {
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
return this._getJson(
|
|
277
|
+
chapter.thisChapterWordsLink,
|
|
278
|
+
endpoint
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Gets the content of a specific chapter of a specific book for a specific Bible translation, using the simplified chapter format.
|
|
283
|
+
*
|
|
284
|
+
* 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.
|
|
285
|
+
* @param translation The ID of the translation to get the chapter for.
|
|
286
|
+
* @param book The ID of the book to get the chapter for.
|
|
287
|
+
* @param chapter The chapter number to get.
|
|
288
|
+
* @param endpoint The API endpoint to use for the request. If not provided, the default endpoint will be used.
|
|
289
|
+
*/
|
|
290
|
+
async getSimpleTranslationBookChapter(translation, book, chapter, endpoint) {
|
|
291
|
+
const encodedTranslation = encodeURIComponent(translation);
|
|
292
|
+
const encodedBook = encodeURIComponent(book);
|
|
293
|
+
const encodedChapter = encodeURIComponent(String(chapter));
|
|
294
|
+
return this._getJson(
|
|
295
|
+
`api/${encodedTranslation}/${encodedBook}/${encodedChapter}.simple.json`,
|
|
296
|
+
endpoint
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* 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.
|
|
301
|
+
*
|
|
302
|
+
* 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.
|
|
303
|
+
* Use `getSimpleChapterWords()` to get the annotations for a simplified chapter that you have already loaded, which returns null instead of failing.
|
|
304
|
+
* @param translation The ID of the translation to get the annotations for.
|
|
305
|
+
* @param book The ID of the book to get the annotations for.
|
|
306
|
+
* @param chapter The chapter number to get the annotations for.
|
|
307
|
+
* @param endpoint The API endpoint to use for the request. If not provided, the default endpoint will be used.
|
|
308
|
+
*/
|
|
309
|
+
async getSimpleTranslationBookChapterWords(translation, book, chapter, endpoint) {
|
|
310
|
+
const encodedTranslation = encodeURIComponent(translation);
|
|
311
|
+
const encodedBook = encodeURIComponent(book);
|
|
312
|
+
const encodedChapter = encodeURIComponent(String(chapter));
|
|
313
|
+
return this._getJson(
|
|
314
|
+
`api/${encodedTranslation}/${encodedBook}/${encodedChapter}.words.simple.json`,
|
|
315
|
+
endpoint
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
async getSimpleChapter(chapter, endpoint) {
|
|
319
|
+
if (!chapter.simpleChapterApiLink) {
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
return this._getJson(chapter.simpleChapterApiLink, endpoint);
|
|
323
|
+
}
|
|
324
|
+
async getSimpleChapterWords(chapter, endpoint) {
|
|
325
|
+
if (!chapter.thisChapterWordsLink) {
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
return this._getJson(
|
|
329
|
+
chapter.thisChapterWordsLink,
|
|
330
|
+
endpoint
|
|
331
|
+
);
|
|
332
|
+
}
|
|
129
333
|
/**
|
|
130
334
|
* Gets the content of a specific chapter of a specific book for a specific Bible commentary.
|
|
131
335
|
* @param commentary The ID of the commentary to get the chapter for.
|
|
@@ -138,12 +342,32 @@ class FreeUseBibleApi {
|
|
|
138
342
|
const encodedBook = encodeURIComponent(book);
|
|
139
343
|
const encodedChapter = encodeURIComponent(String(chapter));
|
|
140
344
|
return this._getJson(
|
|
141
|
-
`api/${encodedCommentary}/${encodedBook}/${encodedChapter}.json`,
|
|
345
|
+
`api/c/${encodedCommentary}/${encodedBook}/${encodedChapter}.json`,
|
|
346
|
+
endpoint
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Gets the content of a specific chapter of a specific book for a specific Bible commentary, using the simplified chapter format.
|
|
351
|
+
* @param commentary The ID of the commentary to get the chapter for.
|
|
352
|
+
* @param book The ID of the book to get the chapter for.
|
|
353
|
+
* @param chapter The chapter number to get.
|
|
354
|
+
* @param endpoint The API endpoint to use for the request. If not provided, the default endpoint will be used.
|
|
355
|
+
*/
|
|
356
|
+
async getSimpleCommentaryBookChapter(commentary, book, chapter, endpoint) {
|
|
357
|
+
const encodedCommentary = encodeURIComponent(commentary);
|
|
358
|
+
const encodedBook = encodeURIComponent(book);
|
|
359
|
+
const encodedChapter = encodeURIComponent(String(chapter));
|
|
360
|
+
return this._getJson(
|
|
361
|
+
`api/c/${encodedCommentary}/${encodedBook}/${encodedChapter}.simple.json`,
|
|
142
362
|
endpoint
|
|
143
363
|
);
|
|
144
364
|
}
|
|
145
365
|
/**
|
|
146
366
|
* Gets the content of a specific chapter of a specific book for a specific dataset.
|
|
367
|
+
*
|
|
368
|
+
* For cross reference datasets, this is the list of cross references for each verse
|
|
369
|
+
* in the chapter. For entity datasets (such as "theographic"), this is the people,
|
|
370
|
+
* places, and events that appear in the chapter.
|
|
147
371
|
* @param dataset The ID of the dataset to get the chapter for.
|
|
148
372
|
* @param book The ID of the book to get the chapter for.
|
|
149
373
|
* @param chapter The chapter number to get.
|
|
@@ -259,6 +483,86 @@ ${content.trim()}`;
|
|
|
259
483
|
}
|
|
260
484
|
return content.trim();
|
|
261
485
|
}
|
|
486
|
+
/**
|
|
487
|
+
* Gets the verse text for the given simplified chapter.
|
|
488
|
+
* 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.
|
|
489
|
+
* @param chapter The simplified chapter to get the text for.
|
|
490
|
+
* @param options Options for getting the chapter text.
|
|
491
|
+
*/
|
|
492
|
+
getSimpleChapterVerseText(chapter, options = {}) {
|
|
493
|
+
let content = "";
|
|
494
|
+
for (let chapterContent of chapter.chapter.content) {
|
|
495
|
+
if (chapterContent.type === "verse") {
|
|
496
|
+
if (!options.omitVerseNumbers) {
|
|
497
|
+
content += `[${chapterContent.number}] `;
|
|
498
|
+
}
|
|
499
|
+
content += chapterContent.text.trim() + " ";
|
|
500
|
+
} else if (chapterContent.type === "line_break") {
|
|
501
|
+
content = content.trim() + "\n";
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
if (!options.omitReference) {
|
|
505
|
+
content = `${this.formatReference(chapter.book, {
|
|
506
|
+
chapter: chapter.chapter.number
|
|
507
|
+
})}
|
|
508
|
+
${content.trim()}`;
|
|
509
|
+
}
|
|
510
|
+
return content.trim();
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Gets the text that the given word-level annotation applies to.
|
|
514
|
+
*
|
|
515
|
+
* Annotations are anchored to a range of characters in a single item of the verse's content,
|
|
516
|
+
* so that the ranges stay correct for verses whose content is split into multiple items,
|
|
517
|
+
* such as poem lines and the words of Jesus.
|
|
518
|
+
* @param verse The verse that the annotation is in.
|
|
519
|
+
* @param word The annotation to get the text for.
|
|
520
|
+
* @returns The annotated text, or an empty string if the annotation doesn't point at any text.
|
|
521
|
+
*/
|
|
522
|
+
getWordText(verse, word) {
|
|
523
|
+
const content = verse.content[word.contentIndex];
|
|
524
|
+
if (typeof content === "string") {
|
|
525
|
+
return content.slice(word.start, word.end);
|
|
526
|
+
} else if (typeof content === "object" && content !== null && "text" in content) {
|
|
527
|
+
return content.text.slice(word.start, word.end);
|
|
528
|
+
}
|
|
529
|
+
return "";
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Gets the word-level annotations for the given verse, paired with the text that each one applies to.
|
|
533
|
+
* @param verse The verse to get the annotations for.
|
|
534
|
+
* @param words The annotations for the chapter that the verse is in.
|
|
535
|
+
* @returns The annotations for the verse, in the order that they occur. Empty if the verse has no annotations.
|
|
536
|
+
*/
|
|
537
|
+
getVerseWords(verse, words) {
|
|
538
|
+
const verseWords = words.verses[verse.number.toString()] ?? [];
|
|
539
|
+
return verseWords.map((word) => ({
|
|
540
|
+
...word,
|
|
541
|
+
text: this.getWordText(verse, word)
|
|
542
|
+
}));
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Gets the text that the given simplified word-level annotation applies to.
|
|
546
|
+
* @param verse The simplified verse that the annotation is in.
|
|
547
|
+
* @param word The annotation to get the text for.
|
|
548
|
+
* @returns The annotated text.
|
|
549
|
+
*/
|
|
550
|
+
getSimpleWordText(verse, word) {
|
|
551
|
+
return verse.text.slice(word.start, word.end);
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Gets the word-level annotations for the given simplified verse, paired with the text that each one applies to.
|
|
555
|
+
* @param verse The simplified verse to get the annotations for.
|
|
556
|
+
* @param words The simplified annotations for the chapter that the verse is in.
|
|
557
|
+
* @returns The annotations for the verse, in the order that they occur. Empty if the verse has no annotations.
|
|
558
|
+
*/
|
|
559
|
+
getSimpleVerseWords(verse, words) {
|
|
560
|
+
const verseWords = words.verses[verse.number.toString()] ?? [];
|
|
561
|
+
return verseWords.map((word) => ({
|
|
562
|
+
...word,
|
|
563
|
+
text: this.getSimpleWordText(verse, word)
|
|
564
|
+
}));
|
|
565
|
+
}
|
|
262
566
|
_getJson(path, endpoint, useCache = true) {
|
|
263
567
|
const url = this._buildUrl(path, endpoint);
|
|
264
568
|
const existing = this._responseCache.get(url);
|