@helloao/tools 0.0.11 → 0.0.13
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/dist/cjs/generation/api.cjs +26 -3
- package/dist/cjs/generation/api.cjs.map +2 -2
- package/dist/cjs/generation/audio.cjs +1 -1
- package/dist/cjs/generation/audio.cjs.map +2 -2
- package/dist/cjs/generation/book-order.cjs +241 -398
- package/dist/cjs/generation/book-order.cjs.map +2 -2
- package/dist/cjs/generation/common-types.cjs.map +1 -1
- package/dist/cjs/generation/dataset.cjs +20 -8
- package/dist/cjs/generation/dataset.cjs.map +2 -2
- package/dist/cjs/parser/types.cjs.map +1 -1
- package/dist/cjs/parser/usx-parser.cjs +41 -1
- package/dist/cjs/parser/usx-parser.cjs.map +2 -2
- package/dist/cjs/utils.cjs +20 -1
- package/dist/cjs/utils.cjs.map +2 -2
- package/dist/esm/generation/api.js +26 -3
- package/dist/esm/generation/api.js.map +2 -2
- package/dist/esm/generation/audio.js +1 -1
- package/dist/esm/generation/audio.js.map +2 -2
- package/dist/esm/generation/book-order.js +239 -398
- package/dist/esm/generation/book-order.js.map +2 -2
- package/dist/esm/generation/dataset.js +25 -9
- package/dist/esm/generation/dataset.js.map +2 -2
- package/dist/esm/parser/usx-parser.js +41 -1
- package/dist/esm/parser/usx-parser.js.map +2 -2
- package/dist/esm/utils.js +18 -1
- package/dist/esm/utils.js.map +2 -2
- package/dist/types/generation/api.d.ts +12 -0
- package/dist/types/generation/book-order.d.ts +4 -0
- package/dist/types/generation/common-types.d.ts +5 -1
- package/dist/types/generation/dataset.d.ts +4 -0
- package/dist/types/parser/types.d.ts +8 -0
- package/dist/types/parser/usx-parser.d.ts +4 -0
- package/dist/types/utils.d.ts +5 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../parser/usx-parser.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n Chapter,\n ChapterContent,\n Footnote,\n FootnoteReference,\n ParseTree,\n Verse,\n Text,\n HebrewSubtitle,\n InlineLineBreak,\n InlineHeading,\n} from './types.js';\nimport {\n iterateAll,\n children,\n RewindableIterator,\n isParent,\n} from './iterators.js';\n\nenum NodeType {\n Text = 3,\n}\n\n/**\n * The version of the parser.\n * Used to determine whether input files need to be re-parsed.\n */\nexport const PARSER_VERSION = '2';\n\n/**\n * Defines a class that is able to parse USX content.\n */\nexport class USXParser {\n private _domParser: DOMParser;\n private _noteCounter: number = 0;\n\n constructor(domParser: DOMParser) {\n this._domParser = domParser;\n }\n\n /**\n * Parses the specified USX content.\n *\n * @param usx The USX content to parse.\n * @returns The parse tree that was generated.\n */\n public parse(usx: string): ParseTree {\n const parser = this._domParser;\n const doc = parser.parseFromString(usx, 'application/xml');\n const usxElement = doc.documentElement;\n\n let root: ParseTree = {\n type: 'root',\n content: [],\n };\n\n const bookElement = usxElement.querySelector('book[code]');\n\n if (!bookElement) {\n throw new Error('The USX content does not contain a book element.');\n }\n\n const bookCode = bookElement.getAttribute('code') || '';\n\n if (!bookCode) {\n throw new Error(\n 'The book element does not contain a code attribute.'\n );\n }\n\n root.id = bookCode;\n\n const header = usxElement.querySelector('para[style=\"h\"]');\n if (header) {\n root.header = header.textContent || '';\n }\n\n const titles = usxElement.querySelectorAll(\n 'para[style=\"mt1\"], para[style=\"mt2\"], para[style=\"mt3\"]'\n );\n // const title2 = usxElement.querySelector('para[style=\"mt2\"]');\n // const title3 = usxElement.querySelector('para[style=\"mt3\"]');\n\n if (titles.length > 0) {\n root.title = [...titles]\n .map((t) => t.textContent)\n .filter((t) => t)\n .join(' ');\n }\n\n for (let content of this.iterateRootContent(usxElement)) {\n root.content.push(content);\n }\n\n return root;\n }\n\n *iterateRootContent(\n usxElement: Element\n ): Generator<ParseTree['content'][0]> {\n const iterator = iterateAll(usxElement);\n while (true) {\n const { done, value: child } = iterator.next();\n if (done) {\n break;\n }\n\n if (!(child instanceof Element)) {\n continue;\n }\n\n if (child.nodeName === 'chapter') {\n if (child.hasAttribute('eid')) {\n continue;\n }\n\n const chapter: Chapter = {\n type: 'chapter',\n number: parseInt(child.getAttribute('number') || '0', 10),\n content: [],\n footnotes: [],\n };\n\n for (let content of this.iterateChapterContent(\n chapter,\n iterator\n )) {\n chapter.content.push(content);\n }\n\n yield chapter;\n } else if (child.nodeName === 'para') {\n const style = child.getAttribute('style');\n if (\n style === 's1' ||\n style === 's2' ||\n style === 's3' ||\n style === 's4'\n ) {\n yield {\n type: 'heading',\n content: child.textContent ? [child.textContent] : [],\n };\n }\n }\n }\n }\n\n *iterateChapterContent(\n chapter: Chapter,\n nodes: RewindableIterator<Node>\n ): IterableIterator<ChapterContent> {\n while (true) {\n const { done, value: element } = nodes.next();\n if (done) {\n break;\n }\n\n if (!(element instanceof Element)) {\n continue;\n }\n\n if (element.nodeName === 'chapter') {\n break;\n } else if (element.nodeName === 'para') {\n const style = element.getAttribute('style');\n if (\n style === 's1' ||\n style === 's2' ||\n style === 's3' ||\n style === 's4'\n ) {\n yield {\n type: 'heading',\n content: element.textContent\n ? [element.textContent]\n : [],\n };\n } else if (style === 'b') {\n yield {\n type: 'line_break',\n };\n } else if (style === 'd') {\n yield* this.parseHebrewSubtitle(element, chapter, nodes);\n }\n } else if (element.nodeName === 'verse') {\n if (element.hasAttribute('eid')) {\n continue;\n }\n\n yield this.parseVerse(element, chapter, nodes);\n }\n }\n }\n\n *iterateVerseContent(\n chapter: Chapter,\n verse: Verse,\n nodes: RewindableIterator<Node>\n ): IterableIterator<string | FootnoteReference | Text | InlineLineBreak> {\n let lastParent: Element | null = null;\n while (true) {\n const { done, value: node } = nodes.next();\n if (done) {\n break;\n }\n\n if (node.nodeName === 'verse') {\n break;\n }\n\n const parent = node.parentElement!;\n let poem: number | null = null;\n let descriptive: boolean | null = null;\n\n if (parent.nodeName === 'para') {\n const style = parent.getAttribute('style');\n if (\n style === 'q1' ||\n style === 'q2' ||\n style === 'q3' ||\n style === 'q4'\n ) {\n poem =\n style === 'q1'\n ? 1\n : style === 'q2'\n ? 2\n : style === 'q3'\n ? 3\n : 4;\n\n // Send explicit line breaks\n // if we are in a new paragraph but the previous paragraph had the same poem style\n if (parent.previousElementSibling?.nodeName === 'para') {\n const previousStyle =\n parent.previousElementSibling?.getAttribute(\n 'style'\n );\n if (previousStyle === style && lastParent !== parent) {\n lastParent = parent;\n yield {\n lineBreak: true,\n };\n }\n }\n } else if (style === 'd') {\n descriptive = true;\n }\n }\n\n for (let content of this.iterateNodeTextContent(\n nodes,\n node,\n chapter,\n verse\n )) {\n if (poem !== null || descriptive !== null) {\n if (typeof content === 'string') {\n let text: Text = {\n text: content,\n };\n\n if (poem !== null) {\n text.poem = poem;\n }\n\n if (descriptive !== null) {\n text.descriptive = true;\n }\n\n yield text;\n } else {\n let text:\n | InlineLineBreak\n | InlineHeading\n | FootnoteReference\n | Text = {\n ...content,\n };\n\n if ('text' in text) {\n if (poem !== null) {\n text.poem = poem;\n }\n\n if (descriptive !== null) {\n text.descriptive = true;\n }\n }\n yield text;\n }\n } else {\n yield content;\n }\n }\n }\n }\n\n parseVerse(\n element: Element,\n chapter: Chapter,\n nodes: RewindableIterator<Node>\n ): Verse {\n const verse: Verse = {\n type: 'verse',\n number: parseInt(element.getAttribute('number') || '0', 10),\n content: [],\n };\n\n for (let content of this.iterateVerseContent(chapter, verse, nodes)) {\n addOrJoin(verse.content, content);\n }\n\n trimContent(verse.content);\n return verse;\n }\n\n *parseHebrewSubtitle(\n para: Element,\n chapter: Chapter,\n nodes: RewindableIterator<Node>\n ): IterableIterator<HebrewSubtitle | Verse> {\n const subtitle: HebrewSubtitle = {\n type: 'hebrew_subtitle',\n content: [],\n };\n\n for (let content of this.iterateHebrewSubtitleContent(\n para,\n chapter,\n nodes\n )) {\n if (typeof content === 'object' && 'number' in content) {\n yield content;\n continue;\n }\n addOrJoin(subtitle.content, content);\n }\n\n trimContent(subtitle.content);\n if (subtitle.content.length > 0) {\n yield subtitle;\n }\n }\n\n *iterateHebrewSubtitleContent(\n element: Element,\n chapter: Chapter,\n nodes: RewindableIterator<Node>\n ): IterableIterator<\n Verse | string | Text | FootnoteReference | InlineLineBreak\n > {\n while (true) {\n const { done, value: node } = nodes.next();\n if (done) {\n break;\n }\n\n if (!isParent(node, element)) {\n nodes.rewind(1);\n break;\n }\n\n if (node instanceof Element && node.nodeName === 'verse') {\n yield this.parseVerse(node, chapter, nodes);\n } else {\n yield* this.iterateNodeTextContent(nodes, node, chapter);\n }\n }\n }\n\n *iterateNodeTextContent(\n nodes: RewindableIterator<Node>,\n node: Node,\n chapter: Chapter,\n verse?: Verse\n ): IterableIterator<string | Text | FootnoteReference | InlineLineBreak> {\n if (node instanceof Element && node.nodeName === 'note') {\n yield* this.iterateNote(nodes, node, chapter, verse);\n } else if (node instanceof Element && node.nodeName === 'char') {\n yield* this.iterateChar(nodes, node);\n } else if (\n node instanceof Element &&\n node.nodeName === 'para' &&\n node.getAttribute('style') === 'b'\n ) {\n for (let _ of children(nodes, node)) {\n // iterate through all the children to prevent iterating over them multiple times\n }\n yield {\n lineBreak: true,\n };\n } else if (node.nodeType === NodeType.Text) {\n yield node.textContent || '';\n }\n }\n\n *iterateCharContent(char: Element): IterableIterator<string | Text> {\n const style = char.getAttribute('style');\n const text = trimText(char.textContent || '');\n if (style === 'wj') {\n yield {\n text,\n wordsOfJesus: true,\n };\n } else {\n yield text;\n }\n }\n\n *iterateNote(\n nodes: RewindableIterator<Node>,\n node: Element,\n chapter: Chapter,\n verse?: Verse\n ): IterableIterator<FootnoteReference> {\n const style = node.getAttribute('style');\n if (style === 'f') {\n const verseReferenceRegex = /^[0-9]{1,3}:[0-9]{1,3}/;\n\n let text = '';\n for (let child of children(nodes, node)) {\n if (child.nodeType === NodeType.Text) {\n text += child.textContent || '';\n }\n }\n\n text = text.trim();\n if (verseReferenceRegex.test(text)) {\n text = text.replace(verseReferenceRegex, '').trim();\n }\n\n const note: Footnote = {\n noteId: this._noteCounter++,\n caller: node.getAttribute('caller') || null,\n text,\n reference: {\n chapter: chapter.number,\n verse: verse?.number ?? 0,\n },\n };\n\n chapter.footnotes.push(note);\n\n yield {\n noteId: note.noteId,\n };\n } else {\n for (let _ of children(nodes, node)) {\n // iterate through all the children\n // so that we don't end up with duplicates\n }\n }\n }\n\n *iterateChar(\n nodes: RewindableIterator<Node>,\n node: Element\n ): IterableIterator<string | Text> {\n const style = node.getAttribute('style');\n let text = '';\n\n for (let char of children(nodes, node)) {\n if (char.nodeType === NodeType.Text) {\n text += char.textContent || '';\n }\n }\n\n if (style === 'wj') {\n yield {\n text,\n wordsOfJesus: true,\n };\n } else {\n yield text;\n }\n\n // if (!parentChar(node) && !parentNote(node)) {\n // yield *iterateCharContent(node);\n // }\n }\n}\n\n// Taken from https://github.com/gracious-tech/fetch/blob/1576cc4eafb32bf347a09332094cf17c2231c90c/converters/usx-to-json/src/elements.ts#L16\nconst ignoredParaStyles = new Set([\n // <para> Identification [exclude all] - Running headings & table of contents\n 'ide', // See https://github.com/schierlm/BibleMultiConverter/issues/67\n 'rem', // Remarks (valid in schema though missed in docs)\n 'h',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'toc1',\n 'toc2',\n 'toc3',\n 'toca1',\n 'toca2',\n 'toca3',\n\n /* <para> Introductions [exclude all] - Introductionary (non-biblical) content\n Which might be helpful in a printed book, but intro material in apps is usually bad UX,\n and users that really care can research a translations methodology themselves\n */\n 'imt',\n 'imt1',\n 'imt2',\n 'imt3',\n 'imt4',\n 'is',\n 'is1',\n 'is2',\n 'is3',\n 'is4',\n 'ip',\n 'ipi',\n 'im',\n 'imi',\n 'ipq',\n 'imq',\n 'ipr',\n 'iq',\n 'iq1',\n 'iq2',\n 'iq3',\n 'iq4',\n 'ib',\n 'ili',\n 'ili1',\n 'ili2',\n 'ili3',\n 'ili4',\n 'iot',\n 'io',\n 'io1',\n 'io2',\n 'io3',\n 'io4',\n 'iex',\n 'imte',\n 'ie',\n\n /* <para> Headings [exclude some] - Exclude book & chapter headings but keep section headings\n Not excluded: ms# | mr | s# | sr | d | sp | sd#\n */\n 'mt',\n 'mt1',\n 'mt2',\n 'mt3',\n 'mt4',\n 'mte',\n 'mte1',\n 'mte2',\n 'mte3',\n 'mte4',\n 'cl',\n 'cd', // Non-biblical chapter summary, more than heading\n 'r', // Parallels to be provided by external data\n]);\n\nfunction* iterateCharContent(char: Element): IterableIterator<string | Text> {\n const style = char.getAttribute('style');\n const text = trimText(char.textContent || '');\n if (style === 'wj') {\n yield {\n text,\n wordsOfJesus: true,\n };\n } else {\n yield text;\n }\n}\n\nfunction trimText(text: string): string {\n return text.replace(/\\s+/g, ' ');\n}\n\nfunction trimContent<T extends string | unknown>(content: T[]): T[] {\n for (let i = 0; i < content.length; i++) {\n const value = content[i];\n if (typeof value === 'string') {\n content[i] = trimText(value as string).trim() as T;\n if (content[i] === '') {\n content.splice(i, 1);\n i--;\n continue;\n }\n } else if (isVerseText(value)) {\n value.text = trimText(value.text).trim();\n if (value.text === '') {\n content.splice(i, 1);\n i--;\n continue;\n }\n }\n }\n return content;\n}\n\nfunction addOrJoin(array: (string | unknown)[], value: string | unknown) {\n if (array.length === 0) {\n array.push(value);\n } else {\n const last = array[array.length - 1];\n if (typeof last === 'string' && typeof value === 'string') {\n array[array.length - 1] = last + value;\n } else if (\n isVerseText(last) &&\n isVerseText(value) &&\n hasSameFormatting(last, value)\n ) {\n last.text += value.text;\n } else {\n array.push(value);\n }\n }\n}\n\nfunction isVerseText(value: unknown): value is Text {\n return typeof value === 'object' && value !== null && 'text' in value;\n}\n\nfunction hasSameFormatting(a: Text, b: Text): boolean {\n return a.poem === b.poem && a.wordsOfJesus === b.wordsOfJesus;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import {\n Chapter,\n ChapterContent,\n Footnote,\n FootnoteReference,\n ParseTree,\n Verse,\n Text,\n HebrewSubtitle,\n InlineLineBreak,\n InlineHeading,\n ParseMessage,\n} from './types.js';\nimport {\n iterateAll,\n children,\n RewindableIterator,\n isParent,\n} from './iterators.js';\nimport { KNOWN_SKIPPED_VERSES } from '../utils.js';\n\nenum NodeType {\n Text = 3,\n}\n\n/**\n * The version of the parser.\n * Used to determine whether input files need to be re-parsed.\n */\nexport const PARSER_VERSION = '2';\n\n/**\n * Defines a class that is able to parse USX content.\n */\nexport class USXParser {\n private _domParser: DOMParser;\n private _noteCounter: number = 0;\n private _messages: ParseMessage[] = [];\n private _lastVerse: Verse | null = null;\n private _currentChapter: Chapter | null = null;\n private _bookId: string | null = null;\n\n constructor(domParser: DOMParser) {\n this._domParser = domParser;\n }\n\n /**\n * Parses the specified USX content.\n *\n * @param usx The USX content to parse.\n * @returns The parse tree that was generated.\n */\n public parse(usx: string): ParseTree {\n this._noteCounter = 0;\n this._messages = [];\n this._lastVerse = null;\n this._currentChapter = null;\n this._bookId = null;\n const parser = this._domParser;\n const doc = parser.parseFromString(usx, 'application/xml');\n const usxElement = doc.documentElement;\n\n let root: ParseTree = {\n type: 'root',\n content: [],\n };\n\n const bookElement = usxElement.querySelector('book[code]');\n\n if (!bookElement) {\n throw new Error('The USX content does not contain a book element.');\n }\n\n const bookCode = bookElement.getAttribute('code') || '';\n\n if (!bookCode) {\n throw new Error(\n 'The book element does not contain a code attribute.'\n );\n }\n\n this._bookId = root.id = bookCode;\n\n const header = usxElement.querySelector('para[style=\"h\"]');\n if (header) {\n root.header = header.textContent || '';\n }\n\n const titles = usxElement.querySelectorAll(\n 'para[style=\"mt1\"], para[style=\"mt2\"], para[style=\"mt3\"]'\n );\n // const title2 = usxElement.querySelector('para[style=\"mt2\"]');\n // const title3 = usxElement.querySelector('para[style=\"mt3\"]');\n\n if (titles.length > 0) {\n root.title = [...titles]\n .map((t) => t.textContent)\n .filter((t) => t)\n .join(' ');\n }\n\n for (let content of this.iterateRootContent(usxElement)) {\n root.content.push(content);\n }\n\n if (this._messages.length > 0) {\n root.parseMessages = this._messages.slice();\n }\n\n return root;\n }\n\n *iterateRootContent(\n usxElement: Element\n ): Generator<ParseTree['content'][0]> {\n const iterator = iterateAll(usxElement);\n while (true) {\n const { done, value: child } = iterator.next();\n if (done) {\n break;\n }\n\n if (!(child instanceof Element)) {\n continue;\n }\n\n if (child.nodeName === 'chapter') {\n if (child.hasAttribute('eid')) {\n continue;\n }\n\n const chapter: Chapter = {\n type: 'chapter',\n number: parseInt(child.getAttribute('number') || '0', 10),\n content: [],\n footnotes: [],\n };\n this._currentChapter = chapter;\n\n for (let content of this.iterateChapterContent(\n chapter,\n iterator\n )) {\n chapter.content.push(content);\n }\n\n yield chapter;\n } else if (child.nodeName === 'para') {\n const style = child.getAttribute('style');\n if (\n style === 's1' ||\n style === 's2' ||\n style === 's3' ||\n style === 's4'\n ) {\n yield {\n type: 'heading',\n content: child.textContent ? [child.textContent] : [],\n };\n }\n }\n }\n }\n\n *iterateChapterContent(\n chapter: Chapter,\n nodes: RewindableIterator<Node>\n ): IterableIterator<ChapterContent> {\n while (true) {\n const { done, value: element } = nodes.next();\n if (done) {\n break;\n }\n\n if (!(element instanceof Element)) {\n continue;\n }\n\n if (element.nodeName === 'chapter') {\n break;\n } else if (element.nodeName === 'para') {\n const style = element.getAttribute('style');\n if (\n style === 's1' ||\n style === 's2' ||\n style === 's3' ||\n style === 's4'\n ) {\n yield {\n type: 'heading',\n content: element.textContent\n ? [element.textContent]\n : [],\n };\n } else if (style === 'b') {\n yield {\n type: 'line_break',\n };\n } else if (style === 'd') {\n yield* this.parseHebrewSubtitle(element, chapter, nodes);\n }\n } else if (element.nodeName === 'verse') {\n if (element.hasAttribute('eid')) {\n continue;\n }\n\n yield this.parseVerse(element, chapter, nodes);\n }\n }\n }\n\n *iterateVerseContent(\n chapter: Chapter,\n verse: Verse,\n nodes: RewindableIterator<Node>\n ): IterableIterator<string | FootnoteReference | Text | InlineLineBreak> {\n let lastParent: Element | null = null;\n while (true) {\n const { done, value: node } = nodes.next();\n if (done) {\n break;\n }\n\n if (node.nodeName === 'verse') {\n if (!(node instanceof Element) || !node.hasAttribute('eid')) {\n nodes.rewind(1);\n }\n break;\n }\n\n const parent = node.parentElement!;\n let poem: number | null = null;\n let descriptive: boolean | null = null;\n\n if (parent.nodeName === 'para') {\n const style = parent.getAttribute('style');\n if (\n style === 'q1' ||\n style === 'q2' ||\n style === 'q3' ||\n style === 'q4'\n ) {\n poem =\n style === 'q1'\n ? 1\n : style === 'q2'\n ? 2\n : style === 'q3'\n ? 3\n : 4;\n\n // Send explicit line breaks\n // if we are in a new paragraph but the previous paragraph had the same poem style\n if (parent.previousElementSibling?.nodeName === 'para') {\n const previousStyle =\n parent.previousElementSibling?.getAttribute(\n 'style'\n );\n if (previousStyle === style && lastParent !== parent) {\n lastParent = parent;\n yield {\n lineBreak: true,\n };\n }\n }\n } else if (style === 'd') {\n descriptive = true;\n }\n }\n\n for (let content of this.iterateNodeTextContent(\n nodes,\n node,\n chapter,\n verse\n )) {\n if (poem !== null || descriptive !== null) {\n if (typeof content === 'string') {\n let text: Text = {\n text: content,\n };\n\n if (poem !== null) {\n text.poem = poem;\n }\n\n if (descriptive !== null) {\n text.descriptive = true;\n }\n\n yield text;\n } else {\n let text:\n | InlineLineBreak\n | InlineHeading\n | FootnoteReference\n | Text = {\n ...content,\n };\n\n if ('text' in text) {\n if (poem !== null) {\n text.poem = poem;\n }\n\n if (descriptive !== null) {\n text.descriptive = true;\n }\n }\n yield text;\n }\n } else {\n yield content;\n }\n }\n }\n }\n\n parseVerse(\n element: Element,\n chapter: Chapter,\n nodes: RewindableIterator<Node>\n ): Verse {\n const verse: Verse = {\n type: 'verse',\n number: parseInt(element.getAttribute('number') || '0', 10),\n content: [],\n };\n\n if (this._currentChapter && this._lastVerse) {\n if (this._currentChapter.number === chapter.number) {\n // We're parsing the same chapter as the last one\n const delta = verse.number - this._lastVerse.number;\n if (delta > 1) {\n // Delta is greater than 1, so we might have missed some verses\n for (\n let v = this._lastVerse.number + 1;\n v < verse.number;\n v++\n ) {\n let isExpected = false;\n if (this._bookId) {\n const missingVerse = `${this._bookId} ${chapter.number}:${v}`;\n if (KNOWN_SKIPPED_VERSES.has(missingVerse)) {\n isExpected = true;\n }\n }\n\n if (!isExpected) {\n this._messages.push({\n type: 'warning',\n message: `Verse ${this._bookId ?? '(null)'} ${chapter.number}:${v} is missing.`,\n });\n }\n }\n }\n }\n }\n this._lastVerse = verse;\n\n for (let content of this.iterateVerseContent(chapter, verse, nodes)) {\n addOrJoin(verse.content, content);\n }\n\n trimContent(verse.content);\n return verse;\n }\n\n *parseHebrewSubtitle(\n para: Element,\n chapter: Chapter,\n nodes: RewindableIterator<Node>\n ): IterableIterator<HebrewSubtitle | Verse> {\n const subtitle: HebrewSubtitle = {\n type: 'hebrew_subtitle',\n content: [],\n };\n\n for (let content of this.iterateHebrewSubtitleContent(\n para,\n chapter,\n nodes\n )) {\n if (typeof content === 'object' && 'number' in content) {\n yield content;\n continue;\n }\n addOrJoin(subtitle.content, content);\n }\n\n trimContent(subtitle.content);\n if (subtitle.content.length > 0) {\n yield subtitle;\n }\n }\n\n *iterateHebrewSubtitleContent(\n element: Element,\n chapter: Chapter,\n nodes: RewindableIterator<Node>\n ): IterableIterator<\n Verse | string | Text | FootnoteReference | InlineLineBreak\n > {\n while (true) {\n const { done, value: node } = nodes.next();\n if (done) {\n break;\n }\n\n if (!isParent(node, element)) {\n nodes.rewind(1);\n break;\n }\n\n if (node instanceof Element && node.nodeName === 'verse') {\n yield this.parseVerse(node, chapter, nodes);\n } else {\n yield* this.iterateNodeTextContent(nodes, node, chapter);\n }\n }\n }\n\n *iterateNodeTextContent(\n nodes: RewindableIterator<Node>,\n node: Node,\n chapter: Chapter,\n verse?: Verse\n ): IterableIterator<string | Text | FootnoteReference | InlineLineBreak> {\n if (node instanceof Element && node.nodeName === 'note') {\n yield* this.iterateNote(nodes, node, chapter, verse);\n } else if (node instanceof Element && node.nodeName === 'char') {\n yield* this.iterateChar(nodes, node);\n } else if (\n node instanceof Element &&\n node.nodeName === 'para' &&\n node.getAttribute('style') === 'b'\n ) {\n for (let _ of children(nodes, node)) {\n // iterate through all the children to prevent iterating over them multiple times\n }\n yield {\n lineBreak: true,\n };\n } else if (node.nodeType === NodeType.Text) {\n yield node.textContent || '';\n }\n }\n\n *iterateCharContent(char: Element): IterableIterator<string | Text> {\n const style = char.getAttribute('style');\n const text = trimText(char.textContent || '');\n if (style === 'wj') {\n yield {\n text,\n wordsOfJesus: true,\n };\n } else {\n yield text;\n }\n }\n\n *iterateNote(\n nodes: RewindableIterator<Node>,\n node: Element,\n chapter: Chapter,\n verse?: Verse\n ): IterableIterator<FootnoteReference> {\n const style = node.getAttribute('style');\n if (style === 'f') {\n const verseReferenceRegex = /^[0-9]{1,3}:[0-9]{1,3}/;\n\n let text = '';\n for (let child of children(nodes, node)) {\n if (child.nodeType === NodeType.Text) {\n text += child.textContent || '';\n }\n }\n\n text = text.trim();\n if (verseReferenceRegex.test(text)) {\n text = text.replace(verseReferenceRegex, '').trim();\n }\n\n const note: Footnote = {\n noteId: this._noteCounter++,\n caller: node.getAttribute('caller') || null,\n text,\n reference: {\n chapter: chapter.number,\n verse: verse?.number ?? 0,\n },\n };\n\n chapter.footnotes.push(note);\n\n yield {\n noteId: note.noteId,\n };\n } else {\n for (let _ of children(nodes, node)) {\n // iterate through all the children\n // so that we don't end up with duplicates\n }\n }\n }\n\n *iterateChar(\n nodes: RewindableIterator<Node>,\n node: Element\n ): IterableIterator<string | Text> {\n const style = node.getAttribute('style');\n let text = '';\n\n for (let char of children(nodes, node)) {\n if (char.nodeType === NodeType.Text) {\n text += char.textContent || '';\n }\n }\n\n if (style === 'wj') {\n yield {\n text,\n wordsOfJesus: true,\n };\n } else {\n yield text;\n }\n\n // if (!parentChar(node) && !parentNote(node)) {\n // yield *iterateCharContent(node);\n // }\n }\n}\n\n// Taken from https://github.com/gracious-tech/fetch/blob/1576cc4eafb32bf347a09332094cf17c2231c90c/converters/usx-to-json/src/elements.ts#L16\nconst ignoredParaStyles = new Set([\n // <para> Identification [exclude all] - Running headings & table of contents\n 'ide', // See https://github.com/schierlm/BibleMultiConverter/issues/67\n 'rem', // Remarks (valid in schema though missed in docs)\n 'h',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'toc1',\n 'toc2',\n 'toc3',\n 'toca1',\n 'toca2',\n 'toca3',\n\n /* <para> Introductions [exclude all] - Introductionary (non-biblical) content\n Which might be helpful in a printed book, but intro material in apps is usually bad UX,\n and users that really care can research a translations methodology themselves\n */\n 'imt',\n 'imt1',\n 'imt2',\n 'imt3',\n 'imt4',\n 'is',\n 'is1',\n 'is2',\n 'is3',\n 'is4',\n 'ip',\n 'ipi',\n 'im',\n 'imi',\n 'ipq',\n 'imq',\n 'ipr',\n 'iq',\n 'iq1',\n 'iq2',\n 'iq3',\n 'iq4',\n 'ib',\n 'ili',\n 'ili1',\n 'ili2',\n 'ili3',\n 'ili4',\n 'iot',\n 'io',\n 'io1',\n 'io2',\n 'io3',\n 'io4',\n 'iex',\n 'imte',\n 'ie',\n\n /* <para> Headings [exclude some] - Exclude book & chapter headings but keep section headings\n Not excluded: ms# | mr | s# | sr | d | sp | sd#\n */\n 'mt',\n 'mt1',\n 'mt2',\n 'mt3',\n 'mt4',\n 'mte',\n 'mte1',\n 'mte2',\n 'mte3',\n 'mte4',\n 'cl',\n 'cd', // Non-biblical chapter summary, more than heading\n 'r', // Parallels to be provided by external data\n]);\n\nfunction* iterateCharContent(char: Element): IterableIterator<string | Text> {\n const style = char.getAttribute('style');\n const text = trimText(char.textContent || '');\n if (style === 'wj') {\n yield {\n text,\n wordsOfJesus: true,\n };\n } else {\n yield text;\n }\n}\n\nfunction trimText(text: string): string {\n return text.replace(/\\s+/g, ' ');\n}\n\nfunction trimContent<T extends string | unknown>(content: T[]): T[] {\n for (let i = 0; i < content.length; i++) {\n const value = content[i];\n if (typeof value === 'string') {\n content[i] = trimText(value as string).trim() as T;\n if (content[i] === '') {\n content.splice(i, 1);\n i--;\n continue;\n }\n } else if (isVerseText(value)) {\n value.text = trimText(value.text).trim();\n if (value.text === '') {\n content.splice(i, 1);\n i--;\n continue;\n }\n }\n }\n return content;\n}\n\nfunction addOrJoin(array: (string | unknown)[], value: string | unknown) {\n if (array.length === 0) {\n array.push(value);\n } else {\n const last = array[array.length - 1];\n if (typeof last === 'string' && typeof value === 'string') {\n array[array.length - 1] = last + value;\n } else if (\n isVerseText(last) &&\n isVerseText(value) &&\n hasSameFormatting(last, value)\n ) {\n last.text += value.text;\n } else {\n array.push(value);\n }\n }\n}\n\nfunction isVerseText(value: unknown): value is Text {\n return typeof value === 'object' && value !== null && 'text' in value;\n}\n\nfunction hasSameFormatting(a: Text, b: Text): boolean {\n return a.poem === b.poem && a.wordsOfJesus === b.wordsOfJesus;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,uBAKO;AACP,mBAAqC;AAErC,IAAK,WAAL,kBAAKA,cAAL;AACI,EAAAA,oBAAA,UAAO,KAAP;AADC,SAAAA;AAAA,GAAA;AAQE,MAAM,iBAAiB;AAKvB,MAAM,UAAU;AAAA,EACX;AAAA,EACA,eAAuB;AAAA,EACvB,YAA4B,CAAC;AAAA,EAC7B,aAA2B;AAAA,EAC3B,kBAAkC;AAAA,EAClC,UAAyB;AAAA,EAEjC,YAAY,WAAsB;AAC9B,SAAK,aAAa;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,MAAM,KAAwB;AACjC,SAAK,eAAe;AACpB,SAAK,YAAY,CAAC;AAClB,SAAK,aAAa;AAClB,SAAK,kBAAkB;AACvB,SAAK,UAAU;AACf,UAAM,SAAS,KAAK;AACpB,UAAM,MAAM,OAAO,gBAAgB,KAAK,iBAAiB;AACzD,UAAM,aAAa,IAAI;AAEvB,QAAI,OAAkB;AAAA,MAClB,MAAM;AAAA,MACN,SAAS,CAAC;AAA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from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var utils_exports = {};
|
|
20
20
|
__export(utils_exports, {
|
|
21
|
+
KNOWN_SKIPPED_VERSES: () => KNOWN_SKIPPED_VERSES,
|
|
21
22
|
getBookId: () => getBookId,
|
|
22
23
|
getFirstNonEmpty: () => getFirstNonEmpty,
|
|
23
24
|
getTranslationId: () => getTranslationId,
|
|
@@ -34,7 +35,8 @@ const TRANSLATION_ID_MAP = /* @__PURE__ */ new Map([
|
|
|
34
35
|
["arb_nav", "ARBNAV"],
|
|
35
36
|
["eng_webp", "ENGWEBP"],
|
|
36
37
|
["hin_irv", "HINIRV"],
|
|
37
|
-
["hbo_mas", "HBOMAS"]
|
|
38
|
+
["hbo_mas", "HBOMAS"],
|
|
39
|
+
["eng_drv", "eng_dra"]
|
|
38
40
|
]);
|
|
39
41
|
function getTranslationId(translationId) {
|
|
40
42
|
return TRANSLATION_ID_MAP.get(translationId) ?? translationId;
|
|
@@ -247,8 +249,25 @@ function getBookId(book) {
|
|
|
247
249
|
}
|
|
248
250
|
return null;
|
|
249
251
|
}
|
|
252
|
+
const KNOWN_SKIPPED_VERSES = /* @__PURE__ */ new Set([
|
|
253
|
+
"MAT 17:21",
|
|
254
|
+
"MAT 18:11",
|
|
255
|
+
"MAT 23:14",
|
|
256
|
+
"MAR 7:16",
|
|
257
|
+
"MAR 9:44",
|
|
258
|
+
"MAR 9:46",
|
|
259
|
+
"MAR 11:26",
|
|
260
|
+
"LUK 17:36",
|
|
261
|
+
"JHN 5:4",
|
|
262
|
+
"ACT 8:37",
|
|
263
|
+
"ACT 15:34",
|
|
264
|
+
"ACT 24:7",
|
|
265
|
+
"ACT 28:29",
|
|
266
|
+
"ROM 16:24"
|
|
267
|
+
]);
|
|
250
268
|
// Annotate the CommonJS export names for ESM import in node:
|
|
251
269
|
0 && (module.exports = {
|
|
270
|
+
KNOWN_SKIPPED_VERSES,
|
|
252
271
|
getBookId,
|
|
253
272
|
getFirstNonEmpty,
|
|
254
273
|
getTranslationId,
|
package/dist/cjs/utils.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../utils.ts"],
|
|
4
|
-
"sourcesContent": ["/**\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,SAAS,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;
|
|
4
|
+
"sourcesContent": ["/**\n * Normalizes the given language code into a ISO 639 code.\n * @param language The language code to normalize.\n */\nexport function normalizeLanguage(language: string): string {\n return language;\n}\n\n/**\n * The map of translation IDs from fetch.bible to their translation ID in the API.\n */\nconst TRANSLATION_ID_MAP: Map<string, string> = new Map([\n ['eng_bsb', 'BSB'],\n ['arb_nav', 'ARBNAV'],\n ['eng_webp', 'ENGWEBP'],\n ['hin_irv', 'HINIRV'],\n ['hbo_mas', 'HBOMAS'],\n ['eng_drv', 'eng_dra'],\n]);\n\n/**\n * Gets the ID of the translation.\n * @param translation The translation to get the ID for.\n */\nexport function getTranslationId(translationId: string): string {\n return TRANSLATION_ID_MAP.get(translationId) ?? translationId;\n}\n\nexport function isEmptyOrWhitespace(str: string | null | undefined): boolean {\n return !str || /^\\s*$/.test(str);\n}\n\nexport function getFirstNonEmpty<T extends string>(...values: T[]): T {\n for (let value of values) {\n if (!isEmptyOrWhitespace(value)) {\n return value;\n }\n }\n\n throw new Error('All values are empty or whitespace!');\n}\n\nexport interface VerseRef {\n book: string;\n chapter: number;\n verse: number;\n\n /**\n * The rest of the content of the verse.\n */\n content?: string;\n\n /**\n * The chapter that the verse reference ends at.\n */\n endChapter?: number;\n\n /**\n * The verse that the verse reference ends at.\n */\n endVerse?: number;\n}\n\n/**\n * Parses the given verse reference.\n * Formatted like \"GEN 1:1\".\n *\n * @param text The reference to parse.\n */\nexport function parseVerseReference(text: string): VerseRef | null {\n const match = text.match(\n /^\\s*([0-9A-Za-z\\s]+)[\\s\\.]+(\\d+)[:\\.](\\d+)(?:-([0-9]+)(?:[\\s:\\.]([0-9]+))?)?/\n );\n\n if (!match) {\n return null;\n }\n\n const [reference, book, chapterStr, verseStr, endChapterStr, endVerseStr] =\n match;\n\n const chapter = parseInt(chapterStr);\n const verse = parseInt(verseStr);\n\n let endChapter = endChapterStr ? parseInt(endChapterStr) : undefined;\n let endVerse = endVerseStr ? parseInt(endVerseStr) : undefined;\n\n if (endChapter && !endVerse) {\n endVerse = endChapter;\n endChapter = undefined;\n }\n\n if (isNaN(chapter) || isNaN(verse)) {\n return null;\n }\n\n if (reference.length !== text.length) {\n return {\n book: getBookId(book) ?? book,\n chapter,\n verse,\n content: text.substring(reference.length).trim(),\n endChapter,\n endVerse,\n };\n }\n\n return {\n book: getBookId(book) ?? book,\n chapter,\n verse,\n endChapter,\n endVerse,\n };\n}\n\n/**\n * Defines a map that maps the book ID to the USFM Book identifier.\n */\nconst BOOK_ID_MAP: Map<string, string> = new Map([\n ['gen', 'GEN'],\n ['genesis', 'GEN'],\n ['exo', 'EXO'],\n ['exodus', 'EXO'],\n ['lev', 'LEV'],\n ['lev', 'LEV'],\n ['laviticus', 'LEV'],\n ['num', 'NUM'],\n ['numbers', 'NUM'],\n ['deu', 'DEU'],\n ['deuteronomy', 'DEU'],\n ['jos', 'JOS'],\n ['joshua', 'JOS'],\n ['jdg', 'JDG'],\n ['judges', 'JDG'],\n ['rut', 'RUT'],\n ['ruth', 'RUT'],\n ['1sa', '1SA'],\n ['1samuel', '1SA'],\n ['2sa', '2SA'],\n ['2samuel', '2SA'],\n ['1ki', '1KI'],\n ['1kings', '1KI'],\n ['1kgs', '1KI'],\n ['2ki', '2KI'],\n ['2kings', '2KI'],\n ['2kgs', '2KI'],\n ['1ch', '1CH'],\n ['1chronicles', '1CH'],\n ['chronicles1', '1CH'],\n ['2ch', '2CH'],\n ['2chronicles', '2CH'],\n ['chronicles2', '2CH'],\n ['ezr', 'EZR'],\n ['ezra', 'EZR'],\n ['neh', 'NEH'],\n ['nehemiah', 'NEH'],\n ['est', 'EST'],\n ['ester', 'EST'],\n ['job', 'JOB'],\n ['ps', 'PSA'],\n ['psa', 'PSA'],\n ['psalms', 'PSA'],\n ['psalm', 'PSA'],\n ['pr', 'PRO'],\n ['pro', 'PRO'],\n ['proverbs', 'PRO'],\n ['ecc', 'ECC'],\n ['ecclesiastes', 'ECC'],\n ['eccl', 'ECC'],\n ['sng', 'SNG'],\n ['song', 'SNG'],\n ['songofsolomon', 'SNG'],\n ['isa', 'ISA'],\n ['isaiah', 'ISA'],\n ['jer', 'JER'],\n ['jeremiah', 'JER'],\n ['lam', 'LAM'],\n ['lamentations', 'LAM'],\n ['ezk', 'EZK'],\n ['ezekiel', 'EZK'],\n ['ezek', 'EZK'],\n ['dan', 'DAN'],\n ['daniel', 'DAN'],\n ['hos', 'HOS'],\n ['hosea', 'HOS'],\n ['jol', 'JOL'],\n ['joel', 'JOL'],\n ['amo', 'AMO'],\n ['amos', 'AMO'],\n ['oba', 'OBA'],\n ['obadiah', 'OBA'],\n ['jon', 'JON'],\n ['jonah', 'JON'],\n ['mic', 'MIC'],\n ['micah', 'MIC'],\n ['nam', 'NAM'],\n ['nahum', 'NAM'],\n ['nah', 'NAM'],\n ['hab', 'HAB'],\n ['habakkuk', 'HAB'],\n ['zep', 'ZEP'],\n ['zepaniah', 'ZEP'],\n ['hag', 'HAG'],\n ['haggai', 'HAG'],\n ['zec', 'ZEC'],\n ['zechariah', 'ZEC'],\n ['mal', 'MAL'],\n ['malachi', 'MAL'],\n ['mat', 'MAT'],\n ['matthew', 'MAT'],\n ['mrk', 'MRK'],\n ['mark', 'MRK'],\n ['luk', 'LUK'],\n ['luke', 'LUK'],\n ['jhn', 'JHN'],\n ['john', 'JHN'],\n ['act', 'ACT'],\n ['acts', 'ACT'],\n ['rom', 'ROM'],\n ['romans', 'ROM'],\n ['1co', '1CO'],\n ['1corinthians', '1CO'],\n ['2co', '2CO'],\n ['2corinthians', '2CO'],\n ['gal', 'GAL'],\n ['galatians', 'GAL'],\n ['eph', 'EPH'],\n ['ephesians', 'EPH'],\n ['php', 'PHP'],\n ['philippians', 'PHP'],\n ['phil', 'PHP'],\n ['col', 'COL'],\n ['colossians', 'COL'],\n ['1th', '1TH'],\n ['1thessalonians', '1TH'],\n ['2th', '2TH'],\n ['2thessalonians', '2TH'],\n ['1ti', '1TI'],\n ['1timothy', '1TI'],\n ['2ti', '2TI'],\n ['2timothy', '2TI'],\n ['tit', 'TIT'],\n ['titus', 'TIT'],\n ['phm', 'PHM'],\n ['philemon', 'PHM'],\n ['phlm', 'PHM'],\n ['heb', 'HEB'],\n ['hebrews', 'HEB'],\n ['jas', 'JAS'],\n ['james', 'JAS'],\n ['1pe', '1PE'],\n ['1peter', '1PE'],\n ['2pe', '2PE'],\n ['2peter', '2PE'],\n ['1jn', '1JN'],\n ['1john', '1JN'],\n ['2jn', '2JN'],\n ['2john', '2JN'],\n ['3jn', '3JN'],\n ['3john', '3JN'],\n ['jud', 'JUD'],\n ['jude', 'JUD'],\n ['rev', 'REV'],\n ['revelation', 'REV'],\n]);\n\n/**\n * Gets the ID of the given book.\n * Returns null if the ID could not be found.\n * @param book The name/ID of the book.\n */\nexport function getBookId(book: string): string | null {\n const bookLower = book.toLowerCase().replaceAll(/\\s+/g, '');\n\n const id = BOOK_ID_MAP.get(bookLower);\n if (id) {\n return id;\n }\n\n for (let [key, id] of BOOK_ID_MAP) {\n if (bookLower.startsWith(key)) {\n return id;\n }\n }\n\n return null;\n}\n\n/**\n * A brief list of verses which may appear in some older translations\n * but are not present in more modern translations.\n */\nexport const KNOWN_SKIPPED_VERSES = new Set([\n 'MAT 17:21',\n 'MAT 18:11',\n 'MAT 23:14',\n 'MAR 7:16',\n 'MAR 9:44',\n 'MAR 9:46',\n 'MAR 11:26',\n 'LUK 17:36',\n 'JHN 5:4',\n 'ACT 8:37',\n 'ACT 15:34',\n 'ACT 24:7',\n 'ACT 28:29',\n 'ROM 16:24',\n]);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,SAAS,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;AAAA,EACpB,CAAC,WAAW,SAAS;AACzB,CAAC;AAMM,SAAS,iBAAiB,eAA+B;AAC5D,SAAO,mBAAmB,IAAI,aAAa,KAAK;AACpD;AAEO,SAAS,oBAAoB,KAAyC;AACzE,SAAO,CAAC,OAAO,QAAQ,KAAK,GAAG;AACnC;AAEO,SAAS,oBAAsC,QAAgB;AAClE,WAAS,SAAS,QAAQ;AACtB,QAAI,CAAC,oBAAoB,KAAK,GAAG;AAC7B,aAAO;AAAA,IACX;AAAA,EACJ;AAEA,QAAM,IAAI,MAAM,qCAAqC;AACzD;AA6BO,SAAS,oBAAoB,MAA+B;AAC/D,QAAM,QAAQ,KAAK;AAAA,IACf;AAAA,EACJ;AAEA,MAAI,CAAC,OAAO;AACR,WAAO;AAAA,EACX;AAEA,QAAM,CAAC,WAAW,MAAM,YAAY,UAAU,eAAe,WAAW,IACpE;AAEJ,QAAM,UAAU,SAAS,UAAU;AACnC,QAAM,QAAQ,SAAS,QAAQ;AAE/B,MAAI,aAAa,gBA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E;AAE1D,QAAM,KAAK,YAAY,IAAI,SAAS;AACpC,MAAI,IAAI;AACJ,WAAO;AAAA,EACX;AAEA,WAAS,CAAC,KAAKA,GAAE,KAAK,aAAa;AAC/B,QAAI,UAAU,WAAW,GAAG,GAAG;AAC3B,aAAOA;AAAA,IACX;AAAA,EACJ;AAEA,SAAO;AACX;AAMO,MAAM,uBAAuB,oBAAI,IAAI;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ,CAAC;",
|
|
6
6
|
"names": ["id"]
|
|
7
7
|
}
|
|
@@ -21,6 +21,15 @@ export function generateApiForDataset(dataset, options = {}) {
|
|
|
21
21
|
const getNativeName = options.getNativeName;
|
|
22
22
|
const getEnglishName = options.getEnglishName;
|
|
23
23
|
for (let { books, ...translation } of dataset.translations) {
|
|
24
|
+
let numberOfBooks = 0;
|
|
25
|
+
let numberOfApocryphalBooks = 0;
|
|
26
|
+
for (let book of books) {
|
|
27
|
+
if (book.isApocryphal) {
|
|
28
|
+
numberOfApocryphalBooks++;
|
|
29
|
+
} else {
|
|
30
|
+
numberOfBooks++;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
24
33
|
const apiTranslation = {
|
|
25
34
|
...translation,
|
|
26
35
|
availableFormats: ["json"],
|
|
@@ -28,12 +37,15 @@ export function generateApiForDataset(dataset, options = {}) {
|
|
|
28
37
|
translation.id,
|
|
29
38
|
apiPathPrefix
|
|
30
39
|
),
|
|
31
|
-
numberOfBooks
|
|
40
|
+
numberOfBooks,
|
|
32
41
|
totalNumberOfChapters: 0,
|
|
33
42
|
totalNumberOfVerses: 0,
|
|
34
43
|
languageName: getNativeName ? getNativeName(translation.language) ?? void 0 : void 0,
|
|
35
44
|
languageEnglishName: getEnglishName ? getEnglishName(translation.language) ?? void 0 : void 0
|
|
36
45
|
};
|
|
46
|
+
if (numberOfApocryphalBooks > 0) {
|
|
47
|
+
apiTranslation.numberOfApocryphalBooks = numberOfApocryphalBooks;
|
|
48
|
+
}
|
|
37
49
|
const translationBooks = {
|
|
38
50
|
translation: apiTranslation,
|
|
39
51
|
books: []
|
|
@@ -108,8 +120,19 @@ export function generateApiForDataset(dataset, options = {}) {
|
|
|
108
120
|
api.translationBookChapters.push(apiBookChapter);
|
|
109
121
|
}
|
|
110
122
|
translationBooks.books.push(apiBook);
|
|
111
|
-
|
|
112
|
-
|
|
123
|
+
if (apiBook.isApocryphal) {
|
|
124
|
+
if (!apiTranslation.totalNumberOfApocryphalChapters) {
|
|
125
|
+
apiTranslation.totalNumberOfApocryphalChapters = 0;
|
|
126
|
+
}
|
|
127
|
+
if (!apiTranslation.totalNumberOfApocryphalVerses) {
|
|
128
|
+
apiTranslation.totalNumberOfApocryphalVerses = 0;
|
|
129
|
+
}
|
|
130
|
+
apiTranslation.totalNumberOfApocryphalChapters += apiBook.numberOfChapters;
|
|
131
|
+
apiTranslation.totalNumberOfApocryphalVerses += apiBook.totalNumberOfVerses;
|
|
132
|
+
} else {
|
|
133
|
+
apiTranslation.totalNumberOfChapters += apiBook.numberOfChapters;
|
|
134
|
+
apiTranslation.totalNumberOfVerses += apiBook.totalNumberOfVerses;
|
|
135
|
+
}
|
|
113
136
|
}
|
|
114
137
|
for (let i = 0; i < translationChapters.length; i++) {
|
|
115
138
|
if (i > 0) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../generation/api.ts"],
|
|
4
|
-
"sourcesContent": ["import {\r\n Commentary,\r\n CommentaryBook,\r\n CommentaryBookChapter,\r\n CommentaryProfile,\r\n OutputFile,\r\n Translation,\r\n TranslationBook,\r\n TranslationBookChapter,\r\n TranslationBookChapterAudioLinks,\r\n} from './common-types.js';\r\nimport { DatasetOutput } from './dataset.js';\r\n\r\n/**\r\n * Defines the output of the API generation.\r\n */\r\nexport interface ApiOutput {\r\n /**\r\n * The list of available translations.\r\n * This maps to the /api/available-translations.json endpoint.\r\n */\r\n availableTranslations: ApiAvailableTranslations;\r\n\r\n /**\r\n * The list of books for each translation.\r\n * This maps to the /api/:translationId/books.json endpoint.\r\n */\r\n translationBooks: ApiTranslationBooks[];\r\n\r\n /**\r\n * The list of chapters for each book.\r\n * This maps to the following endpoints:\r\n * - /api/:translationId/:bookId/:chapterNumber.json\r\n * - /api/:translationId/:bookCommonName/:chapterNumber.json\r\n */\r\n translationBookChapters: ApiTranslationBookChapter[];\r\n\r\n /**\r\n * The list of audio files.\r\n * This maps to the following endpoints:\r\n * - /api/:translationId/:bookId/:chapterNumber.:reader.mp3\r\n */\r\n translationBookChapterAudio: ApiTranslationBookChapterAudio[];\r\n\r\n /**\r\n * The list of available commentaries.\r\n * This maps to the /api/available-commentaries.json endpoint.\r\n */\r\n availableCommentaries: ApiAvailableCommentaries;\r\n\r\n /**\r\n * The list of books for each commentary.\r\n * This maps to the /api/c/:commentaryId/books.json endpoint.\r\n */\r\n commentaryBooks: ApiCommentaryBooks[];\r\n\r\n /**\r\n * The list of profiles for each commentary.\r\n * This maps to the /api/c/:commentaryId/profiles.json endpoint.\r\n */\r\n commentaryProfiles: ApiCommentaryProfiles[];\r\n\r\n /**\r\n * The list of chapters for each commentary book.\r\n * This maps to the following endpoint:\r\n * - /api/c/:commentaryId/:bookId/:chapterNumber.json\r\n */\r\n commentaryBookChapters: ApiCommentaryBookChapter[];\r\n\r\n /**\r\n * The list of individual profiles for each commentary.\r\n * This maps to the following endpoint:\r\n * - /api/c/:commentaryId/profiles/:profileId.json\r\n */\r\n commentaryProfileContents: ApiCommentaryProfileContent[];\r\n\r\n /**\r\n * The path prefix that the API should use.\r\n */\r\n pathPrefix: string;\r\n}\r\n\r\n/**\r\n * The list of available translations.\r\n * Maps to the /api/available-translations.json endpoint.\r\n */\r\nexport interface ApiAvailableTranslations {\r\n /**\r\n * The list of translations.\r\n */\r\n translations: ApiTranslation[];\r\n}\r\n\r\n/**\r\n * The list of available commentaries.\r\n * Maps to the /api/available-commentaries.json endpoint.\r\n */\r\nexport interface ApiAvailableCommentaries {\r\n /**\r\n * The list of commentaries.\r\n */\r\n commentaries: ApiCommentary[];\r\n}\r\n\r\n/**\r\n * Defines a translation that is used in the API.\r\n */\r\nexport interface ApiTranslation extends Translation {\r\n /**\r\n * The API link for the list of available books for this translation.\r\n */\r\n listOfBooksApiLink: string;\r\n\r\n /**\r\n * The available list of formats.\r\n */\r\n availableFormats: ('json' | 'usfm')[];\r\n\r\n /**\r\n * The number of books that are contained in this translation.\r\n *\r\n * Complete translations should have the same number of books as the Bible (66).\r\n */\r\n numberOfBooks: number;\r\n\r\n /**\r\n * The total number of chapters that are contained in this translation.\r\n *\r\n * Complete translations should have the same number of chapters as the Bible (1,189).\r\n */\r\n totalNumberOfChapters: number;\r\n\r\n /**\r\n * The total number of verses that are contained in this translation.\r\n *\r\n * Complete translations should have the same number of verses as the Bible (around 31,102 - some translations exclude verses based on the aparent likelyhood of existing in the original source texts).\r\n */\r\n totalNumberOfVerses: number;\r\n\r\n /**\r\n * Gets the name of the language that the translation is in.\r\n * Null or undefined if the name of the language is not known.\r\n */\r\n languageName?: string;\r\n\r\n /**\r\n * Gets the name of the language in English.\r\n * Null or undefined if the language doesn't have an english name.\r\n */\r\n languageEnglishName?: string;\r\n}\r\n\r\n/**\r\n * Defines a commentary that is used in the API.\r\n */\r\nexport interface ApiCommentary extends Commentary {\r\n /**\r\n * The API link for the list of available books for this translation.\r\n */\r\n listOfBooksApiLink: string;\r\n\r\n /**\r\n * The API link for the list of available profiles for this commentary.\r\n */\r\n listOfProfilesApiLink: string;\r\n\r\n /**\r\n * The available list of formats.\r\n */\r\n availableFormats: ('json' | 'usfm')[];\r\n\r\n /**\r\n * The number of books that are contained in this commentary.\r\n *\r\n * Complete commentaries should have the same number of books as the Bible (66).\r\n */\r\n numberOfBooks: number;\r\n\r\n /**\r\n * The total number of chapters that are contained in this translation.\r\n *\r\n * Complete commentaries should have the same number of chapters as the Bible (1,189).\r\n */\r\n totalNumberOfChapters: number;\r\n\r\n /**\r\n * The total number of verses that are contained in this commentary.\r\n *\r\n * Complete commentaries should have the same number of verses as the Bible (around 31,102 - some commentaries exclude verses based on the aparent likelyhood of existing in the original source texts).\r\n */\r\n totalNumberOfVerses: number;\r\n\r\n /**\r\n * The total number of profiles that are contained in this commentary.\r\n *\r\n * Profiles are used to provide additional information about people and people groups that are mentioned in the Bible.\r\n */\r\n totalNumberOfProfiles: number;\r\n\r\n /**\r\n * Gets the name of the language that the commentary is in.\r\n * Null or undefined if the name of the language is not known.\r\n */\r\n languageName?: string;\r\n\r\n /**\r\n * Gets the name of the language in English.\r\n * Null or undefined if the language doesn't have an english name.\r\n */\r\n languageEnglishName?: string;\r\n}\r\n\r\n/**\r\n * Defines an interface that contains information about the books that are available for a translation.\r\n */\r\nexport interface ApiTranslationBooks {\r\n /**\r\n * The translation information for the books.\r\n */\r\n translation: ApiTranslation;\r\n\r\n /**\r\n * The list of books that are available for the translation.\r\n */\r\n books: ApiTranslationBook[];\r\n}\r\n\r\n/**\r\n * Defines an interface that contains information about the books that are available for a commentary.\r\n */\r\nexport interface ApiCommentaryBooks {\r\n /**\r\n * The commentary information for the books.\r\n */\r\n commentary: ApiCommentary;\r\n\r\n /**\r\n * The list of books that are available for the commentary.\r\n */\r\n books: ApiCommentaryBook[];\r\n}\r\n\r\n/**\r\n * Defines an interface that contains information about the profiles that are available for a commentary.\r\n */\r\nexport interface ApiCommentaryProfiles {\r\n /**\r\n * The commentary information for the books.\r\n */\r\n commentary: ApiCommentary;\r\n\r\n /**\r\n * The list of profiles that are available for the commentary.\r\n */\r\n profiles: ApiCommentaryProfile[];\r\n}\r\n\r\n/**\r\n * Defines an interface that contains information about a profile.\r\n */\r\nexport interface ApiCommentaryProfile extends CommentaryProfile {\r\n /**\r\n * The link to this profile.\r\n */\r\n thisProfileLink: string;\r\n\r\n /**\r\n * The link to the chapter that this profile references in the commentary.\r\n */\r\n referenceChapterLink: string | null;\r\n}\r\n\r\n/**\r\n * Defines a translation book that is used in the API.\r\n */\r\nexport interface ApiTranslationBook extends TranslationBook {\r\n /**\r\n * The link to the first chapter of the book.\r\n */\r\n firstChapterApiLink: string;\r\n\r\n /**\r\n * The link to the last chapter of the book.\r\n */\r\n lastChapterApiLink: string;\r\n\r\n /**\r\n * The number of chapters that the book contains.\r\n */\r\n numberOfChapters: number;\r\n\r\n /**\r\n * The number of verses that the book contains.\r\n */\r\n totalNumberOfVerses: number;\r\n}\r\n\r\n/**\r\n * Defines a commentary book that is used in the API.\r\n */\r\nexport interface ApiCommentaryBook extends CommentaryBook {\r\n /**\r\n * The link to the first chapter of the book.\r\n */\r\n firstChapterApiLink: string;\r\n\r\n /**\r\n * The link to the last chapter of the book.\r\n */\r\n lastChapterApiLink: string;\r\n\r\n /**\r\n * The number of chapters that the book contains.\r\n */\r\n numberOfChapters: number;\r\n\r\n /**\r\n * The number of verses that the book contains.\r\n */\r\n totalNumberOfVerses: number;\r\n}\r\n\r\n/**\r\n * Defines an interface that contains information about a book chapter.\r\n */\r\nexport interface ApiTranslationBookChapter extends TranslationBookChapter {\r\n /**\r\n * The translation information for the book chapter.\r\n */\r\n translation: ApiTranslation;\r\n\r\n /**\r\n * The book information for the book chapter.\r\n */\r\n book: ApiTranslationBook;\r\n\r\n /**\r\n * The link to this chapter.\r\n */\r\n thisChapterLink: string;\r\n\r\n /**\r\n * The link to the next chapter.\r\n * Null if this is the last chapter in the translation.\r\n */\r\n nextChapterApiLink: string | null;\r\n\r\n /**\r\n * The links to the audio versions for the next chapter.\r\n * Null if this is the last chapter in the translation.\r\n */\r\n nextChapterAudioLinks: TranslationBookChapterAudioLinks | null;\r\n\r\n /**\r\n * The link to the previous chapter.\r\n * Null if this is the first chapter in the translation.\r\n */\r\n previousChapterApiLink: string | null;\r\n\r\n /**\r\n * The links to the audio versions for the previous chapter.\r\n * Null if this is the first chapter in the translation.\r\n */\r\n previousChapterAudioLinks: TranslationBookChapterAudioLinks | null;\r\n\r\n /**\r\n * The number of verses that the chapter contains.\r\n */\r\n numberOfVerses: number;\r\n}\r\n\r\n/**\r\n * Defines an interface that contains information about a book chapter.\r\n */\r\nexport interface ApiCommentaryBookChapter extends CommentaryBookChapter {\r\n /**\r\n * The commentary information for the book chapter.\r\n */\r\n commentary: ApiCommentary;\r\n\r\n /**\r\n * The book information for the book chapter.\r\n */\r\n book: ApiCommentaryBook;\r\n\r\n /**\r\n * The link to this chapter.\r\n */\r\n thisChapterLink: string;\r\n\r\n /**\r\n * The link to the next chapter.\r\n * Null if this is the last chapter in the translation.\r\n */\r\n nextChapterApiLink: string | null;\r\n\r\n /**\r\n * The link to the previous chapter.\r\n * Null if this is the first chapter in the translation.\r\n */\r\n previousChapterApiLink: string | null;\r\n\r\n /**\r\n * The number of verses that the chapter contains.\r\n */\r\n numberOfVerses: number;\r\n}\r\n\r\nexport interface ApiTranslationBookChapterAudio {\r\n /**\r\n * The chapter that the audio is for.\r\n */\r\n chapter: ApiTranslationBookChapter;\r\n\r\n /**\r\n * The link that the audio should be placed at.\r\n */\r\n link: string;\r\n\r\n /**\r\n * The original URL of the audio.\r\n */\r\n originalUrl: string;\r\n}\r\n\r\nexport interface ApiCommentaryProfileContent {\r\n /**\r\n * The commentary information for the profile.\r\n */\r\n commentary: ApiCommentary;\r\n\r\n /**\r\n * The information about the profile.\r\n */\r\n profile: ApiCommentaryProfile;\r\n\r\n /**\r\n * The content of the profile.\r\n */\r\n content: string[];\r\n}\r\n\r\n/**\r\n * The options for generating the API.\r\n */\r\nexport interface GenerateApiOptions {\r\n /**\r\n * Whether to use the common name for the book chapter API link. If false, then book IDs are used.\r\n * Audio URLs will always use the book ID.\r\n * Defaults to false.\r\n */\r\n useCommonName?: boolean;\r\n\r\n /**\r\n * Whether to replace the audio URLs in the dataset with ones that are hosted locally.\r\n * If true, then the audio URLs in the dataset will be replaced with ones that reference files hosted by the API itself.\r\n * If false, then the audio URLs in the dataset will be left as is.\r\n * Defaults to false.\r\n */\r\n generateAudioFiles?: boolean;\r\n\r\n /**\r\n * Gets the english name of the given language.\r\n * If not provided, then the english name for the language will be unknown and omitted.\r\n * @param language The language to get the english name for.\r\n */\r\n getEnglishName?: (language: string) => string | null | undefined;\r\n\r\n /**\r\n * Gets the native name of the given language.\r\n * If not provided, then the native name for the language will be unknown and omitted.\r\n * @param language The language to get the native name for.\r\n */\r\n getNativeName?: (language: string) => string | null | undefined;\r\n\r\n /**\r\n * The prefix that should be added to paths that are generated.\r\n */\r\n pathPrefix?: string;\r\n}\r\n\r\n/**\r\n * Generates the API output for the given dataset.\r\n * @param dataset The dataset to generate the API for.\r\n * @param options The options for generating the API.\r\n */\r\nexport function generateApiForDataset(\r\n dataset: DatasetOutput,\r\n options: GenerateApiOptions = {}\r\n): ApiOutput {\r\n const { useCommonName, pathPrefix } = options;\r\n const apiPathPrefix = pathPrefix ? pathPrefix : '';\r\n let api: ApiOutput = {\r\n availableTranslations: {\r\n translations: [],\r\n },\r\n translationBooks: [],\r\n translationBookChapters: [],\r\n translationBookChapterAudio: [],\r\n availableCommentaries: {\r\n commentaries: [],\r\n },\r\n commentaryBookChapters: [],\r\n commentaryBooks: [],\r\n commentaryProfiles: [],\r\n commentaryProfileContents: [],\r\n pathPrefix: apiPathPrefix,\r\n };\r\n\r\n const getNativeName = options.getNativeName;\r\n const getEnglishName = options.getEnglishName;\r\n\r\n for (let { books, ...translation } of dataset.translations) {\r\n const apiTranslation: ApiTranslation = {\r\n ...translation,\r\n availableFormats: ['json'],\r\n listOfBooksApiLink: listOfBooksApiLink(\r\n translation.id,\r\n apiPathPrefix\r\n ),\r\n numberOfBooks: books.length,\r\n totalNumberOfChapters: 0,\r\n totalNumberOfVerses: 0,\r\n languageName: getNativeName\r\n ? (getNativeName(translation.language) ?? undefined)\r\n : undefined,\r\n languageEnglishName: getEnglishName\r\n ? (getEnglishName(translation.language) ?? undefined)\r\n : undefined,\r\n };\r\n\r\n const translationBooks: ApiTranslationBooks = {\r\n translation: apiTranslation,\r\n books: [],\r\n };\r\n\r\n let translationChapters: ApiTranslationBookChapter[] = [];\r\n\r\n for (let { chapters, ...book } of books) {\r\n const apiBook: ApiTranslationBook = {\r\n ...book,\r\n firstChapterApiLink: bookChapterApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n 1,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n lastChapterApiLink: bookChapterApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n chapters.length,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n numberOfChapters: chapters.length,\r\n totalNumberOfVerses: 0,\r\n };\r\n\r\n for (let { chapter, thisChapterAudioLinks } of chapters) {\r\n const audio: TranslationBookChapterAudioLinks = {};\r\n const apiBookChapter: ApiTranslationBookChapter = {\r\n translation: apiTranslation,\r\n book: apiBook,\r\n chapter: chapter,\r\n thisChapterLink: bookChapterApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n thisChapterAudioLinks: audio,\r\n nextChapterApiLink: null,\r\n nextChapterAudioLinks: null,\r\n previousChapterApiLink: null,\r\n previousChapterAudioLinks: null,\r\n numberOfVerses: 0,\r\n };\r\n\r\n for (let reader in thisChapterAudioLinks) {\r\n if (options.generateAudioFiles) {\r\n const apiAudio: ApiTranslationBookChapterAudio = {\r\n chapter: apiBookChapter,\r\n link: bookChapterAudioApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n chapter.number,\r\n reader,\r\n apiPathPrefix\r\n ),\r\n originalUrl: thisChapterAudioLinks[reader],\r\n };\r\n audio[reader] = apiAudio.link;\r\n api.translationBookChapterAudio.push(apiAudio);\r\n } else {\r\n audio[reader] = thisChapterAudioLinks[reader];\r\n }\r\n }\r\n\r\n for (let c of chapter.content) {\r\n if (c.type === 'verse') {\r\n apiBookChapter.numberOfVerses++;\r\n }\r\n }\r\n\r\n apiBook.totalNumberOfVerses += apiBookChapter.numberOfVerses;\r\n\r\n translationChapters.push(apiBookChapter);\r\n api.translationBookChapters.push(apiBookChapter);\r\n }\r\n\r\n translationBooks.books.push(apiBook);\r\n\r\n apiTranslation.totalNumberOfChapters += apiBook.numberOfChapters;\r\n apiTranslation.totalNumberOfVerses += apiBook.totalNumberOfVerses;\r\n }\r\n\r\n for (let i = 0; i < translationChapters.length; i++) {\r\n if (i > 0) {\r\n translationChapters[i].previousChapterApiLink =\r\n bookChapterApiLink(\r\n translation.id,\r\n getBookLink(translationChapters[i - 1].book),\r\n translationChapters[i - 1].chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n );\r\n translationChapters[i].previousChapterAudioLinks =\r\n translationChapters[i - 1].thisChapterAudioLinks;\r\n }\r\n\r\n if (i < translationChapters.length - 1) {\r\n translationChapters[i].nextChapterApiLink = bookChapterApiLink(\r\n translation.id,\r\n getBookLink(translationChapters[i + 1].book),\r\n translationChapters[i + 1].chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n );\r\n translationChapters[i].nextChapterAudioLinks =\r\n translationChapters[i + 1].thisChapterAudioLinks;\r\n }\r\n }\r\n\r\n api.availableTranslations.translations.push(apiTranslation);\r\n api.translationBooks.push(translationBooks);\r\n }\r\n\r\n for (let { books, profiles, ...commentary } of dataset.commentaries) {\r\n const apiCommentary: ApiCommentary = {\r\n ...commentary,\r\n availableFormats: ['json'],\r\n listOfBooksApiLink: listOfCommentaryBooksApiLink(\r\n commentary.id,\r\n apiPathPrefix\r\n ),\r\n listOfProfilesApiLink: profilesCommentaryApiLink(\r\n commentary.id,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n numberOfBooks: books.length,\r\n totalNumberOfChapters: 0,\r\n totalNumberOfVerses: 0,\r\n totalNumberOfProfiles: 0,\r\n languageName: getNativeName\r\n ? (getNativeName(commentary.language) ?? undefined)\r\n : undefined,\r\n languageEnglishName: getEnglishName\r\n ? (getEnglishName(commentary.language) ?? undefined)\r\n : undefined,\r\n };\r\n\r\n const commentaryBooks: ApiCommentaryBooks = {\r\n commentary: apiCommentary,\r\n books: [],\r\n };\r\n\r\n const commentaryProfiles: ApiCommentaryProfiles = {\r\n commentary: apiCommentary,\r\n profiles: [],\r\n };\r\n\r\n let commentaryChapters: ApiCommentaryBookChapter[] = [];\r\n\r\n for (let { chapters, ...book } of books) {\r\n const apiBook: ApiCommentaryBook = {\r\n ...book,\r\n firstChapterApiLink: bookCommentaryChapterApiLink(\r\n commentary.id,\r\n getBookLink(book),\r\n 1,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n lastChapterApiLink: bookCommentaryChapterApiLink(\r\n commentary.id,\r\n getBookLink(book),\r\n chapters.length,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n numberOfChapters: chapters.length,\r\n totalNumberOfVerses: 0,\r\n };\r\n\r\n for (let { chapter } of chapters) {\r\n const apiBookChapter: ApiCommentaryBookChapter = {\r\n commentary: apiCommentary,\r\n book: apiBook,\r\n chapter: chapter,\r\n thisChapterLink: bookCommentaryChapterApiLink(\r\n commentary.id,\r\n getBookLink(book),\r\n chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n nextChapterApiLink: null,\r\n previousChapterApiLink: null,\r\n numberOfVerses: 0,\r\n };\r\n\r\n for (let c of chapter.content) {\r\n if (c.type === 'verse') {\r\n apiBookChapter.numberOfVerses++;\r\n }\r\n }\r\n\r\n apiBook.totalNumberOfVerses += apiBookChapter.numberOfVerses;\r\n\r\n commentaryChapters.push(apiBookChapter);\r\n api.commentaryBookChapters.push(apiBookChapter);\r\n }\r\n\r\n commentaryBooks.books.push(apiBook);\r\n\r\n apiCommentary.totalNumberOfChapters += apiBook.numberOfChapters;\r\n apiCommentary.totalNumberOfVerses += apiBook.totalNumberOfVerses;\r\n }\r\n\r\n if (profiles) {\r\n for (let profile of profiles) {\r\n const apiProfile: ApiCommentaryProfile = {\r\n id: profile.id,\r\n reference: profile.reference,\r\n subject: profile.subject,\r\n thisProfileLink: profileCommentaryApiLink(\r\n commentary.id,\r\n profile.id,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n referenceChapterLink: profile.reference\r\n ? bookCommentaryChapterApiLink(\r\n commentary.id,\r\n profile.reference.book,\r\n profile.reference.chapter,\r\n 'json',\r\n apiPathPrefix\r\n )\r\n : null,\r\n };\r\n\r\n const apiProfileContent: ApiCommentaryProfileContent = {\r\n commentary: apiCommentary,\r\n profile: apiProfile,\r\n content: profile.content,\r\n };\r\n\r\n apiCommentary.totalNumberOfProfiles += 1;\r\n commentaryProfiles.profiles.push(apiProfile);\r\n api.commentaryProfileContents.push(apiProfileContent);\r\n }\r\n }\r\n\r\n for (let i = 0; i < commentaryChapters.length; i++) {\r\n if (i > 0) {\r\n commentaryChapters[i].previousChapterApiLink =\r\n bookCommentaryChapterApiLink(\r\n commentary.id,\r\n getBookLink(commentaryChapters[i - 1].book),\r\n commentaryChapters[i - 1].chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n );\r\n // commentaryChapters[i].previousChapterAudioLinks =\r\n // commentaryChapters[i - 1].thisChapterAudioLinks;\r\n }\r\n\r\n if (i < commentaryChapters.length - 1) {\r\n commentaryChapters[i].nextChapterApiLink =\r\n bookCommentaryChapterApiLink(\r\n commentary.id,\r\n getBookLink(commentaryChapters[i + 1].book),\r\n commentaryChapters[i + 1].chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n );\r\n // commentaryChapters[i].nextChapterAudioLinks =\r\n // commentaryChapters[i + 1].thisChapterAudioLinks;\r\n }\r\n }\r\n\r\n api.availableCommentaries.commentaries.push(apiCommentary);\r\n api.commentaryBooks.push(commentaryBooks);\r\n api.commentaryProfiles.push(commentaryProfiles);\r\n }\r\n\r\n return api;\r\n\r\n function getBookLink(book: TranslationBook | CommentaryBook): string {\r\n return useCommonName ? book.commonName : book.id;\r\n }\r\n}\r\n\r\n/**\r\n * Generates the output files for the given API.\r\n * @param api The API that the files should be generated for.\r\n */\r\nexport function generateFilesForApi(api: ApiOutput): OutputFile[] {\r\n let files: OutputFile[] = [];\r\n\r\n files.push(\r\n jsonFile(\r\n `${api.pathPrefix}/api/available_translations.json`,\r\n api.availableTranslations,\r\n true\r\n )\r\n );\r\n for (let translationBooks of api.translationBooks) {\r\n files.push(\r\n jsonFile(\r\n translationBooks.translation.listOfBooksApiLink,\r\n translationBooks\r\n )\r\n );\r\n }\r\n\r\n for (let bookChapter of api.translationBookChapters) {\r\n files.push(jsonFile(bookChapter.thisChapterLink, bookChapter));\r\n }\r\n\r\n for (let audio of api.translationBookChapterAudio) {\r\n files.push(downloadedFile(audio.link, audio.originalUrl));\r\n }\r\n\r\n files.push(\r\n jsonFile(\r\n `${api.pathPrefix}/api/available_commentaries.json`,\r\n api.availableCommentaries,\r\n true\r\n )\r\n );\r\n for (let commentaryBooks of api.commentaryBooks) {\r\n files.push(\r\n jsonFile(\r\n commentaryBooks.commentary.listOfBooksApiLink,\r\n commentaryBooks\r\n )\r\n );\r\n }\r\n\r\n for (let commentaryProfiles of api.commentaryProfiles) {\r\n files.push(\r\n jsonFile(\r\n commentaryProfiles.commentary.listOfProfilesApiLink,\r\n commentaryProfiles\r\n )\r\n );\r\n }\r\n\r\n for (let profileContent of api.commentaryProfileContents) {\r\n files.push(\r\n jsonFile(profileContent.profile.thisProfileLink, profileContent)\r\n );\r\n }\r\n\r\n for (let bookChapter of api.commentaryBookChapters) {\r\n files.push(jsonFile(bookChapter.thisChapterLink, bookChapter));\r\n }\r\n\r\n // for (let audio of api.translationBookChapterAudio) {\r\n // files.push(downloadedFile(audio.link, audio.originalUrl));\r\n // }\r\n\r\n return files;\r\n}\r\n\r\n/**\r\n * Generates the output files for the given datasets.\r\n * @param datasets The datasets to generate the output files for.\r\n * @param options The options for generating the API files.\r\n */\r\nexport async function* generateOutputFilesFromDatasets(\r\n datasets: AsyncIterable<DatasetOutput>,\r\n options?: GenerateApiOptions\r\n): AsyncGenerator<OutputFile[]> {\r\n for await (let dataset of datasets) {\r\n const api = generateApiForDataset(dataset, options);\r\n const files = generateFilesForApi(api);\r\n\r\n yield files;\r\n }\r\n}\r\n\r\n/**\r\n * Gets the API Link for the list of books endpoint for a translation.\r\n * @param translationId The ID of the translation.\r\n * @returns\r\n */\r\nexport function listOfBooksApiLink(\r\n translationId: string,\r\n prefix: string = ''\r\n): string {\r\n return `${prefix}/api/${translationId}/books.json`;\r\n}\r\n\r\n/**\r\n * Gets the API Link for the list of books endpoint for a commentary.\r\n * @param commentaryId The ID of the commentary.\r\n * @returns\r\n */\r\nexport function listOfCommentaryBooksApiLink(\r\n commentaryId: string,\r\n prefix: string = ''\r\n): string {\r\n return `${prefix}/api/c/${commentaryId}/books.json`;\r\n}\r\n\r\n/**\r\n * Getes the API link for a book chapter.\r\n * @param translationId The ID of the translation.\r\n * @param commonName The name of the book.\r\n * @param chapterNumber The number of the book.\r\n * @param extension The extension of the file.\r\n */\r\nexport function bookChapterApiLink(\r\n translationId: string,\r\n commonName: string,\r\n chapterNumber: number,\r\n extension: string,\r\n prefix: string = ''\r\n) {\r\n return `${prefix}/api/${translationId}/${replaceSpacesWithUnderscores(\r\n commonName\r\n )}/${chapterNumber}.${extension}`;\r\n}\r\n\r\n/**\r\n * Getes the API link for a book chapter.\r\n * @param translationId The ID of the translation.\r\n * @param commonName The name of the book.\r\n * @param chapterNumber The number of the book.\r\n * @param extension The extension of the file.\r\n */\r\nexport function bookCommentaryChapterApiLink(\r\n translationId: string,\r\n commonName: string,\r\n chapterNumber: number,\r\n extension: string,\r\n prefix: string = ''\r\n) {\r\n return `${prefix}/api/c/${translationId}/${replaceSpacesWithUnderscores(\r\n commonName\r\n )}/${chapterNumber}.${extension}`;\r\n}\r\n\r\nexport function bookChapterAudioApiLink(\r\n translationId: string,\r\n bookId: string,\r\n chapterNumber: number,\r\n reader: string,\r\n prefix: string = ''\r\n) {\r\n return `${prefix}/api/${translationId}/${replaceSpacesWithUnderscores(\r\n bookId\r\n )}/${chapterNumber}.${reader}.mp3`;\r\n}\r\n\r\n/**\r\n * Gets the API link for a profile.\r\n * @param translationId The ID of the translation.\r\n * @param profileId The ID of the profile.\r\n * @param extension The extension of the file.\r\n */\r\nexport function profilesCommentaryApiLink(\r\n translationId: string,\r\n extension: string,\r\n prefix: string = ''\r\n) {\r\n return `${prefix}/api/c/${translationId}/profiles.${extension}`;\r\n}\r\n\r\n/**\r\n * Gets the API link for a profile.\r\n * @param translationId The ID of the translation.\r\n * @param profileId The ID of the profile.\r\n * @param extension The extension of the file.\r\n */\r\nexport function profileCommentaryApiLink(\r\n translationId: string,\r\n profileId: string,\r\n extension: string,\r\n prefix: string = ''\r\n) {\r\n return `${prefix}/api/c/${translationId}/profiles/${replaceSpacesWithUnderscores(\r\n profileId\r\n )}.${extension}`;\r\n}\r\n\r\nexport function jsonFile(\r\n path: string,\r\n content: any,\r\n mergable?: boolean\r\n): OutputFile {\r\n return {\r\n path,\r\n content,\r\n mergable,\r\n };\r\n}\r\n\r\nexport function downloadedFile(path: string, url: string): OutputFile {\r\n return {\r\n path,\r\n content: () => fetch(url).then((response) => response.body),\r\n };\r\n}\r\n\r\nexport function replaceSpacesWithUnderscores(str: string): string {\r\n return str.replace(/[<>:\"/\\\\|?*\\s]/g, '_');\r\n}\r\n"],
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["import {\n Commentary,\n CommentaryBook,\n CommentaryBookChapter,\n CommentaryProfile,\n OutputFile,\n Translation,\n TranslationBook,\n TranslationBookChapter,\n TranslationBookChapterAudioLinks,\n} from './common-types.js';\nimport { DatasetOutput } from './dataset.js';\n\n/**\n * Defines the output of the API generation.\n */\nexport interface ApiOutput {\n /**\n * The list of available translations.\n * This maps to the /api/available-translations.json endpoint.\n */\n availableTranslations: ApiAvailableTranslations;\n\n /**\n * The list of books for each translation.\n * This maps to the /api/:translationId/books.json endpoint.\n */\n translationBooks: ApiTranslationBooks[];\n\n /**\n * The list of chapters for each book.\n * This maps to the following endpoints:\n * - /api/:translationId/:bookId/:chapterNumber.json\n * - /api/:translationId/:bookCommonName/:chapterNumber.json\n */\n translationBookChapters: ApiTranslationBookChapter[];\n\n /**\n * The list of audio files.\n * This maps to the following endpoints:\n * - /api/:translationId/:bookId/:chapterNumber.:reader.mp3\n */\n translationBookChapterAudio: ApiTranslationBookChapterAudio[];\n\n /**\n * The list of available commentaries.\n * This maps to the /api/available-commentaries.json endpoint.\n */\n availableCommentaries: ApiAvailableCommentaries;\n\n /**\n * The list of books for each commentary.\n * This maps to the /api/c/:commentaryId/books.json endpoint.\n */\n commentaryBooks: ApiCommentaryBooks[];\n\n /**\n * The list of profiles for each commentary.\n * This maps to the /api/c/:commentaryId/profiles.json endpoint.\n */\n commentaryProfiles: ApiCommentaryProfiles[];\n\n /**\n * The list of chapters for each commentary book.\n * This maps to the following endpoint:\n * - /api/c/:commentaryId/:bookId/:chapterNumber.json\n */\n commentaryBookChapters: ApiCommentaryBookChapter[];\n\n /**\n * The list of individual profiles for each commentary.\n * This maps to the following endpoint:\n * - /api/c/:commentaryId/profiles/:profileId.json\n */\n commentaryProfileContents: ApiCommentaryProfileContent[];\n\n /**\n * The path prefix that the API should use.\n */\n pathPrefix: string;\n}\n\n/**\n * The list of available translations.\n * Maps to the /api/available-translations.json endpoint.\n */\nexport interface ApiAvailableTranslations {\n /**\n * The list of translations.\n */\n translations: ApiTranslation[];\n}\n\n/**\n * The list of available commentaries.\n * Maps to the /api/available-commentaries.json endpoint.\n */\nexport interface ApiAvailableCommentaries {\n /**\n * The list of commentaries.\n */\n commentaries: ApiCommentary[];\n}\n\n/**\n * Defines a translation that is used in the API.\n */\nexport interface ApiTranslation extends Translation {\n /**\n * The API link for the list of available books for this translation.\n */\n listOfBooksApiLink: string;\n\n /**\n * The available list of formats.\n */\n availableFormats: ('json' | 'usfm')[];\n\n /**\n * The number of books that are contained in this translation.\n *\n * Complete translations should have the same number of books as the Bible (66).\n */\n numberOfBooks: number;\n\n /**\n * The total number of chapters that are contained in this translation.\n *\n * Complete translations should have the same number of chapters as the Bible (1,189).\n */\n totalNumberOfChapters: number;\n\n /**\n * The total number of verses that are contained in this translation.\n *\n * Complete translations should have the same number of verses as the Bible (around 31,102 - some translations exclude verses based on the aparent likelyhood of existing in the original source texts).\n */\n totalNumberOfVerses: number;\n\n /**\n * The total number of apocryphal books that are contained in this translation.\n */\n numberOfApocryphalBooks?: number;\n\n /**\n * The total number of apocryphal chapters that are contained in this translation.\n */\n totalNumberOfApocryphalChapters?: number;\n\n /**\n * the total number of apocryphal verses that are contained in this translation.\n */\n totalNumberOfApocryphalVerses?: number;\n\n /**\n * Gets the name of the language that the translation is in.\n * Null or undefined if the name of the language is not known.\n */\n languageName?: string;\n\n /**\n * Gets the name of the language in English.\n * Null or undefined if the language doesn't have an english name.\n */\n languageEnglishName?: string;\n}\n\n/**\n * Defines a commentary that is used in the API.\n */\nexport interface ApiCommentary extends Commentary {\n /**\n * The API link for the list of available books for this translation.\n */\n listOfBooksApiLink: string;\n\n /**\n * The API link for the list of available profiles for this commentary.\n */\n listOfProfilesApiLink: string;\n\n /**\n * The available list of formats.\n */\n availableFormats: ('json' | 'usfm')[];\n\n /**\n * The number of books that are contained in this commentary.\n *\n * Complete commentaries should have the same number of books as the Bible (66).\n */\n numberOfBooks: number;\n\n /**\n * The total number of chapters that are contained in this translation.\n *\n * Complete commentaries should have the same number of chapters as the Bible (1,189).\n */\n totalNumberOfChapters: number;\n\n /**\n * The total number of verses that are contained in this commentary.\n *\n * Complete commentaries should have the same number of verses as the Bible (around 31,102 - some commentaries exclude verses based on the aparent likelyhood of existing in the original source texts).\n */\n totalNumberOfVerses: number;\n\n /**\n * The total number of profiles that are contained in this commentary.\n *\n * Profiles are used to provide additional information about people and people groups that are mentioned in the Bible.\n */\n totalNumberOfProfiles: number;\n\n /**\n * Gets the name of the language that the commentary is in.\n * Null or undefined if the name of the language is not known.\n */\n languageName?: string;\n\n /**\n * Gets the name of the language in English.\n * Null or undefined if the language doesn't have an english name.\n */\n languageEnglishName?: string;\n}\n\n/**\n * Defines an interface that contains information about the books that are available for a translation.\n */\nexport interface ApiTranslationBooks {\n /**\n * The translation information for the books.\n */\n translation: ApiTranslation;\n\n /**\n * The list of books that are available for the translation.\n */\n books: ApiTranslationBook[];\n}\n\n/**\n * Defines an interface that contains information about the books that are available for a commentary.\n */\nexport interface ApiCommentaryBooks {\n /**\n * The commentary information for the books.\n */\n commentary: ApiCommentary;\n\n /**\n * The list of books that are available for the commentary.\n */\n books: ApiCommentaryBook[];\n}\n\n/**\n * Defines an interface that contains information about the profiles that are available for a commentary.\n */\nexport interface ApiCommentaryProfiles {\n /**\n * The commentary information for the books.\n */\n commentary: ApiCommentary;\n\n /**\n * The list of profiles that are available for the commentary.\n */\n profiles: ApiCommentaryProfile[];\n}\n\n/**\n * Defines an interface that contains information about a profile.\n */\nexport interface ApiCommentaryProfile extends CommentaryProfile {\n /**\n * The link to this profile.\n */\n thisProfileLink: string;\n\n /**\n * The link to the chapter that this profile references in the commentary.\n */\n referenceChapterLink: string | null;\n}\n\n/**\n * Defines a translation book that is used in the API.\n */\nexport interface ApiTranslationBook extends TranslationBook {\n /**\n * The link to the first chapter of the book.\n */\n firstChapterApiLink: string;\n\n /**\n * The link to the last chapter of the book.\n */\n lastChapterApiLink: string;\n\n /**\n * The number of chapters that the book contains.\n */\n numberOfChapters: number;\n\n /**\n * The number of verses that the book contains.\n */\n totalNumberOfVerses: number;\n}\n\n/**\n * Defines a commentary book that is used in the API.\n */\nexport interface ApiCommentaryBook extends CommentaryBook {\n /**\n * The link to the first chapter of the book.\n */\n firstChapterApiLink: string;\n\n /**\n * The link to the last chapter of the book.\n */\n lastChapterApiLink: string;\n\n /**\n * The number of chapters that the book contains.\n */\n numberOfChapters: number;\n\n /**\n * The number of verses that the book contains.\n */\n totalNumberOfVerses: number;\n}\n\n/**\n * Defines an interface that contains information about a book chapter.\n */\nexport interface ApiTranslationBookChapter extends TranslationBookChapter {\n /**\n * The translation information for the book chapter.\n */\n translation: ApiTranslation;\n\n /**\n * The book information for the book chapter.\n */\n book: ApiTranslationBook;\n\n /**\n * The link to this chapter.\n */\n thisChapterLink: string;\n\n /**\n * The link to the next chapter.\n * Null if this is the last chapter in the translation.\n */\n nextChapterApiLink: string | null;\n\n /**\n * The links to the audio versions for the next chapter.\n * Null if this is the last chapter in the translation.\n */\n nextChapterAudioLinks: TranslationBookChapterAudioLinks | null;\n\n /**\n * The link to the previous chapter.\n * Null if this is the first chapter in the translation.\n */\n previousChapterApiLink: string | null;\n\n /**\n * The links to the audio versions for the previous chapter.\n * Null if this is the first chapter in the translation.\n */\n previousChapterAudioLinks: TranslationBookChapterAudioLinks | null;\n\n /**\n * The number of verses that the chapter contains.\n */\n numberOfVerses: number;\n}\n\n/**\n * Defines an interface that contains information about a book chapter.\n */\nexport interface ApiCommentaryBookChapter extends CommentaryBookChapter {\n /**\n * The commentary information for the book chapter.\n */\n commentary: ApiCommentary;\n\n /**\n * The book information for the book chapter.\n */\n book: ApiCommentaryBook;\n\n /**\n * The link to this chapter.\n */\n thisChapterLink: string;\n\n /**\n * The link to the next chapter.\n * Null if this is the last chapter in the translation.\n */\n nextChapterApiLink: string | null;\n\n /**\n * The link to the previous chapter.\n * Null if this is the first chapter in the translation.\n */\n previousChapterApiLink: string | null;\n\n /**\n * The number of verses that the chapter contains.\n */\n numberOfVerses: number;\n}\n\nexport interface ApiTranslationBookChapterAudio {\n /**\n * The chapter that the audio is for.\n */\n chapter: ApiTranslationBookChapter;\n\n /**\n * The link that the audio should be placed at.\n */\n link: string;\n\n /**\n * The original URL of the audio.\n */\n originalUrl: string;\n}\n\nexport interface ApiCommentaryProfileContent {\n /**\n * The commentary information for the profile.\n */\n commentary: ApiCommentary;\n\n /**\n * The information about the profile.\n */\n profile: ApiCommentaryProfile;\n\n /**\n * The content of the profile.\n */\n content: string[];\n}\n\n/**\n * The options for generating the API.\n */\nexport interface GenerateApiOptions {\n /**\n * Whether to use the common name for the book chapter API link. If false, then book IDs are used.\n * Audio URLs will always use the book ID.\n * Defaults to false.\n */\n useCommonName?: boolean;\n\n /**\n * Whether to replace the audio URLs in the dataset with ones that are hosted locally.\n * If true, then the audio URLs in the dataset will be replaced with ones that reference files hosted by the API itself.\n * If false, then the audio URLs in the dataset will be left as is.\n * Defaults to false.\n */\n generateAudioFiles?: boolean;\n\n /**\n * Gets the english name of the given language.\n * If not provided, then the english name for the language will be unknown and omitted.\n * @param language The language to get the english name for.\n */\n getEnglishName?: (language: string) => string | null | undefined;\n\n /**\n * Gets the native name of the given language.\n * If not provided, then the native name for the language will be unknown and omitted.\n * @param language The language to get the native name for.\n */\n getNativeName?: (language: string) => string | null | undefined;\n\n /**\n * The prefix that should be added to paths that are generated.\n */\n pathPrefix?: string;\n}\n\n/**\n * Generates the API output for the given dataset.\n * @param dataset The dataset to generate the API for.\n * @param options The options for generating the API.\n */\nexport function generateApiForDataset(\n dataset: DatasetOutput,\n options: GenerateApiOptions = {}\n): ApiOutput {\n const { useCommonName, pathPrefix } = options;\n const apiPathPrefix = pathPrefix ? pathPrefix : '';\n let api: ApiOutput = {\n availableTranslations: {\n translations: [],\n },\n translationBooks: [],\n translationBookChapters: [],\n translationBookChapterAudio: [],\n availableCommentaries: {\n commentaries: [],\n },\n commentaryBookChapters: [],\n commentaryBooks: [],\n commentaryProfiles: [],\n commentaryProfileContents: [],\n pathPrefix: apiPathPrefix,\n };\n\n const getNativeName = options.getNativeName;\n const getEnglishName = options.getEnglishName;\n\n for (let { books, ...translation } of dataset.translations) {\n let numberOfBooks = 0;\n let numberOfApocryphalBooks = 0;\n\n for (let book of books) {\n if (book.isApocryphal) {\n numberOfApocryphalBooks++;\n } else {\n numberOfBooks++;\n }\n }\n\n const apiTranslation: ApiTranslation = {\n ...translation,\n availableFormats: ['json'],\n listOfBooksApiLink: listOfBooksApiLink(\n translation.id,\n apiPathPrefix\n ),\n numberOfBooks,\n totalNumberOfChapters: 0,\n totalNumberOfVerses: 0,\n languageName: getNativeName\n ? (getNativeName(translation.language) ?? undefined)\n : undefined,\n languageEnglishName: getEnglishName\n ? (getEnglishName(translation.language) ?? undefined)\n : undefined,\n };\n\n if (numberOfApocryphalBooks > 0) {\n apiTranslation.numberOfApocryphalBooks = numberOfApocryphalBooks;\n }\n\n const translationBooks: ApiTranslationBooks = {\n translation: apiTranslation,\n books: [],\n };\n\n let translationChapters: ApiTranslationBookChapter[] = [];\n\n for (let { chapters, ...book } of books) {\n const apiBook: ApiTranslationBook = {\n ...book,\n firstChapterApiLink: bookChapterApiLink(\n translation.id,\n getBookLink(book),\n 1,\n 'json',\n apiPathPrefix\n ),\n lastChapterApiLink: bookChapterApiLink(\n translation.id,\n getBookLink(book),\n chapters.length,\n 'json',\n apiPathPrefix\n ),\n numberOfChapters: chapters.length,\n totalNumberOfVerses: 0,\n };\n\n for (let { chapter, thisChapterAudioLinks } of chapters) {\n const audio: TranslationBookChapterAudioLinks = {};\n const apiBookChapter: ApiTranslationBookChapter = {\n translation: apiTranslation,\n book: apiBook,\n chapter: chapter,\n thisChapterLink: bookChapterApiLink(\n translation.id,\n getBookLink(book),\n chapter.number,\n 'json',\n apiPathPrefix\n ),\n thisChapterAudioLinks: audio,\n nextChapterApiLink: null,\n nextChapterAudioLinks: null,\n previousChapterApiLink: null,\n previousChapterAudioLinks: null,\n numberOfVerses: 0,\n };\n\n for (let reader in thisChapterAudioLinks) {\n if (options.generateAudioFiles) {\n const apiAudio: ApiTranslationBookChapterAudio = {\n chapter: apiBookChapter,\n link: bookChapterAudioApiLink(\n translation.id,\n getBookLink(book),\n chapter.number,\n reader,\n apiPathPrefix\n ),\n originalUrl: thisChapterAudioLinks[reader],\n };\n audio[reader] = apiAudio.link;\n api.translationBookChapterAudio.push(apiAudio);\n } else {\n audio[reader] = thisChapterAudioLinks[reader];\n }\n }\n\n for (let c of chapter.content) {\n if (c.type === 'verse') {\n apiBookChapter.numberOfVerses++;\n }\n }\n\n apiBook.totalNumberOfVerses += apiBookChapter.numberOfVerses;\n\n translationChapters.push(apiBookChapter);\n api.translationBookChapters.push(apiBookChapter);\n }\n\n translationBooks.books.push(apiBook);\n\n if (apiBook.isApocryphal) {\n if (!apiTranslation.totalNumberOfApocryphalChapters) {\n apiTranslation.totalNumberOfApocryphalChapters = 0;\n }\n if (!apiTranslation.totalNumberOfApocryphalVerses) {\n apiTranslation.totalNumberOfApocryphalVerses = 0;\n }\n apiTranslation.totalNumberOfApocryphalChapters +=\n apiBook.numberOfChapters;\n apiTranslation.totalNumberOfApocryphalVerses +=\n apiBook.totalNumberOfVerses;\n } else {\n apiTranslation.totalNumberOfChapters +=\n apiBook.numberOfChapters;\n apiTranslation.totalNumberOfVerses +=\n apiBook.totalNumberOfVerses;\n }\n }\n\n for (let i = 0; i < translationChapters.length; i++) {\n if (i > 0) {\n translationChapters[i].previousChapterApiLink =\n bookChapterApiLink(\n translation.id,\n getBookLink(translationChapters[i - 1].book),\n translationChapters[i - 1].chapter.number,\n 'json',\n apiPathPrefix\n );\n translationChapters[i].previousChapterAudioLinks =\n translationChapters[i - 1].thisChapterAudioLinks;\n }\n\n if (i < translationChapters.length - 1) {\n translationChapters[i].nextChapterApiLink = bookChapterApiLink(\n translation.id,\n getBookLink(translationChapters[i + 1].book),\n translationChapters[i + 1].chapter.number,\n 'json',\n apiPathPrefix\n );\n translationChapters[i].nextChapterAudioLinks =\n translationChapters[i + 1].thisChapterAudioLinks;\n }\n }\n\n api.availableTranslations.translations.push(apiTranslation);\n api.translationBooks.push(translationBooks);\n }\n\n for (let { books, profiles, ...commentary } of dataset.commentaries) {\n const apiCommentary: ApiCommentary = {\n ...commentary,\n availableFormats: ['json'],\n listOfBooksApiLink: listOfCommentaryBooksApiLink(\n commentary.id,\n apiPathPrefix\n ),\n listOfProfilesApiLink: profilesCommentaryApiLink(\n commentary.id,\n 'json',\n apiPathPrefix\n ),\n numberOfBooks: books.length,\n totalNumberOfChapters: 0,\n totalNumberOfVerses: 0,\n totalNumberOfProfiles: 0,\n languageName: getNativeName\n ? (getNativeName(commentary.language) ?? undefined)\n : undefined,\n languageEnglishName: getEnglishName\n ? (getEnglishName(commentary.language) ?? undefined)\n : undefined,\n };\n\n const commentaryBooks: ApiCommentaryBooks = {\n commentary: apiCommentary,\n books: [],\n };\n\n const commentaryProfiles: ApiCommentaryProfiles = {\n commentary: apiCommentary,\n profiles: [],\n };\n\n let commentaryChapters: ApiCommentaryBookChapter[] = [];\n\n for (let { chapters, ...book } of books) {\n const apiBook: ApiCommentaryBook = {\n ...book,\n firstChapterApiLink: bookCommentaryChapterApiLink(\n commentary.id,\n getBookLink(book),\n 1,\n 'json',\n apiPathPrefix\n ),\n lastChapterApiLink: bookCommentaryChapterApiLink(\n commentary.id,\n getBookLink(book),\n chapters.length,\n 'json',\n apiPathPrefix\n ),\n numberOfChapters: chapters.length,\n totalNumberOfVerses: 0,\n };\n\n for (let { chapter } of chapters) {\n const apiBookChapter: ApiCommentaryBookChapter = {\n commentary: apiCommentary,\n book: apiBook,\n chapter: chapter,\n thisChapterLink: bookCommentaryChapterApiLink(\n commentary.id,\n getBookLink(book),\n chapter.number,\n 'json',\n apiPathPrefix\n ),\n nextChapterApiLink: null,\n previousChapterApiLink: null,\n numberOfVerses: 0,\n };\n\n for (let c of chapter.content) {\n if (c.type === 'verse') {\n apiBookChapter.numberOfVerses++;\n }\n }\n\n apiBook.totalNumberOfVerses += apiBookChapter.numberOfVerses;\n\n commentaryChapters.push(apiBookChapter);\n api.commentaryBookChapters.push(apiBookChapter);\n }\n\n commentaryBooks.books.push(apiBook);\n\n apiCommentary.totalNumberOfChapters += apiBook.numberOfChapters;\n apiCommentary.totalNumberOfVerses += apiBook.totalNumberOfVerses;\n }\n\n if (profiles) {\n for (let profile of profiles) {\n const apiProfile: ApiCommentaryProfile = {\n id: profile.id,\n reference: profile.reference,\n subject: profile.subject,\n thisProfileLink: profileCommentaryApiLink(\n commentary.id,\n profile.id,\n 'json',\n apiPathPrefix\n ),\n referenceChapterLink: profile.reference\n ? bookCommentaryChapterApiLink(\n commentary.id,\n profile.reference.book,\n profile.reference.chapter,\n 'json',\n apiPathPrefix\n )\n : null,\n };\n\n const apiProfileContent: ApiCommentaryProfileContent = {\n commentary: apiCommentary,\n profile: apiProfile,\n content: profile.content,\n };\n\n apiCommentary.totalNumberOfProfiles += 1;\n commentaryProfiles.profiles.push(apiProfile);\n api.commentaryProfileContents.push(apiProfileContent);\n }\n }\n\n for (let i = 0; i < commentaryChapters.length; i++) {\n if (i > 0) {\n commentaryChapters[i].previousChapterApiLink =\n bookCommentaryChapterApiLink(\n commentary.id,\n getBookLink(commentaryChapters[i - 1].book),\n commentaryChapters[i - 1].chapter.number,\n 'json',\n apiPathPrefix\n );\n // commentaryChapters[i].previousChapterAudioLinks =\n // commentaryChapters[i - 1].thisChapterAudioLinks;\n }\n\n if (i < commentaryChapters.length - 1) {\n commentaryChapters[i].nextChapterApiLink =\n bookCommentaryChapterApiLink(\n commentary.id,\n getBookLink(commentaryChapters[i + 1].book),\n commentaryChapters[i + 1].chapter.number,\n 'json',\n apiPathPrefix\n );\n // commentaryChapters[i].nextChapterAudioLinks =\n // commentaryChapters[i + 1].thisChapterAudioLinks;\n }\n }\n\n api.availableCommentaries.commentaries.push(apiCommentary);\n api.commentaryBooks.push(commentaryBooks);\n api.commentaryProfiles.push(commentaryProfiles);\n }\n\n return api;\n\n function getBookLink(book: TranslationBook | CommentaryBook): string {\n return useCommonName ? book.commonName : book.id;\n }\n}\n\n/**\n * Generates the output files for the given API.\n * @param api The API that the files should be generated for.\n */\nexport function generateFilesForApi(api: ApiOutput): OutputFile[] {\n let files: OutputFile[] = [];\n\n files.push(\n jsonFile(\n `${api.pathPrefix}/api/available_translations.json`,\n api.availableTranslations,\n true\n )\n );\n for (let translationBooks of api.translationBooks) {\n files.push(\n jsonFile(\n translationBooks.translation.listOfBooksApiLink,\n translationBooks\n )\n );\n }\n\n for (let bookChapter of api.translationBookChapters) {\n files.push(jsonFile(bookChapter.thisChapterLink, bookChapter));\n }\n\n for (let audio of api.translationBookChapterAudio) {\n files.push(downloadedFile(audio.link, audio.originalUrl));\n }\n\n files.push(\n jsonFile(\n `${api.pathPrefix}/api/available_commentaries.json`,\n api.availableCommentaries,\n true\n )\n );\n for (let commentaryBooks of api.commentaryBooks) {\n files.push(\n jsonFile(\n commentaryBooks.commentary.listOfBooksApiLink,\n commentaryBooks\n )\n );\n }\n\n for (let commentaryProfiles of api.commentaryProfiles) {\n files.push(\n jsonFile(\n commentaryProfiles.commentary.listOfProfilesApiLink,\n commentaryProfiles\n )\n );\n }\n\n for (let profileContent of api.commentaryProfileContents) {\n files.push(\n jsonFile(profileContent.profile.thisProfileLink, profileContent)\n );\n }\n\n for (let bookChapter of api.commentaryBookChapters) {\n files.push(jsonFile(bookChapter.thisChapterLink, bookChapter));\n }\n\n // for (let audio of api.translationBookChapterAudio) {\n // files.push(downloadedFile(audio.link, audio.originalUrl));\n // }\n\n return files;\n}\n\n/**\n * Generates the output files for the given datasets.\n * @param datasets The datasets to generate the output files for.\n * @param options The options for generating the API files.\n */\nexport async function* generateOutputFilesFromDatasets(\n datasets: AsyncIterable<DatasetOutput>,\n options?: GenerateApiOptions\n): AsyncGenerator<OutputFile[]> {\n for await (let dataset of datasets) {\n const api = generateApiForDataset(dataset, options);\n const files = generateFilesForApi(api);\n\n yield files;\n }\n}\n\n/**\n * Gets the API Link for the list of books endpoint for a translation.\n * @param translationId The ID of the translation.\n * @returns\n */\nexport function listOfBooksApiLink(\n translationId: string,\n prefix: string = ''\n): string {\n return `${prefix}/api/${translationId}/books.json`;\n}\n\n/**\n * Gets the API Link for the list of books endpoint for a commentary.\n * @param commentaryId The ID of the commentary.\n * @returns\n */\nexport function listOfCommentaryBooksApiLink(\n commentaryId: string,\n prefix: string = ''\n): string {\n return `${prefix}/api/c/${commentaryId}/books.json`;\n}\n\n/**\n * Getes the API link for a book chapter.\n * @param translationId The ID of the translation.\n * @param commonName The name of the book.\n * @param chapterNumber The number of the book.\n * @param extension The extension of the file.\n */\nexport function bookChapterApiLink(\n translationId: string,\n commonName: string,\n chapterNumber: number,\n extension: string,\n prefix: string = ''\n) {\n return `${prefix}/api/${translationId}/${replaceSpacesWithUnderscores(\n commonName\n )}/${chapterNumber}.${extension}`;\n}\n\n/**\n * Getes the API link for a book chapter.\n * @param translationId The ID of the translation.\n * @param commonName The name of the book.\n * @param chapterNumber The number of the book.\n * @param extension The extension of the file.\n */\nexport function bookCommentaryChapterApiLink(\n translationId: string,\n commonName: string,\n chapterNumber: number,\n extension: string,\n prefix: string = ''\n) {\n return `${prefix}/api/c/${translationId}/${replaceSpacesWithUnderscores(\n commonName\n )}/${chapterNumber}.${extension}`;\n}\n\nexport function bookChapterAudioApiLink(\n translationId: string,\n bookId: string,\n chapterNumber: number,\n reader: string,\n prefix: string = ''\n) {\n return `${prefix}/api/${translationId}/${replaceSpacesWithUnderscores(\n bookId\n )}/${chapterNumber}.${reader}.mp3`;\n}\n\n/**\n * Gets the API link for a profile.\n * @param translationId The ID of the translation.\n * @param profileId The ID of the profile.\n * @param extension The extension of the file.\n */\nexport function profilesCommentaryApiLink(\n translationId: string,\n extension: string,\n prefix: string = ''\n) {\n return `${prefix}/api/c/${translationId}/profiles.${extension}`;\n}\n\n/**\n * Gets the API link for a profile.\n * @param translationId The ID of the translation.\n * @param profileId The ID of the profile.\n * @param extension The extension of the file.\n */\nexport function profileCommentaryApiLink(\n translationId: string,\n profileId: string,\n extension: string,\n prefix: string = ''\n) {\n return `${prefix}/api/c/${translationId}/profiles/${replaceSpacesWithUnderscores(\n profileId\n )}.${extension}`;\n}\n\nexport function jsonFile(\n path: string,\n content: any,\n mergable?: boolean\n): OutputFile {\n return {\n path,\n content,\n mergable,\n };\n}\n\nexport function downloadedFile(path: string, url: string): OutputFile {\n return {\n path,\n content: () => fetch(url).then((response) => response.body),\n };\n}\n\nexport function replaceSpacesWithUnderscores(str: string): string {\n return str.replace(/[<>:\"/\\\\|?*\\s]/g, '_');\n}\n"],
|
|
5
|
+
"mappings": ";AAqfO,gBAAS,sBACZ,SACA,UAA8B,CAAC,GACtB;AACT,QAAM,EAAE,eAAe,WAAW,IA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AAA,EACJ;AACJ;AAEO,gBAAS,eAAe,MAAc,KAAyB;AAClE,SAAO;AAAA,IACH;AAAA,IACA,SAAS,MAAM,MAAM,GAAG,EAAE,KAAK,CAAC,aAAa,SAAS,IAAI;AAAA,EAC9D;AACJ;AAEO,gBAAS,6BAA6B,KAAqB;AAC9D,SAAO,IAAI,QAAQ,mBAAmB,GAAG;AAC7C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -10,7 +10,7 @@ const openBibleUrlGenerator = (translation, reader, postfix) => {
|
|
|
10
10
|
);
|
|
11
11
|
const chapterStr = padStart(chapter.toString(), 3, "0");
|
|
12
12
|
let link = `https://openbible.com/audio/${reader}/${translation}_${bookOrder}_${capitalize(
|
|
13
|
-
bookId
|
|
13
|
+
bookId === "TIT" ? "TTS" : bookId
|
|
14
14
|
)}_${chapterStr}`;
|
|
15
15
|
if (postfix) {
|
|
16
16
|
link += `_${postfix}`;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../generation/audio.ts"],
|
|
4
|
-
"sourcesContent": ["import { padStart } from 'lodash';\
|
|
5
|
-
"mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAK7B,MAAM,wBAI8B,CAAC,aAAa,QAAQ,YAAY;AAClE,SAAO,CAAC,QAAQ,YAAY;AACxB,UAAM,YAAY;AAAA,MACd,aAAa,IAAI,MAAM,EAAG,SAAS;AAAA,MACnC;AAAA,MACA;AAAA,IACJ;AACA,UAAM,aAAa,SAAS,QAAQ,SAAS,GAAG,GAAG,GAAG;AAEtD,QAAI,OAAO,+BAA+B,MAAM,IAAI,WAAW,IAAI,SAAS,IAAI;AAAA,MAC5E;AAAA,
|
|
4
|
+
"sourcesContent": ["import { padStart } from 'lodash';\nimport { bookOrderMap } from './book-order.js';\nimport { TranslationBookChapterAudioLinks } from './common-types.js';\n\ntype AudioTranslationUrlGenerator = (bookId: string, chapter: number) => string;\n\nconst openBibleUrlGenerator: (\n translation: string,\n reader: string,\n postfix: string | null\n) => AudioTranslationUrlGenerator = (translation, reader, postfix) => {\n return (bookId, chapter) => {\n const bookOrder = padStart(\n bookOrderMap.get(bookId)!.toString(),\n 2,\n '0'\n );\n const chapterStr = padStart(chapter.toString(), 3, '0');\n\n let link = `https://openbible.com/audio/${reader}/${translation}_${bookOrder}_${capitalize(\n bookId === 'TIT' ? 'TTS' : bookId\n )}_${chapterStr}`;\n\n if (postfix) {\n link += `_${postfix}`;\n }\n\n link += '.mp3';\n\n return link;\n };\n};\n\n/**\n * A map of translation IDs to a map of reader IDs to the URL generator for the audio file.\n */\nexport const KNOWN_AUDIO_TRANSLATIONS: Map<\n string,\n Map<string, AudioTranslationUrlGenerator>\n> = new Map([\n [\n 'BSB',\n new Map([\n ['gilbert', openBibleUrlGenerator('BSB', 'gilbert', 'G')],\n ['hays', openBibleUrlGenerator('BSB', 'hays', 'H')],\n ['souer', openBibleUrlGenerator('BSB', 'souer', null)],\n ]),\n ],\n]);\n\n/**\n * Gets the audio URLs for the given translation, book, and chapter.\n * @param translationId The ID of the translation.\n * @param bookId The ID of the book.\n * @param chapter The number of the chapter.\n */\nexport function getAudioUrlsForChapter(\n translationId: string,\n bookId: string,\n chapter: number\n): TranslationBookChapterAudioLinks {\n const translation = KNOWN_AUDIO_TRANSLATIONS.get(translationId);\n if (!translation) {\n return {};\n }\n\n const links: TranslationBookChapterAudioLinks = {};\n for (let [reader, generator] of translation) {\n const url = generator(bookId, chapter);\n if (url) {\n links[reader] = url;\n }\n }\n return links;\n}\n\n/**\n * Capitalizes the first letter of the given string.\n * @param str The string to capitalize.\n */\nexport function capitalize(str: string): string {\n const char = str.charAt(0);\n if (/[0-9]/.test(char)) {\n return (\n str.charAt(0) +\n str.charAt(1).toUpperCase() +\n str.slice(2).toLowerCase()\n );\n }\n\n return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();\n}\n"],
|
|
5
|
+
"mappings": ";AAAA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