@helloao/tools 0.0.5 → 0.0.6-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +98 -98
- package/dist/cjs/generation/api.cjs +240 -0
- package/dist/cjs/generation/api.cjs.map +7 -0
- package/dist/cjs/generation/audio.cjs +83 -0
- package/dist/cjs/generation/audio.cjs.map +7 -0
- package/dist/cjs/generation/book-order.cjs +508 -0
- package/dist/cjs/generation/book-order.cjs.map +7 -0
- package/dist/cjs/generation/common-types.cjs +17 -0
- package/dist/cjs/generation/common-types.cjs.map +7 -0
- package/dist/cjs/generation/dataset.cjs +158 -0
- package/dist/cjs/generation/dataset.cjs.map +7 -0
- package/dist/cjs/generation/index.cjs +51 -0
- package/dist/cjs/generation/index.cjs.map +7 -0
- package/dist/cjs/index.cjs +45 -0
- package/dist/cjs/index.cjs.map +7 -0
- package/dist/cjs/parser/codex-parser.cjs +176 -0
- package/dist/cjs/parser/codex-parser.cjs.map +7 -0
- package/dist/cjs/parser/index.cjs +48 -0
- package/dist/cjs/parser/index.cjs.map +7 -0
- package/dist/cjs/parser/iterators.cjs +204 -0
- package/dist/cjs/parser/iterators.cjs.map +7 -0
- package/dist/cjs/parser/types.cjs +17 -0
- package/dist/cjs/parser/types.cjs.map +7 -0
- package/dist/cjs/parser/usfm-parser.cjs +791 -0
- package/dist/cjs/parser/usfm-parser.cjs.map +7 -0
- package/dist/cjs/parser/usx-parser.cjs +471 -0
- package/dist/cjs/parser/usx-parser.cjs.map +7 -0
- package/dist/cjs/utils.cjs +85 -0
- package/dist/cjs/utils.cjs.map +7 -0
- package/dist/esm/generation/api.js +198 -0
- package/dist/esm/generation/api.js.map +7 -0
- package/dist/esm/generation/audio.js +53 -0
- package/dist/esm/generation/audio.js.map +7 -0
- package/dist/esm/generation/book-order.js +478 -0
- package/dist/esm/generation/book-order.js.map +7 -0
- package/dist/esm/generation/common-types.js +2 -0
- package/dist/esm/generation/common-types.js.map +7 -0
- package/dist/esm/generation/dataset.js +132 -0
- package/dist/esm/generation/dataset.js.map +7 -0
- package/dist/esm/generation/index.js +8 -0
- package/dist/esm/generation/index.js.map +7 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/parser/codex-parser.js +144 -0
- package/dist/esm/parser/codex-parser.js.map +7 -0
- package/dist/esm/parser/index.js +8 -0
- package/dist/esm/parser/index.js.map +7 -0
- package/dist/esm/parser/iterators.js +152 -0
- package/dist/esm/parser/iterators.js.map +7 -0
- package/dist/esm/parser/types.js +2 -0
- package/dist/esm/parser/types.js.map +7 -0
- package/dist/esm/parser/usfm-parser.js +749 -0
- package/dist/esm/parser/usfm-parser.js.map +7 -0
- package/dist/esm/parser/usx-parser.js +447 -0
- package/dist/esm/parser/usx-parser.js.map +7 -0
- package/dist/esm/utils.js +51 -0
- package/dist/esm/utils.js.map +7 -0
- package/{generation → dist/types/generation}/api.d.ts +14 -2
- package/{generation → dist/types/generation}/audio.d.ts +1 -1
- package/{generation → dist/types/generation}/dataset.d.ts +1 -1
- package/dist/types/generation/index.d.ts +7 -0
- package/dist/types/index.d.ts +5 -0
- package/{parser → dist/types/parser}/codex-parser.d.ts +1 -1
- package/dist/types/parser/index.d.ts +7 -0
- package/{parser → dist/types/parser}/usfm-parser.d.ts +1 -1
- package/{parser → dist/types/parser}/usx-parser.d.ts +2 -2
- package/package.json +25 -4
- package/typings/types.d.ts +13 -13
- package/generation/api.js +0 -179
- package/generation/api.spec.d.ts +0 -2
- package/generation/api.spec.js +0 -656
- package/generation/audio.js +0 -60
- package/generation/audio.spec.d.ts +0 -2
- package/generation/audio.spec.js +0 -36
- package/generation/book-order.js +0 -494
- package/generation/book-order.spec.d.ts +0 -2
- package/generation/book-order.spec.js +0 -8
- package/generation/common-types.js +0 -2
- package/generation/dataset.js +0 -106
- package/generation/index.d.ts +0 -7
- package/generation/index.js +0 -38
- package/index.d.ts +0 -5
- package/index.js +0 -32
- package/parser/codex-parser.js +0 -160
- package/parser/codex-parser.spec.d.ts +0 -2
- package/parser/codex-parser.spec.js +0 -645
- package/parser/index.d.ts +0 -7
- package/parser/index.js +0 -35
- package/parser/iterators.js +0 -222
- package/parser/iterators.spec.d.ts +0 -2
- package/parser/iterators.spec.js +0 -174
- package/parser/types.js +0 -2
- package/parser/usfm-parser.js +0 -840
- package/parser/usfm-parser.spec.d.ts +0 -2
- package/parser/usfm-parser.spec.js +0 -1593
- package/parser/usx-parser.js +0 -425
- package/parser/usx-parser.spec.d.ts +0 -2
- package/parser/usx-parser.spec.js +0 -1260
- package/utils.js +0 -73
- package/utils.spec.d.ts +0 -2
- package/utils.spec.js +0 -42
- /package/{generation → dist/types/generation}/book-order.d.ts +0 -0
- /package/{generation → dist/types/generation}/common-types.d.ts +0 -0
- /package/{parser → dist/types/parser}/iterators.d.ts +0 -0
- /package/{parser → dist/types/parser}/types.d.ts +0 -0
- /package/{utils.d.ts → dist/types/utils.d.ts} +0 -0
package/generation/dataset.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateDataset = generateDataset;
|
|
4
|
-
const parser_1 = require("../parser");
|
|
5
|
-
const usx_parser_1 = require("../parser/usx-parser");
|
|
6
|
-
const book_order_1 = require("./book-order");
|
|
7
|
-
const lodash_1 = require("lodash");
|
|
8
|
-
const audio_1 = require("./audio");
|
|
9
|
-
const codex_parser_1 = require("../parser/codex-parser");
|
|
10
|
-
/**
|
|
11
|
-
* Generates a list of output files from the given list of input files.
|
|
12
|
-
* @param file The list of files.
|
|
13
|
-
*/
|
|
14
|
-
function generateDataset(files, parser = new globalThis.DOMParser()) {
|
|
15
|
-
let output = {
|
|
16
|
-
translations: [],
|
|
17
|
-
};
|
|
18
|
-
let usfmParser = new parser_1.UsfmParser();
|
|
19
|
-
let usxParser = new usx_parser_1.USXParser(parser);
|
|
20
|
-
let codexParser = new codex_parser_1.CodexParser();
|
|
21
|
-
let parsedTranslations = new Map();
|
|
22
|
-
const unknownLanguages = new Set();
|
|
23
|
-
for (let file of files) {
|
|
24
|
-
try {
|
|
25
|
-
let parser;
|
|
26
|
-
if (file.fileType === 'usfm') {
|
|
27
|
-
parser = usfmParser;
|
|
28
|
-
}
|
|
29
|
-
else if (file.fileType === 'usx') {
|
|
30
|
-
parser = usxParser;
|
|
31
|
-
}
|
|
32
|
-
else if (file.fileType === 'json') {
|
|
33
|
-
parser = codexParser;
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
console.warn('[generate] File does not have a valid type!', file.name);
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
const parsed = parser.parse(file.content);
|
|
40
|
-
const id = parsed.id;
|
|
41
|
-
if (!id) {
|
|
42
|
-
console.warn('[generate] File does not have a valid book ID!', file.name, id);
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
const order = book_order_1.bookOrderMap.get(id);
|
|
46
|
-
if (typeof order !== 'number') {
|
|
47
|
-
console.warn('[generate] Book does not have an order!', id);
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
const bookMap = book_order_1.bookIdMap.get(file.metadata.translation.language);
|
|
51
|
-
if (!bookMap) {
|
|
52
|
-
if (!unknownLanguages.has(file.metadata.translation.language)) {
|
|
53
|
-
console.warn('[generate] File does not have a known language!', file.name, file.metadata.translation.language);
|
|
54
|
-
unknownLanguages.add(file.metadata.translation.language);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const bookName = bookMap?.get(id);
|
|
58
|
-
if (!!bookMap && !bookName) {
|
|
59
|
-
console.warn('[generate] Book name not found for ID!', file.name, id);
|
|
60
|
-
}
|
|
61
|
-
let translation = parsedTranslations.get(file.metadata.translation.id);
|
|
62
|
-
if (!translation) {
|
|
63
|
-
translation = {
|
|
64
|
-
...(0, lodash_1.omit)(file.metadata.translation, 'direction'),
|
|
65
|
-
textDirection: file.metadata.translation.direction,
|
|
66
|
-
books: []
|
|
67
|
-
};
|
|
68
|
-
output.translations.push(translation);
|
|
69
|
-
parsedTranslations.set(file.metadata.translation.id, translation);
|
|
70
|
-
}
|
|
71
|
-
const name = parsed.header ?? bookName?.commonName ?? parsed.title;
|
|
72
|
-
if (!name) {
|
|
73
|
-
console.warn('[generate] Book does not have a name!', file.name, id);
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
const commonName = bookName?.commonName ?? parsed.header ?? parsed.title ?? id;
|
|
77
|
-
const book = {
|
|
78
|
-
id: id,
|
|
79
|
-
name,
|
|
80
|
-
commonName,
|
|
81
|
-
title: parsed.title ?? null,
|
|
82
|
-
order,
|
|
83
|
-
chapters: [],
|
|
84
|
-
};
|
|
85
|
-
for (let content of parsed.content) {
|
|
86
|
-
if (content.type === 'chapter') {
|
|
87
|
-
book.chapters.push({
|
|
88
|
-
chapter: {
|
|
89
|
-
number: content.number,
|
|
90
|
-
content: content.content,
|
|
91
|
-
footnotes: content.footnotes
|
|
92
|
-
},
|
|
93
|
-
thisChapterAudioLinks: (0, audio_1.getAudioUrlsForChapter)(translation.id, id, content.number)
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
book.chapters = (0, lodash_1.sortBy)(book.chapters, c => c.chapter.number);
|
|
98
|
-
const index = (0, lodash_1.sortedIndexBy)(translation.books, book, b => b.order);
|
|
99
|
-
translation.books.splice(index, 0, book);
|
|
100
|
-
}
|
|
101
|
-
catch (err) {
|
|
102
|
-
console.error(`[generate] Error occurred while parsing ${file.name}`, err);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return output;
|
|
106
|
-
}
|
package/generation/index.d.ts
DELETED
package/generation/index.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.bookOrder = exports.dataset = exports.audio = exports.api = void 0;
|
|
30
|
-
const api = __importStar(require("./api"));
|
|
31
|
-
exports.api = api;
|
|
32
|
-
const audio = __importStar(require("./audio"));
|
|
33
|
-
exports.audio = audio;
|
|
34
|
-
const dataset = __importStar(require("./dataset"));
|
|
35
|
-
exports.dataset = dataset;
|
|
36
|
-
const bookOrder = __importStar(require("./book-order"));
|
|
37
|
-
exports.bookOrder = bookOrder;
|
|
38
|
-
__exportStar(require("./common-types"), exports);
|
package/index.d.ts
DELETED
package/index.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.parser = exports.generation = exports.utils = void 0;
|
|
27
|
-
const utils = __importStar(require("./utils"));
|
|
28
|
-
exports.utils = utils;
|
|
29
|
-
const generation = __importStar(require("./generation"));
|
|
30
|
-
exports.generation = generation;
|
|
31
|
-
const parser = __importStar(require("./parser"));
|
|
32
|
-
exports.parser = parser;
|
package/parser/codex-parser.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CodexParser = exports.codexSchema = exports.metadataSchema = exports.chapterHeadingSchema = void 0;
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
exports.chapterHeadingSchema = zod_1.z.object({
|
|
7
|
-
type: zod_1.z.literal('chapter-heading'),
|
|
8
|
-
data: zod_1.z.object({
|
|
9
|
-
chapter: zod_1.z.coerce.number().int(),
|
|
10
|
-
}),
|
|
11
|
-
});
|
|
12
|
-
exports.metadataSchema = zod_1.z.discriminatedUnion('type', [
|
|
13
|
-
exports.chapterHeadingSchema
|
|
14
|
-
]);
|
|
15
|
-
exports.codexSchema = zod_1.z.object({
|
|
16
|
-
cells: zod_1.z.array(zod_1.z.object({
|
|
17
|
-
// kind: z.number().int(),
|
|
18
|
-
language: zod_1.z.string(),
|
|
19
|
-
value: zod_1.z.string(),
|
|
20
|
-
metadata: zod_1.z.object({
|
|
21
|
-
type: zod_1.z.string()
|
|
22
|
-
}).passthrough().nullable().optional()
|
|
23
|
-
})),
|
|
24
|
-
});
|
|
25
|
-
/**
|
|
26
|
-
* Defines a parser for codex files.
|
|
27
|
-
*/
|
|
28
|
-
class CodexParser {
|
|
29
|
-
// TODO:
|
|
30
|
-
// /**
|
|
31
|
-
// * Whether to preserve markdown in the parsed content.
|
|
32
|
-
// */
|
|
33
|
-
// preserveMarkdown: boolean = true;
|
|
34
|
-
_noteCounter = 0;
|
|
35
|
-
/**
|
|
36
|
-
* Parses the specified USX content.
|
|
37
|
-
*
|
|
38
|
-
* @param usx The USX content to parse.
|
|
39
|
-
* @returns The parse tree that was generated.
|
|
40
|
-
*/
|
|
41
|
-
parse(codex) {
|
|
42
|
-
const json = JSON.parse(codex);
|
|
43
|
-
const data = exports.codexSchema.parse(json);
|
|
44
|
-
let root = {
|
|
45
|
-
type: 'root',
|
|
46
|
-
content: []
|
|
47
|
-
};
|
|
48
|
-
let chapters = new Map();
|
|
49
|
-
let lastChapter = null;
|
|
50
|
-
function addChapterContent(chapterNumber, content) {
|
|
51
|
-
let chapter = chapters.get(chapterNumber);
|
|
52
|
-
if (!chapter) {
|
|
53
|
-
chapter = {
|
|
54
|
-
type: 'chapter',
|
|
55
|
-
number: chapterNumber,
|
|
56
|
-
content: [],
|
|
57
|
-
footnotes: []
|
|
58
|
-
};
|
|
59
|
-
lastChapter = chapter;
|
|
60
|
-
chapters.set(chapterNumber, chapter);
|
|
61
|
-
}
|
|
62
|
-
chapter.content.push(...content);
|
|
63
|
-
}
|
|
64
|
-
function addReference(ref, content) {
|
|
65
|
-
addChapterContent(ref.chapter, [
|
|
66
|
-
{
|
|
67
|
-
type: 'verse',
|
|
68
|
-
number: ref.verse,
|
|
69
|
-
content: content
|
|
70
|
-
}
|
|
71
|
-
]);
|
|
72
|
-
}
|
|
73
|
-
for (let cell of data.cells) {
|
|
74
|
-
if (cell.language === 'scripture') {
|
|
75
|
-
const lines = cell.value.split('\n');
|
|
76
|
-
const references = lines.map(l => (0, utils_1.parseVerseReference)(l) ?? l);
|
|
77
|
-
let currentRef = null;
|
|
78
|
-
let content = [];
|
|
79
|
-
for (let i = 0; i < references.length; i++) {
|
|
80
|
-
const ref = references[i];
|
|
81
|
-
const nextRef = references[i + 1];
|
|
82
|
-
if (typeof ref === 'string') {
|
|
83
|
-
// continuation on existing verse
|
|
84
|
-
// or line break between verses
|
|
85
|
-
if (ref === '') {
|
|
86
|
-
// line break
|
|
87
|
-
if (typeof nextRef === 'object') {
|
|
88
|
-
// between verses
|
|
89
|
-
if (currentRef && currentRef.chapter === nextRef.chapter) {
|
|
90
|
-
// in same chapter
|
|
91
|
-
addChapterContent(currentRef.chapter, [
|
|
92
|
-
{
|
|
93
|
-
type: 'line_break',
|
|
94
|
-
}
|
|
95
|
-
]);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
// do nothing since line breaks between chapters are ignored
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
// inside verse
|
|
103
|
-
content.push({
|
|
104
|
-
lineBreak: true
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
else if (ref) {
|
|
109
|
-
content.push(ref);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
if (!root.id) {
|
|
114
|
-
root.id = ref.book;
|
|
115
|
-
}
|
|
116
|
-
// new verse
|
|
117
|
-
if (currentRef) {
|
|
118
|
-
// finish previous verse
|
|
119
|
-
currentRef = null;
|
|
120
|
-
content = [];
|
|
121
|
-
}
|
|
122
|
-
currentRef = ref;
|
|
123
|
-
if (ref.content) {
|
|
124
|
-
content.push(ref.content);
|
|
125
|
-
}
|
|
126
|
-
addReference(ref, content);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
else if (cell.language === 'markdown') {
|
|
131
|
-
if (cell.metadata) {
|
|
132
|
-
if (cell.metadata.type === 'chapter-heading') {
|
|
133
|
-
const metadata = exports.metadataSchema.parse(cell.metadata);
|
|
134
|
-
const chapter = metadata.data.chapter;
|
|
135
|
-
addChapterContent(chapter, [
|
|
136
|
-
{
|
|
137
|
-
type: 'heading',
|
|
138
|
-
content: [cell.value]
|
|
139
|
-
}
|
|
140
|
-
]);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
if (lastChapter) {
|
|
145
|
-
lastChapter.footnotes.push({
|
|
146
|
-
noteId: this._noteCounter++,
|
|
147
|
-
text: cell.value,
|
|
148
|
-
caller: null,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
for (let chapter of chapters.values()) {
|
|
155
|
-
root.content.push(chapter);
|
|
156
|
-
}
|
|
157
|
-
return root;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
exports.CodexParser = CodexParser;
|