@helloao/tools 0.0.4 → 0.0.6-alpha

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.
Files changed (105) hide show
  1. package/README.md +6 -6
  2. package/dist/cjs/generation/api.cjs +240 -0
  3. package/dist/cjs/generation/api.cjs.map +7 -0
  4. package/dist/cjs/generation/audio.cjs +83 -0
  5. package/dist/cjs/generation/audio.cjs.map +7 -0
  6. package/dist/cjs/generation/book-order.cjs +508 -0
  7. package/dist/cjs/generation/book-order.cjs.map +7 -0
  8. package/dist/cjs/generation/common-types.cjs +17 -0
  9. package/dist/cjs/generation/common-types.cjs.map +7 -0
  10. package/dist/cjs/generation/dataset.cjs +158 -0
  11. package/dist/cjs/generation/dataset.cjs.map +7 -0
  12. package/dist/cjs/generation/index.cjs +51 -0
  13. package/dist/cjs/generation/index.cjs.map +7 -0
  14. package/dist/cjs/index.cjs +45 -0
  15. package/dist/cjs/index.cjs.map +7 -0
  16. package/dist/cjs/parser/codex-parser.cjs +176 -0
  17. package/dist/cjs/parser/codex-parser.cjs.map +7 -0
  18. package/dist/cjs/parser/index.cjs +48 -0
  19. package/dist/cjs/parser/index.cjs.map +7 -0
  20. package/dist/cjs/parser/iterators.cjs +204 -0
  21. package/dist/cjs/parser/iterators.cjs.map +7 -0
  22. package/dist/cjs/parser/types.cjs +17 -0
  23. package/dist/cjs/parser/types.cjs.map +7 -0
  24. package/dist/cjs/parser/usfm-parser.cjs +791 -0
  25. package/dist/cjs/parser/usfm-parser.cjs.map +7 -0
  26. package/dist/cjs/parser/usx-parser.cjs +471 -0
  27. package/dist/cjs/parser/usx-parser.cjs.map +7 -0
  28. package/dist/cjs/utils.cjs +85 -0
  29. package/dist/cjs/utils.cjs.map +7 -0
  30. package/dist/esm/generation/api.js +198 -0
  31. package/dist/esm/generation/api.js.map +7 -0
  32. package/dist/esm/generation/audio.js +53 -0
  33. package/dist/esm/generation/audio.js.map +7 -0
  34. package/dist/esm/generation/book-order.js +478 -0
  35. package/dist/esm/generation/book-order.js.map +7 -0
  36. package/dist/esm/generation/common-types.js +2 -0
  37. package/dist/esm/generation/common-types.js.map +7 -0
  38. package/dist/esm/generation/dataset.js +132 -0
  39. package/dist/esm/generation/dataset.js.map +7 -0
  40. package/dist/esm/generation/index.js +8 -0
  41. package/dist/esm/generation/index.js.map +7 -0
  42. package/dist/esm/index.js +6 -0
  43. package/dist/esm/index.js.map +7 -0
  44. package/dist/esm/parser/codex-parser.js +144 -0
  45. package/dist/esm/parser/codex-parser.js.map +7 -0
  46. package/dist/esm/parser/index.js +8 -0
  47. package/dist/esm/parser/index.js.map +7 -0
  48. package/dist/esm/parser/iterators.js +152 -0
  49. package/dist/esm/parser/iterators.js.map +7 -0
  50. package/dist/esm/parser/types.js +2 -0
  51. package/dist/esm/parser/types.js.map +7 -0
  52. package/dist/esm/parser/usfm-parser.js +749 -0
  53. package/dist/esm/parser/usfm-parser.js.map +7 -0
  54. package/dist/esm/parser/usx-parser.js +447 -0
  55. package/dist/esm/parser/usx-parser.js.map +7 -0
  56. package/dist/esm/utils.js +51 -0
  57. package/dist/esm/utils.js.map +7 -0
  58. package/{generation → dist/types/generation}/api.d.ts +46 -5
  59. package/{generation → dist/types/generation}/audio.d.ts +1 -1
  60. package/{generation → dist/types/generation}/dataset.d.ts +1 -1
  61. package/dist/types/generation/index.d.ts +7 -0
  62. package/dist/types/index.d.ts +5 -0
  63. package/{parser → dist/types/parser}/codex-parser.d.ts +1 -1
  64. package/dist/types/parser/index.d.ts +7 -0
  65. package/{parser → dist/types/parser}/usfm-parser.d.ts +1 -1
  66. package/{parser → dist/types/parser}/usx-parser.d.ts +2 -2
  67. package/package.json +25 -4
  68. package/generation/api.js +0 -153
  69. package/generation/api.spec.d.ts +0 -2
  70. package/generation/api.spec.js +0 -463
  71. package/generation/audio.js +0 -60
  72. package/generation/audio.spec.d.ts +0 -2
  73. package/generation/audio.spec.js +0 -36
  74. package/generation/book-order.js +0 -494
  75. package/generation/book-order.spec.d.ts +0 -2
  76. package/generation/book-order.spec.js +0 -8
  77. package/generation/common-types.js +0 -2
  78. package/generation/dataset.js +0 -106
  79. package/generation/index.d.ts +0 -7
  80. package/generation/index.js +0 -38
  81. package/index.d.ts +0 -5
  82. package/index.js +0 -32
  83. package/parser/codex-parser.js +0 -160
  84. package/parser/codex-parser.spec.d.ts +0 -2
  85. package/parser/codex-parser.spec.js +0 -645
  86. package/parser/index.d.ts +0 -7
  87. package/parser/index.js +0 -35
  88. package/parser/iterators.js +0 -222
  89. package/parser/iterators.spec.d.ts +0 -2
  90. package/parser/iterators.spec.js +0 -174
  91. package/parser/types.js +0 -2
  92. package/parser/usfm-parser.js +0 -840
  93. package/parser/usfm-parser.spec.d.ts +0 -2
  94. package/parser/usfm-parser.spec.js +0 -1593
  95. package/parser/usx-parser.js +0 -425
  96. package/parser/usx-parser.spec.d.ts +0 -2
  97. package/parser/usx-parser.spec.js +0 -1260
  98. package/utils.js +0 -73
  99. package/utils.spec.d.ts +0 -2
  100. package/utils.spec.js +0 -42
  101. /package/{generation → dist/types/generation}/book-order.d.ts +0 -0
  102. /package/{generation → dist/types/generation}/common-types.d.ts +0 -0
  103. /package/{parser → dist/types/parser}/iterators.d.ts +0 -0
  104. /package/{parser → dist/types/parser}/types.d.ts +0 -0
  105. /package/{utils.d.ts → dist/types/utils.d.ts} +0 -0
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ export function normalizeLanguage(language) {
3
+ return language;
4
+ }
5
+ const TRANSLATION_ID_MAP = /* @__PURE__ */ new Map([
6
+ ["eng_bsb", "BSB"],
7
+ ["arb_nav", "ARBNAV"],
8
+ ["eng_webp", "ENGWEBP"],
9
+ ["hin_irv", "HINIRV"],
10
+ ["hbo_mas", "HBOMAS"]
11
+ ]);
12
+ export function getTranslationId(translationId) {
13
+ return TRANSLATION_ID_MAP.get(translationId) ?? translationId;
14
+ }
15
+ export function isEmptyOrWhitespace(str) {
16
+ return !str || /^\s*$/.test(str);
17
+ }
18
+ export function getFirstNonEmpty(...values) {
19
+ for (let value of values) {
20
+ if (!isEmptyOrWhitespace(value)) {
21
+ return value;
22
+ }
23
+ }
24
+ throw new Error("All values are empty or whitespace!");
25
+ }
26
+ export function parseVerseReference(text) {
27
+ const match = text.match(/^\s*([A-Z]+)\s+(\d+):(\d+)/);
28
+ if (!match) {
29
+ return null;
30
+ }
31
+ const [reference, book, chapterStr, verseStr] = match;
32
+ const chapter = parseInt(chapterStr);
33
+ const verse = parseInt(verseStr);
34
+ if (isNaN(chapter) || isNaN(verse)) {
35
+ return null;
36
+ }
37
+ if (reference.length !== text.length) {
38
+ return {
39
+ book,
40
+ chapter,
41
+ verse,
42
+ content: text.substring(reference.length).trim()
43
+ };
44
+ }
45
+ return {
46
+ book,
47
+ chapter,
48
+ verse
49
+ };
50
+ }
51
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../utils.ts"],
4
+ "sourcesContent": ["\r\n/**\r\n * Normalizes the given language code into a ISO 639 code.\r\n * @param language The language code to normalize.\r\n */\r\nexport function normalizeLanguage(language: string): string {\r\n return language;\r\n}\r\n\r\n/**\r\n * The map of translation IDs from fetch.bible to their translation ID in the API.\r\n */\r\nconst TRANSLATION_ID_MAP: Map<string, string> = new Map([\r\n ['eng_bsb', 'BSB'],\r\n ['arb_nav', 'ARBNAV'],\r\n ['eng_webp', 'ENGWEBP'],\r\n ['hin_irv', 'HINIRV'],\r\n ['hbo_mas', 'HBOMAS'],\r\n]);\r\n\r\n/**\r\n * Gets the ID of the translation.\r\n * @param translation The translation to get the ID for.\r\n */\r\nexport function getTranslationId(translationId: string): string {\r\n return TRANSLATION_ID_MAP.get(translationId) ?? translationId;\r\n}\r\n\r\nexport function isEmptyOrWhitespace(str: string | null | undefined): boolean {\r\n return !str || /^\\s*$/.test(str);\r\n}\r\n\r\nexport function getFirstNonEmpty<T extends string>(...values: T[]): T {\r\n for (let value of values) {\r\n if (!isEmptyOrWhitespace(value)) {\r\n return value;\r\n }\r\n }\r\n\r\n throw new Error('All values are empty or whitespace!');\r\n}\r\n\r\nexport interface VerseRef {\r\n book: string;\r\n chapter: number;\r\n verse: number;\r\n\r\n /**\r\n * The rest of the content of the verse.\r\n */\r\n content?: string;\r\n}\r\n\r\n/**\r\n * Parses the given verse reference.\r\n * Formatted like \"GEN 1:1\".\r\n * \r\n * @param text The reference to parse.\r\n */\r\nexport function parseVerseReference(text: string): VerseRef | null {\r\n const match = text.match(/^\\s*([A-Z]+)\\s+(\\d+):(\\d+)/);\r\n\r\n if (!match) {\r\n return null;\r\n }\r\n\r\n const [reference, book, chapterStr, verseStr] = match;\r\n\r\n const chapter = parseInt(chapterStr);\r\n const verse = parseInt(verseStr);\r\n\r\n if (isNaN(chapter) || isNaN(verse)) {\r\n return null;\r\n }\r\n\r\n if (reference.length !== text.length) {\r\n return {\r\n book,\r\n chapter,\r\n verse,\r\n content: text.substring(reference.length).trim(),\r\n };\r\n }\r\n\r\n return {\r\n book,\r\n chapter,\r\n verse,\r\n };\r\n}"],
5
+ "mappings": ";AAKO,gBAAS,kBAAkB,UAA0B;AACxD,SAAO;AACX;AAKA,MAAM,qBAA0C,oBAAI,IAAI;AAAA,EACpD,CAAC,WAAW,KAAK;AAAA,EACjB,CAAC,WAAW,QAAQ;AAAA,EACpB,CAAC,YAAY,SAAS;AAAA,EACtB,CAAC,WAAW,QAAQ;AAAA,EACpB,CAAC,WAAW,QAAQ;AACxB,CAAC;AAMM,gBAAS,iBAAiB,eAA+B;AAC5D,SAAO,mBAAmB,IAAI,aAAa,KAAK;AACpD;AAEO,gBAAS,oBAAoB,KAAyC;AACzE,SAAO,CAAC,OAAO,QAAQ,KAAK,GAAG;AACnC;AAEO,gBAAS,oBAAsC,QAAgB;AAClE,WAAS,SAAS,QAAQ;AACtB,QAAI,CAAC,oBAAoB,KAAK,GAAG;AAC7B,aAAO;AAAA,IACX;AAAA,EACJ;AAEA,QAAM,IAAI,MAAM,qCAAqC;AACzD;AAmBO,gBAAS,oBAAoB,MAA+B;AAC/D,QAAM,QAAQ,KAAK,MAAM,4BAA4B;AAErD,MAAI,CAAC,OAAO;AACR,WAAO;AAAA,EACX;AAEA,QAAM,CAAC,WAAW,MAAM,YAAY,QAAQ,IAAI;AAEhD,QAAM,UAAU,SAAS,UAAU;AACnC,QAAM,QAAQ,SAAS,QAAQ;AAE/B,MAAI,MAAM,OAAO,KAAK,MAAM,KAAK,GAAG;AAChC,WAAO;AAAA,EACX;AAEA,MAAI,UAAU,WAAW,KAAK,QAAQ;AAClC,WAAO;AAAA,MACH;AAAA,MACA;AAAA,MACA;AAAA,MACA,SAAS,KAAK,UAAU,UAAU,MAAM,EAAE,KAAK;AAAA,IACnD;AAAA,EACJ;AAEA,SAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;",
6
+ "names": []
7
+ }
@@ -1,5 +1,5 @@
1
- import { OutputFile, Translation, TranslationBook, TranslationBookChapter, TranslationBookChapterAudioLinks } from "./common-types";
2
- import { DatasetOutput } from "./dataset";
1
+ import { OutputFile, Translation, TranslationBook, TranslationBookChapter, TranslationBookChapterAudioLinks } from './common-types.js';
2
+ import { DatasetOutput } from './dataset.js';
3
3
  /**
4
4
  * Defines the output of the API generation.
5
5
  */
@@ -27,6 +27,10 @@ export interface ApiOutput {
27
27
  * - /api/:translationId/:bookId/:chapterNumber.:reader.mp3
28
28
  */
29
29
  translationBookChapterAudio: ApiTranslationBookChapterAudio[];
30
+ /**
31
+ * The path prefix that the API should use.
32
+ */
33
+ pathPrefix: string;
30
34
  }
31
35
  /**
32
36
  * The list of available translations.
@@ -168,6 +172,9 @@ export interface ApiTranslationBookChapterAudio {
168
172
  */
169
173
  originalUrl: string;
170
174
  }
175
+ /**
176
+ * The options for generating the API.
177
+ */
171
178
  export interface GenerateApiOptions {
172
179
  /**
173
180
  * Whether to use the common name for the book chapter API link. If false, then book IDs are used.
@@ -182,6 +189,22 @@ export interface GenerateApiOptions {
182
189
  * Defaults to false.
183
190
  */
184
191
  generateAudioFiles?: boolean;
192
+ /**
193
+ * Gets the english name of the given language.
194
+ * If not provided, then the english name for the language will be unknown and omitted.
195
+ * @param language The language to get the english name for.
196
+ */
197
+ getEnglishName?: (language: string) => string | null | undefined;
198
+ /**
199
+ * Gets the native name of the given language.
200
+ * If not provided, then the native name for the language will be unknown and omitted.
201
+ * @param language The language to get the native name for.
202
+ */
203
+ getNativeName?: (language: string) => string | null | undefined;
204
+ /**
205
+ * The prefix that should be added to paths that are generated.
206
+ */
207
+ pathPrefix?: string;
185
208
  }
186
209
  /**
187
210
  * Generates the API output for the given dataset.
@@ -194,9 +217,27 @@ export declare function generateApiForDataset(dataset: DatasetOutput, options?:
194
217
  * @param api The API that the files should be generated for.
195
218
  */
196
219
  export declare function generateFilesForApi(api: ApiOutput): OutputFile[];
197
- export declare function listOfBooksApiLink(translationId: string): string;
198
- export declare function bookChapterApiLink(translationId: string, commonName: string, chapterNumber: number, extension: string): string;
199
- export declare function bookChapterAudioApiLink(translationId: string, bookId: string, chapterNumber: number, reader: string): string;
220
+ /**
221
+ * Generates the output files for the given datasets.
222
+ * @param datasets The datasets to generate the output files for.
223
+ * @param options The options for generating the API files.
224
+ */
225
+ export declare function generateOutputFilesFromDatasets(datasets: AsyncIterable<DatasetOutput>, options?: GenerateApiOptions): AsyncGenerator<OutputFile[]>;
226
+ /**
227
+ * Gets the API Link for the list of books endpoint for a translation.
228
+ * @param translationId The ID of the translation.
229
+ * @returns
230
+ */
231
+ export declare function listOfBooksApiLink(translationId: string, prefix?: string): string;
232
+ /**
233
+ * Getes the API link for a book chapter.
234
+ * @param translationId The ID of the translation.
235
+ * @param commonName The name of the book.
236
+ * @param chapterNumber The number of the book.
237
+ * @param extension The extension of the file.
238
+ */
239
+ export declare function bookChapterApiLink(translationId: string, commonName: string, chapterNumber: number, extension: string, prefix?: string): string;
240
+ export declare function bookChapterAudioApiLink(translationId: string, bookId: string, chapterNumber: number, reader: string, prefix?: string): string;
200
241
  export declare function jsonFile(path: string, content: any, mergable?: boolean): OutputFile;
201
242
  export declare function downloadedFile(path: string, url: string): OutputFile;
202
243
  export declare function replaceSpacesWithUnderscores(str: string): string;
@@ -1,4 +1,4 @@
1
- import { TranslationBookChapterAudioLinks } from "./common-types";
1
+ import { TranslationBookChapterAudioLinks } from './common-types.js';
2
2
  type AudioTranslationUrlGenerator = (bookId: string, chapter: number) => string;
3
3
  /**
4
4
  * A map of translation IDs to a map of reader IDs to the URL generator for the audio file.
@@ -1,4 +1,4 @@
1
- import { InputFile, Translation, TranslationBook, TranslationBookChapter } from "./common-types";
1
+ import { InputFile, Translation, TranslationBook, TranslationBookChapter } from './common-types.js';
2
2
  /**
3
3
  * Defines an interface that contains generated dataset info.
4
4
  */
@@ -0,0 +1,7 @@
1
+ import * as api from './api.js';
2
+ import * as audio from './audio.js';
3
+ import * as dataset from './dataset.js';
4
+ import * as bookOrder from './book-order.js';
5
+ export * from './common-types.js';
6
+ export { api, audio, dataset, bookOrder };
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,5 @@
1
+ import * as utils from './utils.js';
2
+ import * as generation from './generation/index.js';
3
+ import * as parser from './parser/index.js';
4
+ export { utils, generation, parser };
5
+ //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { ParseTree } from './types';
2
+ import { ParseTree } from './types.js';
3
3
  export declare const chapterHeadingSchema: z.ZodObject<{
4
4
  type: z.ZodLiteral<"chapter-heading">;
5
5
  data: z.ZodObject<{
@@ -0,0 +1,7 @@
1
+ export * from './types.js';
2
+ export * from './usfm-parser.js';
3
+ export * from './usx-parser.js';
4
+ export * from './codex-parser.js';
5
+ import * as iterators from './iterators.js';
6
+ export { iterators };
7
+ //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- import { ParseTree } from './types';
1
+ import { ParseTree } from './types.js';
2
2
  /**
3
3
  * Defines a class that can tokenize a stream of characters into tokens.
4
4
  */
@@ -1,5 +1,5 @@
1
- import { Chapter, ChapterContent, FootnoteReference, ParseTree, Verse, Text, HebrewSubtitle, InlineLineBreak } from "./types";
2
- import { RewindableIterator } from "./iterators";
1
+ import { Chapter, ChapterContent, FootnoteReference, ParseTree, Verse, Text, HebrewSubtitle, InlineLineBreak } from './types.js';
2
+ import { RewindableIterator } from './iterators.js';
3
3
  /**
4
4
  * The version of the parser.
5
5
  * Used to determine whether input files need to be re-parsed.
package/package.json CHANGED
@@ -1,14 +1,33 @@
1
1
  {
2
2
  "name": "@helloao/tools",
3
- "version": "0.0.4",
3
+ "version": "0.0.6-alpha",
4
4
  "description": "A set of tools for managing HelloAO's Free Bible API",
5
- "module": "index.js",
6
- "types": "index.d.ts",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/types/index.d.ts",
8
+ "import": "./dist/esm/index.js",
9
+ "require": "./dist/cjs/index.cjs"
10
+ },
11
+ "./*.js": {
12
+ "types": "./dist/types/*.d.ts",
13
+ "import": "./dist/esm/*.js",
14
+ "require": "./dist/cjs/*.cjs"
15
+ },
16
+ "./parser/*.js": {
17
+ "types": "./dist/types/parser/*.d.ts",
18
+ "import": "./dist/esm/parser/*.js",
19
+ "require": "./dist/cjs/parser/*.cjs"
20
+ },
21
+ "./generation/*.js": {
22
+ "types": "./dist/types/generation/*.d.ts",
23
+ "import": "./dist/esm/generation/*.js",
24
+ "require": "./dist/cjs/generation/*.cjs"
25
+ }
26
+ },
7
27
  "author": "Kallyn Gowdy <kal@helloao.org>",
8
28
  "license": "MIT",
9
29
  "dependencies": {
10
30
  "lodash": "4.17.21",
11
- "all-iso-language-codes": "1.0.17",
12
31
  "zod": "^3.23.8"
13
32
  },
14
33
  "devDependencies": {
@@ -21,6 +40,8 @@
21
40
  "/migrations/**/*.sql",
22
41
  "**/*.js",
23
42
  "**/*.js.map",
43
+ "**/*.cjs",
44
+ "**/*.cjs.map",
24
45
  "**/*.d.ts"
25
46
  ],
26
47
  "scripts": {}
package/generation/api.js DELETED
@@ -1,153 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateApiForDataset = generateApiForDataset;
4
- exports.generateFilesForApi = generateFilesForApi;
5
- exports.listOfBooksApiLink = listOfBooksApiLink;
6
- exports.bookChapterApiLink = bookChapterApiLink;
7
- exports.bookChapterAudioApiLink = bookChapterAudioApiLink;
8
- exports.jsonFile = jsonFile;
9
- exports.downloadedFile = downloadedFile;
10
- exports.replaceSpacesWithUnderscores = replaceSpacesWithUnderscores;
11
- const all_iso_language_codes_1 = require("all-iso-language-codes");
12
- /**
13
- * Generates the API output for the given dataset.
14
- * @param dataset The dataset to generate the API for.
15
- * @param options The options for generating the API.
16
- */
17
- function generateApiForDataset(dataset, options = {}) {
18
- const { useCommonName } = options;
19
- let api = {
20
- availableTranslations: {
21
- translations: [],
22
- },
23
- translationBooks: [],
24
- translationBookChapters: [],
25
- translationBookChapterAudio: [],
26
- };
27
- for (let { books, ...translation } of dataset.translations) {
28
- const apiTranslation = {
29
- ...translation,
30
- availableFormats: ['json'],
31
- listOfBooksApiLink: listOfBooksApiLink(translation.id),
32
- numberOfBooks: books.length,
33
- totalNumberOfChapters: 0,
34
- totalNumberOfVerses: 0,
35
- languageName: (0, all_iso_language_codes_1.getNativeName)(translation.language) ?? undefined,
36
- languageEnglishName: (0, all_iso_language_codes_1.getEnglishName)(translation.language) ?? undefined,
37
- };
38
- const translationBooks = {
39
- translation: apiTranslation,
40
- books: [],
41
- };
42
- let translationChapters = [];
43
- for (let { chapters, ...book } of books) {
44
- const apiBook = {
45
- ...book,
46
- firstChapterApiLink: bookChapterApiLink(translation.id, getBookLink(book), 1, 'json'),
47
- lastChapterApiLink: bookChapterApiLink(translation.id, getBookLink(book), chapters.length, 'json'),
48
- numberOfChapters: chapters.length,
49
- totalNumberOfVerses: 0,
50
- };
51
- for (let { chapter, thisChapterAudioLinks } of chapters) {
52
- const audio = {};
53
- const apiBookChapter = {
54
- translation: apiTranslation,
55
- book: apiBook,
56
- chapter: chapter,
57
- thisChapterLink: bookChapterApiLink(translation.id, getBookLink(book), chapter.number, 'json'),
58
- thisChapterAudioLinks: audio,
59
- nextChapterApiLink: null,
60
- nextChapterAudioLinks: null,
61
- previousChapterApiLink: null,
62
- previousChapterAudioLinks: null,
63
- numberOfVerses: 0,
64
- };
65
- for (let reader in thisChapterAudioLinks) {
66
- if (options.generateAudioFiles) {
67
- const apiAudio = {
68
- chapter: apiBookChapter,
69
- link: bookChapterAudioApiLink(translation.id, getBookLink(book), chapter.number, reader),
70
- originalUrl: thisChapterAudioLinks[reader],
71
- };
72
- audio[reader] = apiAudio.link;
73
- api.translationBookChapterAudio.push(apiAudio);
74
- }
75
- else {
76
- audio[reader] = thisChapterAudioLinks[reader];
77
- }
78
- }
79
- for (let c of chapter.content) {
80
- if (c.type === 'verse') {
81
- apiBookChapter.numberOfVerses++;
82
- }
83
- }
84
- apiBook.totalNumberOfVerses += apiBookChapter.numberOfVerses;
85
- translationChapters.push(apiBookChapter);
86
- api.translationBookChapters.push(apiBookChapter);
87
- }
88
- translationBooks.books.push(apiBook);
89
- apiTranslation.totalNumberOfChapters += apiBook.numberOfChapters;
90
- apiTranslation.totalNumberOfVerses += apiBook.totalNumberOfVerses;
91
- }
92
- for (let i = 0; i < translationChapters.length; i++) {
93
- if (i > 0) {
94
- translationChapters[i].previousChapterApiLink = bookChapterApiLink(translation.id, getBookLink(translationChapters[i - 1].book), translationChapters[i - 1].chapter.number, 'json');
95
- translationChapters[i].previousChapterAudioLinks = translationChapters[i - 1].thisChapterAudioLinks;
96
- }
97
- if (i < translationChapters.length - 1) {
98
- translationChapters[i].nextChapterApiLink = bookChapterApiLink(translation.id, getBookLink(translationChapters[i + 1].book), translationChapters[i + 1].chapter.number, 'json');
99
- translationChapters[i].nextChapterAudioLinks = translationChapters[i + 1].thisChapterAudioLinks;
100
- }
101
- }
102
- api.availableTranslations.translations.push(apiTranslation);
103
- api.translationBooks.push(translationBooks);
104
- }
105
- return api;
106
- function getBookLink(book) {
107
- return useCommonName ? book.commonName : book.id;
108
- }
109
- }
110
- /**
111
- * Generates the output files for the given API.
112
- * @param api The API that the files should be generated for.
113
- */
114
- function generateFilesForApi(api) {
115
- let files = [];
116
- files.push(jsonFile('/api/available_translations.json', api.availableTranslations, true));
117
- for (let translationBooks of api.translationBooks) {
118
- files.push(jsonFile(translationBooks.translation.listOfBooksApiLink, translationBooks));
119
- }
120
- for (let bookChapter of api.translationBookChapters) {
121
- files.push(jsonFile(bookChapter.thisChapterLink, bookChapter));
122
- }
123
- for (let audio of api.translationBookChapterAudio) {
124
- files.push(downloadedFile(audio.link, audio.originalUrl));
125
- }
126
- return files;
127
- }
128
- ;
129
- function listOfBooksApiLink(translationId) {
130
- return `/api/${translationId}/books.json`;
131
- }
132
- function bookChapterApiLink(translationId, commonName, chapterNumber, extension) {
133
- return `/api/${translationId}/${replaceSpacesWithUnderscores(commonName)}/${chapterNumber}.${extension}`;
134
- }
135
- function bookChapterAudioApiLink(translationId, bookId, chapterNumber, reader) {
136
- return `/api/${translationId}/${replaceSpacesWithUnderscores(bookId)}/${chapterNumber}.${reader}.mp3`;
137
- }
138
- function jsonFile(path, content, mergable) {
139
- return {
140
- path,
141
- content,
142
- mergable
143
- };
144
- }
145
- function downloadedFile(path, url) {
146
- return {
147
- path,
148
- content: () => fetch(url).then(response => response.body),
149
- };
150
- }
151
- function replaceSpacesWithUnderscores(str) {
152
- return str.replace(/[<>:"/\\|?*\s]/g, '_');
153
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=api.spec.d.ts.map