@helloao/tools 0.0.1 → 0.0.3
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/README.md +98 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
## Hello AO Tools
|
|
2
|
+
|
|
3
|
+
Tools for the [Free Use Bible API](https://bible.helloao.org).
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- Parse [USFM](https://ubsicap.github.io/usfm/), [USX](https://ubsicap.github.io/usx/), and Codex (JSON) files and understand some basic structure.
|
|
8
|
+
- Generate JSON from USFM, USX, and other formats.
|
|
9
|
+
|
|
10
|
+
### Installation
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
$ npm install @helloao/tools
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Usage
|
|
17
|
+
|
|
18
|
+
#### Parse a USX File
|
|
19
|
+
```typescript
|
|
20
|
+
import { parser } from '@helloao/tools';
|
|
21
|
+
// Used to parse XML
|
|
22
|
+
const parser = new DOMParser();
|
|
23
|
+
const usx = new parser.USXParser(parser);
|
|
24
|
+
const parseTree = usx.parse('YOUR USX');
|
|
25
|
+
console.log(parseTree);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
#### Generate the API Files for a translation
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { parser, generation } from '@helloao/tools';
|
|
32
|
+
|
|
33
|
+
// Used to parse XML
|
|
34
|
+
const domParser = new DOMParser();
|
|
35
|
+
|
|
36
|
+
// Each input file needs some metadata about the translation that it is associated with
|
|
37
|
+
const translation: generation.ParseTreeMetadata = {
|
|
38
|
+
translation: {
|
|
39
|
+
|
|
40
|
+
// The ID of the translation
|
|
41
|
+
// this should be unique for the translation
|
|
42
|
+
id: 'my translation id',
|
|
43
|
+
|
|
44
|
+
// The name of the translation in the translation's language
|
|
45
|
+
name: 'my translation name',
|
|
46
|
+
|
|
47
|
+
// The name of the translation in English
|
|
48
|
+
englishName: 'my translation name',
|
|
49
|
+
|
|
50
|
+
// The website that hosts information about the translation
|
|
51
|
+
website: 'translation website',
|
|
52
|
+
|
|
53
|
+
// The URL that hosts information about the license that the
|
|
54
|
+
// translation is shared under
|
|
55
|
+
licenseUrl: 'translation license',
|
|
56
|
+
|
|
57
|
+
// The ISO 639 letter language tag that the translation is primarily in.
|
|
58
|
+
language: 'eng',
|
|
59
|
+
|
|
60
|
+
// The direction that the text is written in.
|
|
61
|
+
// "ltr" means "left to right" and "rtl" means "right to left"
|
|
62
|
+
direction: 'ltr',
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// The list of files that should be processed.
|
|
67
|
+
const files: generation.InputFile[] = [
|
|
68
|
+
{
|
|
69
|
+
// the metadata about the translation for this file
|
|
70
|
+
metadata: translation,
|
|
71
|
+
|
|
72
|
+
// The content contained in the file
|
|
73
|
+
content: 'YOUR USX',
|
|
74
|
+
|
|
75
|
+
// The type of the file.
|
|
76
|
+
// One of "usx", "usfm", and "json"
|
|
77
|
+
fileType: 'usx'
|
|
78
|
+
}
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
// Generate a dataset from the files
|
|
82
|
+
// Datasets organize all the files and their content
|
|
83
|
+
// by translation, book, chapter, and verse
|
|
84
|
+
const dataset = generation.dataset.generateDataset(files, parser);
|
|
85
|
+
|
|
86
|
+
// Generate an API representation from the files
|
|
87
|
+
// This adds links between chapters and additional metadata.
|
|
88
|
+
const api = generation.api.generateApiForDataset(dataset);
|
|
89
|
+
|
|
90
|
+
// Generate output files from the API representation.
|
|
91
|
+
// This will give us a list of files and file paths that represent
|
|
92
|
+
// the entire API.
|
|
93
|
+
const outputFiles = generation.api.generateFilesForApi(api);
|
|
94
|
+
|
|
95
|
+
for (let file of outputFiles) {
|
|
96
|
+
console.log(file.path, file.content);
|
|
97
|
+
}
|
|
98
|
+
```
|