@helloao/tools 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/LICENSE +21 -0
- package/generation/api.d.ts +203 -0
- package/generation/api.js +153 -0
- package/generation/api.spec.d.ts +2 -0
- package/generation/api.spec.js +463 -0
- package/generation/audio.d.ts +20 -0
- package/generation/audio.js +60 -0
- package/generation/audio.spec.d.ts +2 -0
- package/generation/audio.spec.js +36 -0
- package/generation/book-order.d.ts +15 -0
- package/generation/book-order.js +494 -0
- package/generation/book-order.spec.d.ts +2 -0
- package/generation/book-order.spec.js +8 -0
- package/generation/common-types.d.ts +327 -0
- package/generation/common-types.js +2 -0
- package/generation/dataset.d.ts +34 -0
- package/generation/dataset.js +106 -0
- package/generation/index.d.ts +7 -0
- package/generation/index.js +38 -0
- package/index.d.ts +5 -0
- package/index.js +32 -0
- package/package.json +27 -0
- package/parser/codex-parser.d.ts +97 -0
- package/parser/codex-parser.js +160 -0
- package/parser/codex-parser.spec.d.ts +2 -0
- package/parser/codex-parser.spec.js +645 -0
- package/parser/index.d.ts +7 -0
- package/parser/index.js +35 -0
- package/parser/iterators.d.ts +89 -0
- package/parser/iterators.js +222 -0
- package/parser/iterators.spec.d.ts +2 -0
- package/parser/iterators.spec.js +174 -0
- package/parser/types.d.ts +144 -0
- package/parser/types.js +2 -0
- package/parser/usfm-parser.d.ts +135 -0
- package/parser/usfm-parser.js +840 -0
- package/parser/usfm-parser.spec.d.ts +2 -0
- package/parser/usfm-parser.spec.js +1593 -0
- package/parser/usx-parser.d.ts +33 -0
- package/parser/usx-parser.js +425 -0
- package/parser/usx-parser.spec.d.ts +2 -0
- package/parser/usx-parser.spec.js +1260 -0
- package/typings/types.d.ts +14 -0
- package/utils.d.ts +29 -0
- package/utils.js +73 -0
- package/utils.spec.d.ts +2 -0
- package/utils.spec.js +42 -0
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const api_1 = require("./api");
|
|
7
|
+
const _01GENBSB_usfm_1 = __importDefault(require("../../../bible/bsb/01GENBSB.usfm"));
|
|
8
|
+
const _02EXOBSB_usfm_1 = __importDefault(require("../../../bible/bsb/02EXOBSB.usfm"));
|
|
9
|
+
const _131CHBSB_usfm_1 = __importDefault(require("../../../bible/bsb/131CHBSB.usfm"));
|
|
10
|
+
const dataset_1 = require("./dataset");
|
|
11
|
+
const linkedom_1 = require("linkedom");
|
|
12
|
+
describe('replaceSpacesWithUnderscores()', () => {
|
|
13
|
+
const cases = [
|
|
14
|
+
['Hello World', 'Hello_World'],
|
|
15
|
+
['Hello World 2', 'Hello_World_2'],
|
|
16
|
+
];
|
|
17
|
+
it.each(cases)('should replace spaces with underscores', (input, expected) => {
|
|
18
|
+
expect((0, api_1.replaceSpacesWithUnderscores)(input)).toBe(expected);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
describe('generateApiForDataset()', () => {
|
|
22
|
+
it('should output a file tree', () => {
|
|
23
|
+
let translation1 = {
|
|
24
|
+
id: 'bsb',
|
|
25
|
+
name: 'Berean Standard Bible',
|
|
26
|
+
englishName: 'Berean Standard Bible',
|
|
27
|
+
shortName: 'BSB',
|
|
28
|
+
language: 'eng',
|
|
29
|
+
direction: 'ltr',
|
|
30
|
+
licenseUrl: 'https://berean.bible/terms.htm',
|
|
31
|
+
website: 'https://berean.bible'
|
|
32
|
+
};
|
|
33
|
+
let inputFiles = [
|
|
34
|
+
{
|
|
35
|
+
fileType: 'usfm',
|
|
36
|
+
metadata: {
|
|
37
|
+
translation: translation1
|
|
38
|
+
},
|
|
39
|
+
content: firstXLines(_01GENBSB_usfm_1.default, 13)
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
fileType: 'usfm',
|
|
43
|
+
metadata: {
|
|
44
|
+
translation: translation1
|
|
45
|
+
},
|
|
46
|
+
content: firstXLines(_02EXOBSB_usfm_1.default, 14)
|
|
47
|
+
}
|
|
48
|
+
];
|
|
49
|
+
const dataset = (0, dataset_1.generateDataset)(inputFiles, new linkedom_1.DOMParser());
|
|
50
|
+
const generated = (0, api_1.generateApiForDataset)(dataset);
|
|
51
|
+
const files = (0, api_1.generateFilesForApi)(generated);
|
|
52
|
+
const tree = fileTree(files);
|
|
53
|
+
const expectedTranslation = {
|
|
54
|
+
id: 'bsb',
|
|
55
|
+
name: 'Berean Standard Bible',
|
|
56
|
+
englishName: 'Berean Standard Bible',
|
|
57
|
+
shortName: 'BSB',
|
|
58
|
+
language: 'eng',
|
|
59
|
+
textDirection: 'ltr',
|
|
60
|
+
licenseUrl: 'https://berean.bible/terms.htm',
|
|
61
|
+
website: 'https://berean.bible',
|
|
62
|
+
availableFormats: [
|
|
63
|
+
'json'
|
|
64
|
+
],
|
|
65
|
+
listOfBooksApiLink: '/api/bsb/books.json',
|
|
66
|
+
numberOfBooks: 2,
|
|
67
|
+
totalNumberOfChapters: 2,
|
|
68
|
+
totalNumberOfVerses: 4,
|
|
69
|
+
languageName: 'English',
|
|
70
|
+
languageEnglishName: 'English',
|
|
71
|
+
};
|
|
72
|
+
expect(tree).toEqual({
|
|
73
|
+
'/api/available_translations.json': {
|
|
74
|
+
translations: [
|
|
75
|
+
expectedTranslation
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
'/api/bsb/books.json': {
|
|
79
|
+
translation: expectedTranslation,
|
|
80
|
+
books: [
|
|
81
|
+
{
|
|
82
|
+
id: 'GEN',
|
|
83
|
+
name: 'Genesis',
|
|
84
|
+
commonName: 'Genesis',
|
|
85
|
+
title: 'Genesis',
|
|
86
|
+
order: 1,
|
|
87
|
+
numberOfChapters: 1,
|
|
88
|
+
totalNumberOfVerses: 2,
|
|
89
|
+
firstChapterApiLink: '/api/bsb/GEN/1.json',
|
|
90
|
+
lastChapterApiLink: '/api/bsb/GEN/1.json',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
id: 'EXO',
|
|
94
|
+
name: 'Exodus',
|
|
95
|
+
commonName: 'Exodus',
|
|
96
|
+
title: 'Exodus',
|
|
97
|
+
order: 2,
|
|
98
|
+
numberOfChapters: 1,
|
|
99
|
+
totalNumberOfVerses: 2,
|
|
100
|
+
firstChapterApiLink: '/api/bsb/EXO/1.json',
|
|
101
|
+
lastChapterApiLink: '/api/bsb/EXO/1.json',
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
},
|
|
105
|
+
'/api/bsb/GEN/1.json': {
|
|
106
|
+
translation: expectedTranslation,
|
|
107
|
+
book: {
|
|
108
|
+
id: 'GEN',
|
|
109
|
+
name: 'Genesis',
|
|
110
|
+
commonName: 'Genesis',
|
|
111
|
+
title: 'Genesis',
|
|
112
|
+
order: 1,
|
|
113
|
+
numberOfChapters: 1,
|
|
114
|
+
totalNumberOfVerses: 2,
|
|
115
|
+
firstChapterApiLink: '/api/bsb/GEN/1.json',
|
|
116
|
+
lastChapterApiLink: '/api/bsb/GEN/1.json'
|
|
117
|
+
},
|
|
118
|
+
thisChapterLink: '/api/bsb/GEN/1.json',
|
|
119
|
+
thisChapterAudioLinks: {},
|
|
120
|
+
nextChapterApiLink: '/api/bsb/EXO/1.json',
|
|
121
|
+
nextChapterAudioLinks: {},
|
|
122
|
+
previousChapterApiLink: null,
|
|
123
|
+
previousChapterAudioLinks: null,
|
|
124
|
+
numberOfVerses: 2,
|
|
125
|
+
chapter: {
|
|
126
|
+
number: 1,
|
|
127
|
+
content: [
|
|
128
|
+
{
|
|
129
|
+
type: 'heading',
|
|
130
|
+
content: [
|
|
131
|
+
'The Creation'
|
|
132
|
+
]
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
type: 'line_break'
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
type: 'verse',
|
|
139
|
+
number: 1,
|
|
140
|
+
content: [
|
|
141
|
+
'In the beginning God created the heavens and the earth.'
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
type: 'line_break'
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
type: 'verse',
|
|
149
|
+
number: 2,
|
|
150
|
+
content: [
|
|
151
|
+
'Now the earth was formless and void, and darkness was over the surface of the deep. And the Spirit of God was hovering over the surface of the waters.'
|
|
152
|
+
],
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
footnotes: []
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
'/api/bsb/EXO/1.json': {
|
|
159
|
+
translation: expectedTranslation,
|
|
160
|
+
book: {
|
|
161
|
+
id: 'EXO',
|
|
162
|
+
name: 'Exodus',
|
|
163
|
+
commonName: 'Exodus',
|
|
164
|
+
title: 'Exodus',
|
|
165
|
+
order: 2,
|
|
166
|
+
numberOfChapters: 1,
|
|
167
|
+
totalNumberOfVerses: 2,
|
|
168
|
+
firstChapterApiLink: '/api/bsb/EXO/1.json',
|
|
169
|
+
lastChapterApiLink: '/api/bsb/EXO/1.json'
|
|
170
|
+
},
|
|
171
|
+
thisChapterLink: '/api/bsb/EXO/1.json',
|
|
172
|
+
thisChapterAudioLinks: {},
|
|
173
|
+
nextChapterApiLink: null,
|
|
174
|
+
nextChapterAudioLinks: null,
|
|
175
|
+
previousChapterApiLink: '/api/bsb/GEN/1.json',
|
|
176
|
+
previousChapterAudioLinks: {},
|
|
177
|
+
numberOfVerses: 2,
|
|
178
|
+
chapter: {
|
|
179
|
+
number: 1,
|
|
180
|
+
content: [
|
|
181
|
+
{
|
|
182
|
+
type: 'heading',
|
|
183
|
+
content: [
|
|
184
|
+
'The Israelites Multiply in Egypt'
|
|
185
|
+
]
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
type: 'line_break'
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
type: 'verse',
|
|
192
|
+
number: 1,
|
|
193
|
+
content: [
|
|
194
|
+
'These are the names of the sons of Israel who went to Egypt with Jacob, each with his family:'
|
|
195
|
+
],
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
type: 'line_break'
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
type: 'verse',
|
|
202
|
+
number: 2,
|
|
203
|
+
content: [
|
|
204
|
+
'Reuben, Simeon, Levi, and Judah;'
|
|
205
|
+
],
|
|
206
|
+
},
|
|
207
|
+
],
|
|
208
|
+
footnotes: []
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
// expect(availableTranslations).toEqual({
|
|
213
|
+
// translations: [
|
|
214
|
+
// expectedTranslation
|
|
215
|
+
// ]
|
|
216
|
+
// });
|
|
217
|
+
});
|
|
218
|
+
it('should use underscores for spaces in the book name', () => {
|
|
219
|
+
let translation1 = {
|
|
220
|
+
id: 'bsb',
|
|
221
|
+
name: 'Berean Standard Bible',
|
|
222
|
+
englishName: 'Berean Standard Bible',
|
|
223
|
+
shortName: 'BSB',
|
|
224
|
+
language: 'eng',
|
|
225
|
+
direction: 'ltr',
|
|
226
|
+
licenseUrl: 'https://berean.bible/terms.htm',
|
|
227
|
+
website: 'https://berean.bible'
|
|
228
|
+
};
|
|
229
|
+
let inputFiles = [
|
|
230
|
+
{
|
|
231
|
+
fileType: 'usfm',
|
|
232
|
+
metadata: {
|
|
233
|
+
translation: translation1
|
|
234
|
+
},
|
|
235
|
+
content: firstXLines(_131CHBSB_usfm_1.default, 11)
|
|
236
|
+
},
|
|
237
|
+
];
|
|
238
|
+
const dataset = (0, dataset_1.generateDataset)(inputFiles, new linkedom_1.DOMParser());
|
|
239
|
+
const generated = (0, api_1.generateApiForDataset)(dataset, {
|
|
240
|
+
useCommonName: true,
|
|
241
|
+
});
|
|
242
|
+
const files = (0, api_1.generateFilesForApi)(generated);
|
|
243
|
+
const tree = fileTree(files);
|
|
244
|
+
const expectedTranslation = {
|
|
245
|
+
id: 'bsb',
|
|
246
|
+
name: 'Berean Standard Bible',
|
|
247
|
+
englishName: 'Berean Standard Bible',
|
|
248
|
+
shortName: 'BSB',
|
|
249
|
+
language: 'eng',
|
|
250
|
+
textDirection: 'ltr',
|
|
251
|
+
licenseUrl: 'https://berean.bible/terms.htm',
|
|
252
|
+
website: 'https://berean.bible',
|
|
253
|
+
availableFormats: [
|
|
254
|
+
'json'
|
|
255
|
+
],
|
|
256
|
+
listOfBooksApiLink: '/api/bsb/books.json',
|
|
257
|
+
numberOfBooks: 1,
|
|
258
|
+
totalNumberOfChapters: 1,
|
|
259
|
+
totalNumberOfVerses: 1,
|
|
260
|
+
languageName: 'English',
|
|
261
|
+
languageEnglishName: 'English',
|
|
262
|
+
};
|
|
263
|
+
expect(tree).toEqual({
|
|
264
|
+
'/api/available_translations.json': {
|
|
265
|
+
translations: [
|
|
266
|
+
expectedTranslation
|
|
267
|
+
]
|
|
268
|
+
},
|
|
269
|
+
'/api/bsb/books.json': {
|
|
270
|
+
translation: expectedTranslation,
|
|
271
|
+
books: [
|
|
272
|
+
{
|
|
273
|
+
id: '1CH',
|
|
274
|
+
name: '1 Chronicles',
|
|
275
|
+
commonName: '1 Chronicles',
|
|
276
|
+
title: '1 Chronicles',
|
|
277
|
+
numberOfChapters: 1,
|
|
278
|
+
totalNumberOfVerses: 1,
|
|
279
|
+
order: 13,
|
|
280
|
+
firstChapterApiLink: '/api/bsb/1_Chronicles/1.json',
|
|
281
|
+
lastChapterApiLink: '/api/bsb/1_Chronicles/1.json',
|
|
282
|
+
},
|
|
283
|
+
]
|
|
284
|
+
},
|
|
285
|
+
'/api/bsb/1_Chronicles/1.json': {
|
|
286
|
+
translation: expectedTranslation,
|
|
287
|
+
book: {
|
|
288
|
+
id: '1CH',
|
|
289
|
+
name: '1 Chronicles',
|
|
290
|
+
commonName: '1 Chronicles',
|
|
291
|
+
title: '1 Chronicles',
|
|
292
|
+
numberOfChapters: 1,
|
|
293
|
+
totalNumberOfVerses: 1,
|
|
294
|
+
order: 13,
|
|
295
|
+
firstChapterApiLink: '/api/bsb/1_Chronicles/1.json',
|
|
296
|
+
lastChapterApiLink: '/api/bsb/1_Chronicles/1.json'
|
|
297
|
+
},
|
|
298
|
+
thisChapterLink: "/api/bsb/1_Chronicles/1.json",
|
|
299
|
+
thisChapterAudioLinks: {},
|
|
300
|
+
nextChapterApiLink: null,
|
|
301
|
+
nextChapterAudioLinks: null,
|
|
302
|
+
previousChapterApiLink: null,
|
|
303
|
+
previousChapterAudioLinks: null,
|
|
304
|
+
numberOfVerses: 1,
|
|
305
|
+
chapter: {
|
|
306
|
+
number: 1,
|
|
307
|
+
content: [
|
|
308
|
+
{
|
|
309
|
+
type: 'heading',
|
|
310
|
+
content: [
|
|
311
|
+
'From Adam to Abraham'
|
|
312
|
+
]
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
type: 'line_break'
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
type: 'verse',
|
|
319
|
+
number: 1,
|
|
320
|
+
content: [
|
|
321
|
+
'Adam, Seth, Enosh,'
|
|
322
|
+
],
|
|
323
|
+
},
|
|
324
|
+
],
|
|
325
|
+
footnotes: []
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
});
|
|
329
|
+
// expect(availableTranslations).toEqual({
|
|
330
|
+
// translations: [
|
|
331
|
+
// expectedTranslation
|
|
332
|
+
// ]
|
|
333
|
+
// });
|
|
334
|
+
});
|
|
335
|
+
it('produce the correct names for languages', () => {
|
|
336
|
+
let translation1 = {
|
|
337
|
+
id: 'bsb',
|
|
338
|
+
name: 'Berean Standard Bible',
|
|
339
|
+
englishName: 'Berean Standard Bible',
|
|
340
|
+
shortName: 'BSB',
|
|
341
|
+
language: 'spa',
|
|
342
|
+
direction: 'ltr',
|
|
343
|
+
licenseUrl: 'https://berean.bible/terms.htm',
|
|
344
|
+
website: 'https://berean.bible'
|
|
345
|
+
};
|
|
346
|
+
let inputFiles = [
|
|
347
|
+
{
|
|
348
|
+
fileType: 'usfm',
|
|
349
|
+
metadata: {
|
|
350
|
+
translation: translation1
|
|
351
|
+
},
|
|
352
|
+
content: firstXLines(_131CHBSB_usfm_1.default, 11)
|
|
353
|
+
},
|
|
354
|
+
];
|
|
355
|
+
const dataset = (0, dataset_1.generateDataset)(inputFiles, new linkedom_1.DOMParser());
|
|
356
|
+
const generated = (0, api_1.generateApiForDataset)(dataset, {
|
|
357
|
+
useCommonName: true,
|
|
358
|
+
});
|
|
359
|
+
const files = (0, api_1.generateFilesForApi)(generated);
|
|
360
|
+
const tree = fileTree(files);
|
|
361
|
+
const expectedTranslation = {
|
|
362
|
+
id: 'bsb',
|
|
363
|
+
name: 'Berean Standard Bible',
|
|
364
|
+
englishName: 'Berean Standard Bible',
|
|
365
|
+
shortName: 'BSB',
|
|
366
|
+
language: 'spa',
|
|
367
|
+
textDirection: 'ltr',
|
|
368
|
+
licenseUrl: 'https://berean.bible/terms.htm',
|
|
369
|
+
website: 'https://berean.bible',
|
|
370
|
+
availableFormats: [
|
|
371
|
+
'json'
|
|
372
|
+
],
|
|
373
|
+
listOfBooksApiLink: '/api/bsb/books.json',
|
|
374
|
+
numberOfBooks: 1,
|
|
375
|
+
totalNumberOfChapters: 1,
|
|
376
|
+
totalNumberOfVerses: 1,
|
|
377
|
+
languageName: 'español',
|
|
378
|
+
languageEnglishName: 'Spanish',
|
|
379
|
+
};
|
|
380
|
+
expect(tree).toEqual({
|
|
381
|
+
'/api/available_translations.json': {
|
|
382
|
+
translations: [
|
|
383
|
+
expectedTranslation
|
|
384
|
+
]
|
|
385
|
+
},
|
|
386
|
+
'/api/bsb/books.json': {
|
|
387
|
+
translation: expectedTranslation,
|
|
388
|
+
books: [
|
|
389
|
+
{
|
|
390
|
+
id: '1CH',
|
|
391
|
+
name: '1 Chronicles',
|
|
392
|
+
commonName: '1 Chronicles',
|
|
393
|
+
title: '1 Chronicles',
|
|
394
|
+
numberOfChapters: 1,
|
|
395
|
+
totalNumberOfVerses: 1,
|
|
396
|
+
order: 13,
|
|
397
|
+
firstChapterApiLink: '/api/bsb/1_Chronicles/1.json',
|
|
398
|
+
lastChapterApiLink: '/api/bsb/1_Chronicles/1.json',
|
|
399
|
+
},
|
|
400
|
+
]
|
|
401
|
+
},
|
|
402
|
+
'/api/bsb/1_Chronicles/1.json': {
|
|
403
|
+
translation: expectedTranslation,
|
|
404
|
+
book: {
|
|
405
|
+
id: '1CH',
|
|
406
|
+
name: '1 Chronicles',
|
|
407
|
+
commonName: '1 Chronicles',
|
|
408
|
+
title: '1 Chronicles',
|
|
409
|
+
numberOfChapters: 1,
|
|
410
|
+
totalNumberOfVerses: 1,
|
|
411
|
+
order: 13,
|
|
412
|
+
firstChapterApiLink: '/api/bsb/1_Chronicles/1.json',
|
|
413
|
+
lastChapterApiLink: '/api/bsb/1_Chronicles/1.json'
|
|
414
|
+
},
|
|
415
|
+
thisChapterLink: "/api/bsb/1_Chronicles/1.json",
|
|
416
|
+
thisChapterAudioLinks: {},
|
|
417
|
+
nextChapterApiLink: null,
|
|
418
|
+
nextChapterAudioLinks: null,
|
|
419
|
+
previousChapterApiLink: null,
|
|
420
|
+
previousChapterAudioLinks: null,
|
|
421
|
+
numberOfVerses: 1,
|
|
422
|
+
chapter: {
|
|
423
|
+
number: 1,
|
|
424
|
+
content: [
|
|
425
|
+
{
|
|
426
|
+
type: 'heading',
|
|
427
|
+
content: [
|
|
428
|
+
'From Adam to Abraham'
|
|
429
|
+
]
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
type: 'line_break'
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
type: 'verse',
|
|
436
|
+
number: 1,
|
|
437
|
+
content: [
|
|
438
|
+
'Adam, Seth, Enosh,'
|
|
439
|
+
],
|
|
440
|
+
},
|
|
441
|
+
],
|
|
442
|
+
footnotes: []
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
});
|
|
446
|
+
// expect(availableTranslations).toEqual({
|
|
447
|
+
// translations: [
|
|
448
|
+
// expectedTranslation
|
|
449
|
+
// ]
|
|
450
|
+
// });
|
|
451
|
+
});
|
|
452
|
+
});
|
|
453
|
+
function firstXLines(content, x) {
|
|
454
|
+
const lines = content.split('\n');
|
|
455
|
+
return lines.slice(0, x).join('\n');
|
|
456
|
+
}
|
|
457
|
+
function fileTree(outputFiles) {
|
|
458
|
+
let result = {};
|
|
459
|
+
for (let file of outputFiles) {
|
|
460
|
+
result[file.path] = file.content;
|
|
461
|
+
}
|
|
462
|
+
return result;
|
|
463
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TranslationBookChapterAudioLinks } from "./common-types";
|
|
2
|
+
type AudioTranslationUrlGenerator = (bookId: string, chapter: number) => string;
|
|
3
|
+
/**
|
|
4
|
+
* A map of translation IDs to a map of reader IDs to the URL generator for the audio file.
|
|
5
|
+
*/
|
|
6
|
+
export declare const KNOWN_AUDIO_TRANSLATIONS: Map<string, Map<string, AudioTranslationUrlGenerator>>;
|
|
7
|
+
/**
|
|
8
|
+
* Gets the audio URLs for the given translation, book, and chapter.
|
|
9
|
+
* @param translationId The ID of the translation.
|
|
10
|
+
* @param bookId The ID of the book.
|
|
11
|
+
* @param chapter The number of the chapter.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getAudioUrlsForChapter(translationId: string, bookId: string, chapter: number): TranslationBookChapterAudioLinks;
|
|
14
|
+
/**
|
|
15
|
+
* Capitalizes the first letter of the given string.
|
|
16
|
+
* @param str The string to capitalize.
|
|
17
|
+
*/
|
|
18
|
+
export declare function capitalize(str: string): string;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=audio.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KNOWN_AUDIO_TRANSLATIONS = void 0;
|
|
4
|
+
exports.getAudioUrlsForChapter = getAudioUrlsForChapter;
|
|
5
|
+
exports.capitalize = capitalize;
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
const book_order_1 = require("./book-order");
|
|
8
|
+
const openBibleUrlGenerator = (translation, reader, postfix) => {
|
|
9
|
+
return (bookId, chapter) => {
|
|
10
|
+
const bookOrder = (0, lodash_1.padStart)(book_order_1.bookOrderMap.get(bookId).toString(), 2, '0');
|
|
11
|
+
const chapterStr = (0, lodash_1.padStart)(chapter.toString(), 3, '0');
|
|
12
|
+
let link = `https://openbible.com/audio/${reader}/${translation}_${bookOrder}_${capitalize(bookId)}_${chapterStr}`;
|
|
13
|
+
if (postfix) {
|
|
14
|
+
link += `_${postfix}`;
|
|
15
|
+
}
|
|
16
|
+
link += '.mp3';
|
|
17
|
+
return link;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* A map of translation IDs to a map of reader IDs to the URL generator for the audio file.
|
|
22
|
+
*/
|
|
23
|
+
exports.KNOWN_AUDIO_TRANSLATIONS = new Map([
|
|
24
|
+
['BSB', new Map([
|
|
25
|
+
['gilbert', openBibleUrlGenerator('BSB', 'gilbert', 'G')],
|
|
26
|
+
['hays', openBibleUrlGenerator('BSB', 'hays', "H")],
|
|
27
|
+
['souer', openBibleUrlGenerator('BSB', 'souer', null)],
|
|
28
|
+
])],
|
|
29
|
+
]);
|
|
30
|
+
/**
|
|
31
|
+
* Gets the audio URLs for the given translation, book, and chapter.
|
|
32
|
+
* @param translationId The ID of the translation.
|
|
33
|
+
* @param bookId The ID of the book.
|
|
34
|
+
* @param chapter The number of the chapter.
|
|
35
|
+
*/
|
|
36
|
+
function getAudioUrlsForChapter(translationId, bookId, chapter) {
|
|
37
|
+
const translation = exports.KNOWN_AUDIO_TRANSLATIONS.get(translationId);
|
|
38
|
+
if (!translation) {
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
const links = {};
|
|
42
|
+
for (let [reader, generator] of translation) {
|
|
43
|
+
const url = generator(bookId, chapter);
|
|
44
|
+
if (url) {
|
|
45
|
+
links[reader] = url;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return links;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Capitalizes the first letter of the given string.
|
|
52
|
+
* @param str The string to capitalize.
|
|
53
|
+
*/
|
|
54
|
+
function capitalize(str) {
|
|
55
|
+
const char = str.charAt(0);
|
|
56
|
+
if (/[0-9]/.test(char)) {
|
|
57
|
+
return str.charAt(0) + str.charAt(1).toUpperCase() + str.slice(2).toLowerCase();
|
|
58
|
+
}
|
|
59
|
+
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
60
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const audio_1 = require("./audio");
|
|
4
|
+
describe('capitalize()', () => {
|
|
5
|
+
const cases = [
|
|
6
|
+
['empty', '', ''],
|
|
7
|
+
['single letter', 'a', 'A'],
|
|
8
|
+
['number', '1abc', '1Abc'],
|
|
9
|
+
['word', 'word', 'Word'],
|
|
10
|
+
['lowercase rest', 'WORD', 'Word'],
|
|
11
|
+
['sentence', 'this is a sentence', 'This is a sentence'],
|
|
12
|
+
];
|
|
13
|
+
it.each(cases)('should capitalize %s', (_desc, input, expected) => {
|
|
14
|
+
expect((0, audio_1.capitalize)(input)).toBe(expected);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
describe('KNOWN_AUDIO_TRANSLATIONS', () => {
|
|
18
|
+
const cases = [
|
|
19
|
+
// Gilbert
|
|
20
|
+
['BSB', 'gilbert', 'GEN', 1, 'https://openbible.com/audio/gilbert/BSB_01_Gen_001_G.mp3'],
|
|
21
|
+
['BSB', 'gilbert', '1SA', 5, 'https://openbible.com/audio/gilbert/BSB_09_1Sa_005_G.mp3'],
|
|
22
|
+
['BSB', 'gilbert', 'PSA', 110, 'https://openbible.com/audio/gilbert/BSB_19_Psa_110_G.mp3'],
|
|
23
|
+
// Hays
|
|
24
|
+
['BSB', 'hays', 'GEN', 1, 'https://openbible.com/audio/hays/BSB_01_Gen_001_H.mp3'],
|
|
25
|
+
['BSB', 'hays', '1SA', 5, 'https://openbible.com/audio/hays/BSB_09_1Sa_005_H.mp3'],
|
|
26
|
+
['BSB', 'hays', 'PSA', 110, 'https://openbible.com/audio/hays/BSB_19_Psa_110_H.mp3'],
|
|
27
|
+
// Souer
|
|
28
|
+
['BSB', 'souer', 'GEN', 1, 'https://openbible.com/audio/souer/BSB_01_Gen_001.mp3'],
|
|
29
|
+
['BSB', 'souer', '1SA', 5, 'https://openbible.com/audio/souer/BSB_09_1Sa_005.mp3'],
|
|
30
|
+
['BSB', 'souer', 'PSA', 110, 'https://openbible.com/audio/souer/BSB_19_Psa_110.mp3'],
|
|
31
|
+
];
|
|
32
|
+
it.each(cases)('should generate the correct URL for %s %s %s', (translationId, reader, bookId, chapter, expected) => {
|
|
33
|
+
const generator = audio_1.KNOWN_AUDIO_TRANSLATIONS.get(translationId).get(reader);
|
|
34
|
+
expect(generator(bookId, chapter)).toBe(expected);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines a map that maps the book ID to the numerical order of the book.
|
|
3
|
+
*/
|
|
4
|
+
export declare const bookOrderMap: Map<string, number>;
|
|
5
|
+
/**
|
|
6
|
+
* Defines a map that maps the book ID to the number of chapters the book has.
|
|
7
|
+
*/
|
|
8
|
+
export declare const bookChapterCountMap: Map<string, number>;
|
|
9
|
+
/**
|
|
10
|
+
* Defines a map that maps a locale ID to a book name map.
|
|
11
|
+
*/
|
|
12
|
+
export declare const bookIdMap: Map<string, Map<string, {
|
|
13
|
+
commonName: string;
|
|
14
|
+
}>>;
|
|
15
|
+
//# sourceMappingURL=book-order.d.ts.map
|