@helloao/tools 0.0.5 → 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 (107) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +98 -98
  3. package/dist/cjs/generation/api.cjs +240 -0
  4. package/dist/cjs/generation/api.cjs.map +7 -0
  5. package/dist/cjs/generation/audio.cjs +83 -0
  6. package/dist/cjs/generation/audio.cjs.map +7 -0
  7. package/dist/cjs/generation/book-order.cjs +508 -0
  8. package/dist/cjs/generation/book-order.cjs.map +7 -0
  9. package/dist/cjs/generation/common-types.cjs +17 -0
  10. package/dist/cjs/generation/common-types.cjs.map +7 -0
  11. package/dist/cjs/generation/dataset.cjs +158 -0
  12. package/dist/cjs/generation/dataset.cjs.map +7 -0
  13. package/dist/cjs/generation/index.cjs +51 -0
  14. package/dist/cjs/generation/index.cjs.map +7 -0
  15. package/dist/cjs/index.cjs +45 -0
  16. package/dist/cjs/index.cjs.map +7 -0
  17. package/dist/cjs/parser/codex-parser.cjs +176 -0
  18. package/dist/cjs/parser/codex-parser.cjs.map +7 -0
  19. package/dist/cjs/parser/index.cjs +48 -0
  20. package/dist/cjs/parser/index.cjs.map +7 -0
  21. package/dist/cjs/parser/iterators.cjs +204 -0
  22. package/dist/cjs/parser/iterators.cjs.map +7 -0
  23. package/dist/cjs/parser/types.cjs +17 -0
  24. package/dist/cjs/parser/types.cjs.map +7 -0
  25. package/dist/cjs/parser/usfm-parser.cjs +791 -0
  26. package/dist/cjs/parser/usfm-parser.cjs.map +7 -0
  27. package/dist/cjs/parser/usx-parser.cjs +471 -0
  28. package/dist/cjs/parser/usx-parser.cjs.map +7 -0
  29. package/dist/cjs/utils.cjs +85 -0
  30. package/dist/cjs/utils.cjs.map +7 -0
  31. package/dist/esm/generation/api.js +198 -0
  32. package/dist/esm/generation/api.js.map +7 -0
  33. package/dist/esm/generation/audio.js +53 -0
  34. package/dist/esm/generation/audio.js.map +7 -0
  35. package/dist/esm/generation/book-order.js +478 -0
  36. package/dist/esm/generation/book-order.js.map +7 -0
  37. package/dist/esm/generation/common-types.js +2 -0
  38. package/dist/esm/generation/common-types.js.map +7 -0
  39. package/dist/esm/generation/dataset.js +132 -0
  40. package/dist/esm/generation/dataset.js.map +7 -0
  41. package/dist/esm/generation/index.js +8 -0
  42. package/dist/esm/generation/index.js.map +7 -0
  43. package/dist/esm/index.js +6 -0
  44. package/dist/esm/index.js.map +7 -0
  45. package/dist/esm/parser/codex-parser.js +144 -0
  46. package/dist/esm/parser/codex-parser.js.map +7 -0
  47. package/dist/esm/parser/index.js +8 -0
  48. package/dist/esm/parser/index.js.map +7 -0
  49. package/dist/esm/parser/iterators.js +152 -0
  50. package/dist/esm/parser/iterators.js.map +7 -0
  51. package/dist/esm/parser/types.js +2 -0
  52. package/dist/esm/parser/types.js.map +7 -0
  53. package/dist/esm/parser/usfm-parser.js +749 -0
  54. package/dist/esm/parser/usfm-parser.js.map +7 -0
  55. package/dist/esm/parser/usx-parser.js +447 -0
  56. package/dist/esm/parser/usx-parser.js.map +7 -0
  57. package/dist/esm/utils.js +51 -0
  58. package/dist/esm/utils.js.map +7 -0
  59. package/{generation → dist/types/generation}/api.d.ts +14 -2
  60. package/{generation → dist/types/generation}/audio.d.ts +1 -1
  61. package/{generation → dist/types/generation}/dataset.d.ts +1 -1
  62. package/dist/types/generation/index.d.ts +7 -0
  63. package/dist/types/index.d.ts +5 -0
  64. package/{parser → dist/types/parser}/codex-parser.d.ts +1 -1
  65. package/dist/types/parser/index.d.ts +7 -0
  66. package/{parser → dist/types/parser}/usfm-parser.d.ts +1 -1
  67. package/{parser → dist/types/parser}/usx-parser.d.ts +2 -2
  68. package/package.json +25 -4
  69. package/typings/types.d.ts +13 -13
  70. package/generation/api.js +0 -179
  71. package/generation/api.spec.d.ts +0 -2
  72. package/generation/api.spec.js +0 -656
  73. package/generation/audio.js +0 -60
  74. package/generation/audio.spec.d.ts +0 -2
  75. package/generation/audio.spec.js +0 -36
  76. package/generation/book-order.js +0 -494
  77. package/generation/book-order.spec.d.ts +0 -2
  78. package/generation/book-order.spec.js +0 -8
  79. package/generation/common-types.js +0 -2
  80. package/generation/dataset.js +0 -106
  81. package/generation/index.d.ts +0 -7
  82. package/generation/index.js +0 -38
  83. package/index.d.ts +0 -5
  84. package/index.js +0 -32
  85. package/parser/codex-parser.js +0 -160
  86. package/parser/codex-parser.spec.d.ts +0 -2
  87. package/parser/codex-parser.spec.js +0 -645
  88. package/parser/index.d.ts +0 -7
  89. package/parser/index.js +0 -35
  90. package/parser/iterators.js +0 -222
  91. package/parser/iterators.spec.d.ts +0 -2
  92. package/parser/iterators.spec.js +0 -174
  93. package/parser/types.js +0 -2
  94. package/parser/usfm-parser.js +0 -840
  95. package/parser/usfm-parser.spec.d.ts +0 -2
  96. package/parser/usfm-parser.spec.js +0 -1593
  97. package/parser/usx-parser.js +0 -425
  98. package/parser/usx-parser.spec.d.ts +0 -2
  99. package/parser/usx-parser.spec.js +0 -1260
  100. package/utils.js +0 -73
  101. package/utils.spec.d.ts +0 -2
  102. package/utils.spec.js +0 -42
  103. /package/{generation → dist/types/generation}/book-order.d.ts +0 -0
  104. /package/{generation → dist/types/generation}/common-types.d.ts +0 -0
  105. /package/{parser → dist/types/parser}/iterators.d.ts +0 -0
  106. /package/{parser → dist/types/parser}/types.d.ts +0 -0
  107. /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
  */
@@ -189,6 +189,18 @@ export interface GenerateApiOptions {
189
189
  * Defaults to false.
190
190
  */
191
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;
192
204
  /**
193
205
  * The prefix that should be added to paths that are generated.
194
206
  */
@@ -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.5",
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": {}
@@ -1,14 +1,14 @@
1
- declare module "*.usfm" {
2
- const content: string;
3
- export default content;
4
- }
5
-
6
- declare module "*.usx" {
7
- const content: string;
8
- export default content;
9
- }
10
-
11
- declare module "*.codex" {
12
- const content: string;
13
- export default content;
1
+ declare module "*.usfm" {
2
+ const content: string;
3
+ export default content;
4
+ }
5
+
6
+ declare module "*.usx" {
7
+ const content: string;
8
+ export default content;
9
+ }
10
+
11
+ declare module "*.codex" {
12
+ const content: string;
13
+ export default content;
14
14
  }
package/generation/api.js DELETED
@@ -1,179 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateApiForDataset = generateApiForDataset;
4
- exports.generateFilesForApi = generateFilesForApi;
5
- exports.generateOutputFilesFromDatasets = generateOutputFilesFromDatasets;
6
- exports.listOfBooksApiLink = listOfBooksApiLink;
7
- exports.bookChapterApiLink = bookChapterApiLink;
8
- exports.bookChapterAudioApiLink = bookChapterAudioApiLink;
9
- exports.jsonFile = jsonFile;
10
- exports.downloadedFile = downloadedFile;
11
- exports.replaceSpacesWithUnderscores = replaceSpacesWithUnderscores;
12
- const all_iso_language_codes_1 = require("all-iso-language-codes");
13
- /**
14
- * Generates the API output for the given dataset.
15
- * @param dataset The dataset to generate the API for.
16
- * @param options The options for generating the API.
17
- */
18
- function generateApiForDataset(dataset, options = {}) {
19
- const { useCommonName, pathPrefix } = options;
20
- const apiPathPrefix = pathPrefix ? pathPrefix : '';
21
- let api = {
22
- availableTranslations: {
23
- translations: [],
24
- },
25
- translationBooks: [],
26
- translationBookChapters: [],
27
- translationBookChapterAudio: [],
28
- pathPrefix: apiPathPrefix
29
- };
30
- for (let { books, ...translation } of dataset.translations) {
31
- const apiTranslation = {
32
- ...translation,
33
- availableFormats: ['json'],
34
- listOfBooksApiLink: listOfBooksApiLink(translation.id, apiPathPrefix),
35
- numberOfBooks: books.length,
36
- totalNumberOfChapters: 0,
37
- totalNumberOfVerses: 0,
38
- languageName: (0, all_iso_language_codes_1.getNativeName)(translation.language) ?? undefined,
39
- languageEnglishName: (0, all_iso_language_codes_1.getEnglishName)(translation.language) ?? undefined,
40
- };
41
- const translationBooks = {
42
- translation: apiTranslation,
43
- books: [],
44
- };
45
- let translationChapters = [];
46
- for (let { chapters, ...book } of books) {
47
- const apiBook = {
48
- ...book,
49
- firstChapterApiLink: bookChapterApiLink(translation.id, getBookLink(book), 1, 'json', apiPathPrefix),
50
- lastChapterApiLink: bookChapterApiLink(translation.id, getBookLink(book), chapters.length, 'json', apiPathPrefix),
51
- numberOfChapters: chapters.length,
52
- totalNumberOfVerses: 0,
53
- };
54
- for (let { chapter, thisChapterAudioLinks } of chapters) {
55
- const audio = {};
56
- const apiBookChapter = {
57
- translation: apiTranslation,
58
- book: apiBook,
59
- chapter: chapter,
60
- thisChapterLink: bookChapterApiLink(translation.id, getBookLink(book), chapter.number, 'json', apiPathPrefix),
61
- thisChapterAudioLinks: audio,
62
- nextChapterApiLink: null,
63
- nextChapterAudioLinks: null,
64
- previousChapterApiLink: null,
65
- previousChapterAudioLinks: null,
66
- numberOfVerses: 0,
67
- };
68
- for (let reader in thisChapterAudioLinks) {
69
- if (options.generateAudioFiles) {
70
- const apiAudio = {
71
- chapter: apiBookChapter,
72
- link: bookChapterAudioApiLink(translation.id, getBookLink(book), chapter.number, reader, apiPathPrefix),
73
- originalUrl: thisChapterAudioLinks[reader],
74
- };
75
- audio[reader] = apiAudio.link;
76
- api.translationBookChapterAudio.push(apiAudio);
77
- }
78
- else {
79
- audio[reader] = thisChapterAudioLinks[reader];
80
- }
81
- }
82
- for (let c of chapter.content) {
83
- if (c.type === 'verse') {
84
- apiBookChapter.numberOfVerses++;
85
- }
86
- }
87
- apiBook.totalNumberOfVerses += apiBookChapter.numberOfVerses;
88
- translationChapters.push(apiBookChapter);
89
- api.translationBookChapters.push(apiBookChapter);
90
- }
91
- translationBooks.books.push(apiBook);
92
- apiTranslation.totalNumberOfChapters += apiBook.numberOfChapters;
93
- apiTranslation.totalNumberOfVerses += apiBook.totalNumberOfVerses;
94
- }
95
- for (let i = 0; i < translationChapters.length; i++) {
96
- if (i > 0) {
97
- translationChapters[i].previousChapterApiLink = bookChapterApiLink(translation.id, getBookLink(translationChapters[i - 1].book), translationChapters[i - 1].chapter.number, 'json', apiPathPrefix);
98
- translationChapters[i].previousChapterAudioLinks = translationChapters[i - 1].thisChapterAudioLinks;
99
- }
100
- if (i < translationChapters.length - 1) {
101
- translationChapters[i].nextChapterApiLink = bookChapterApiLink(translation.id, getBookLink(translationChapters[i + 1].book), translationChapters[i + 1].chapter.number, 'json', apiPathPrefix);
102
- translationChapters[i].nextChapterAudioLinks = translationChapters[i + 1].thisChapterAudioLinks;
103
- }
104
- }
105
- api.availableTranslations.translations.push(apiTranslation);
106
- api.translationBooks.push(translationBooks);
107
- }
108
- return api;
109
- function getBookLink(book) {
110
- return useCommonName ? book.commonName : book.id;
111
- }
112
- }
113
- /**
114
- * Generates the output files for the given API.
115
- * @param api The API that the files should be generated for.
116
- */
117
- function generateFilesForApi(api) {
118
- let files = [];
119
- files.push(jsonFile(`${api.pathPrefix}/api/available_translations.json`, api.availableTranslations, true));
120
- for (let translationBooks of api.translationBooks) {
121
- files.push(jsonFile(translationBooks.translation.listOfBooksApiLink, translationBooks));
122
- }
123
- for (let bookChapter of api.translationBookChapters) {
124
- files.push(jsonFile(bookChapter.thisChapterLink, bookChapter));
125
- }
126
- for (let audio of api.translationBookChapterAudio) {
127
- files.push(downloadedFile(audio.link, audio.originalUrl));
128
- }
129
- return files;
130
- }
131
- /**
132
- * Generates the output files for the given datasets.
133
- * @param datasets The datasets to generate the output files for.
134
- * @param options The options for generating the API files.
135
- */
136
- async function* generateOutputFilesFromDatasets(datasets, options) {
137
- for await (let dataset of datasets) {
138
- const api = generateApiForDataset(dataset, options);
139
- const files = generateFilesForApi(api);
140
- yield files;
141
- }
142
- }
143
- /**
144
- * Gets the API Link for the list of books endpoint for a translation.
145
- * @param translationId The ID of the translation.
146
- * @returns
147
- */
148
- function listOfBooksApiLink(translationId, prefix = '') {
149
- return `${prefix}/api/${translationId}/books.json`;
150
- }
151
- /**
152
- * Getes the API link for a book chapter.
153
- * @param translationId The ID of the translation.
154
- * @param commonName The name of the book.
155
- * @param chapterNumber The number of the book.
156
- * @param extension The extension of the file.
157
- */
158
- function bookChapterApiLink(translationId, commonName, chapterNumber, extension, prefix = '') {
159
- return `${prefix}/api/${translationId}/${replaceSpacesWithUnderscores(commonName)}/${chapterNumber}.${extension}`;
160
- }
161
- function bookChapterAudioApiLink(translationId, bookId, chapterNumber, reader, prefix = '') {
162
- return `${prefix}/api/${translationId}/${replaceSpacesWithUnderscores(bookId)}/${chapterNumber}.${reader}.mp3`;
163
- }
164
- function jsonFile(path, content, mergable) {
165
- return {
166
- path,
167
- content,
168
- mergable
169
- };
170
- }
171
- function downloadedFile(path, url) {
172
- return {
173
- path,
174
- content: () => fetch(url).then(response => response.body),
175
- };
176
- }
177
- function replaceSpacesWithUnderscores(str) {
178
- return str.replace(/[<>:"/\\|?*\s]/g, '_');
179
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=api.spec.d.ts.map