UNPKG

twl-generator

Version:

Generate term-to-article lists from unfoldingWord en_tw archive for Bible books. Works in both Node.js (CLI) and React.js (browser) environments.

33 lines (28 loc) 1.25 kB
// Main module for twl-generator import { generateTWTerms } from './utils/zipProcessor.js'; import { processUsfmForBook, parseUsfmToVerses, removeAllTagsExceptChapterVerse } from './utils/usfm-alignment-remover.js'; import { generateTWLMatches } from './utils/twl-matcher.js'; export { generateTWTerms, processUsfmForBook }; /** * Main function that processes both TW articles and USFM file * @param {string} book - The book identifier (optional if usfmContent is provided) * @param {string} usfmContent - Optional USFM content to process instead of fetching * @return {Promise<string>} - TSV string */ export async function generateTWLWithUsfm(book, usfmContent = null) { // Generate TW terms (with caching) const terms = await generateTWTerms(); let verses; if (usfmContent) { // Parse provided USFM content (clean it first) const cleanUsfm = removeAllTagsExceptChapterVerse(usfmContent); verses = parseUsfmToVerses(cleanUsfm); } else { // Fetch USFM from git.door43.org if (!book) throw new Error('Book parameter required when no USFM content provided'); verses = await processUsfmForBook(book); } // Generate TWL matches and return TSV const tsv = generateTWLMatches(terms, verses); return tsv; }