twl-generator 1.2.11 → 1.2.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.
Files changed (2) hide show
  1. package/README.md +55 -103
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -11,143 +11,95 @@ Generate term-to-article lists from unfoldingWord en_tw archive for Bible books.
11
11
  - ✅ **Morphological Variants**: Handles plurals, possessives, verb forms
12
12
  - ✅ **Parentheses Normalization**: "Joseph (OT)" → "Joseph" for better coverage
13
13
 
14
+ ---
15
+
14
16
  ## Usage
15
17
 
16
- ### CLI (Node.js)
18
+ ### CLI
19
+
20
+ Install globally:
17
21
 
18
22
  ```bash
19
- # Install globally
20
23
  npm install -g twl-generator
21
-
22
- # Generate TSV for a Bible book
23
- twl-generator --book JHN --output john.tsv
24
-
25
- # Process local USFM file
26
- twl-generator --usfm my-file.usfm --output results.tsv
27
24
  ```
28
25
 
29
- ### React.js / Browser
30
-
31
- ```jsx
32
- import { generateTWTerms, getCacheInfo, clearCache } from 'twl-generator/src/utils/zipProcessor.js';
33
-
34
- function MyTWLComponent() {
35
- const [terms, setTerms] = useState(null);
36
- const [loading, setLoading] = useState(false);
37
-
38
- const loadTerms = async () => {
39
- setLoading(true);
40
- try {
41
- // First load: Downloads and processes (~3-4 seconds)
42
- // Subsequent loads: Uses browser cache (~instant)
43
- const termData = await generateTWTerms();
44
- setTerms(termData);
45
-
46
- // Debug cache info
47
- console.log('Cache info:', getCacheInfo());
48
- } catch (error) {
49
- console.error('Failed to load terms:', error);
50
- }
51
- setLoading(false);
52
- };
53
-
54
- const handleClearCache = async () => {
55
- await clearCache();
56
- console.log('Cache cleared - next load will download fresh data');
57
- };
58
-
59
- return (
60
- <div>
61
- {loading && <p>Loading translation words...</p>}
62
- <button onClick={() => loadTerms()}>Load Terms</button>
63
- <button onClick={handleClearCache}>Clear Cache</button>
64
- {terms && <p>Loaded {Object.keys(terms).length} terms</p>}
65
- </div>
66
- );
67
- }
68
- ```
69
-
70
- ### Node.js Module
26
+ Generate a TWL TSV for a Bible book (downloads USFM from Door43):
71
27
 
72
- ```js
73
- import { generateTWLWithUsfm } from 'twl-generator';
74
-
75
- const result = await generateTWLWithUsfm('RUT');
76
- console.log(result);
28
+ ```bash
29
+ twl-generator --book rut
77
30
  ```
78
31
 
79
- ## Browser Caching Strategy
80
-
81
- The package uses a multi-tier caching approach for optimal performance in React.js:
82
-
83
- 1. **Memory Cache**: Fastest access during current session
84
- 2. **localStorage**: Persistent across browser sessions
85
- 3. **sessionStorage**: Fallback for private browsing mode
86
- 4. **Auto-regeneration**: Downloads fresh data when cache is invalid
32
+ Generate a TWL TSV from a local USFM file:
87
33
 
88
- ### Cache Performance
89
-
90
- - **Cold start** (no cache): ~3-4 seconds
91
- - **Warm start** (browser cache): ~50-100ms
92
- - **Hot start** (memory cache): ~1-5ms
34
+ ```bash
35
+ twl-generator --usfm ./myfile.usfm
36
+ ```
93
37
 
94
- ## API Reference
38
+ Specify output file:
95
39
 
96
- ### `generateTWTerms()`
40
+ ```bash
41
+ twl-generator --usfm ./myfile.usfm --output ./output.tsv
42
+ ```
97
43
 
98
- Generate terms mapping with caching.
44
+ You can also combine `--book` and `--usfm` (book is used for output filename and context):
99
45
 
100
- - **Returns**: Promise<Object> - Term mapping object
46
+ ```bash
47
+ twl-generator --usfm ./myfile.usfm --book rut
48
+ ```
101
49
 
102
- ### `clearCache()`
50
+ ---
103
51
 
104
- Clear all caches and force fresh download on next call.
52
+ ### As a Library (Node.js/ESM/React)
105
53
 
106
- - **Returns**: Promise<boolean> - Success status
54
+ Install as a dependency:
107
55
 
108
- ### `getCacheInfo()`
56
+ ```bash
57
+ npm install twl-generator
58
+ ```
109
59
 
110
- Get cache status for debugging.
60
+ #### Example: Generate TWL TSV from USFM string
111
61
 
112
- - **Returns**: Object with cache details
62
+ ```js
63
+ import { generateTWLWithUsfm } from 'twl-generator';
113
64
 
114
- ## Installation
65
+ // USFM string (can be loaded from file, API, etc.)
66
+ const usfmContent = `
67
+ \\id MAT
68
+ \\c 1
69
+ \\v 1 In the beginning...
70
+ `;
115
71
 
116
- ```bash
117
- # Global installation (for CLI usage)
118
- npm install -g twl-generator
72
+ const book = 'mat'; // Book code (optional if USFM contains book info)
119
73
 
120
- # Local installation (for React.js projects)
121
- npm install twl-generator
74
+ const tsv = await generateTWLWithUsfm(book, usfmContent);
75
+ // tsv is a string in TSV format, ready to save or process
76
+ console.log(tsv);
122
77
  ```
123
78
 
124
- ## Supported Bible Books
79
+ #### Example: Generate TWL TSV by fetching USFM for a book
125
80
 
126
- All standard Bible book abbreviations are supported:
81
+ ```js
82
+ import { generateTWLWithUsfm } from 'twl-generator';
127
83
 
128
- **Old Testament**: GEN, EXO, LEV, NUM, DEU, JOS, JDG, RUT, 1SA, 2SA, 1KI, 2KI, 1CH, 2CH, EZR, NEH, EST, JOB, PSA, PRO, ECC, SNG, ISA, JER, LAM, EZK, DAN, HOS, JOL, AMO, OBA, JON, MIC, NAH, HAB, ZEP, HAG, ZEC, MAL
84
+ const book = 'rut'; // Book code
129
85
 
130
- **New Testament**: MAT, MRK, LUK, JHN, ACT, ROM, 1CO, 2CO, GAL, EPH, PHP, COL, 1TH, 2TH, 1TI, 2TI, TIT, PHM, HEB, JAS, 1PE, 2PE, 1JN, 2JN, 3JN, JUD, REV
86
+ const tsv = await generateTWLWithUsfm(book);
87
+ // This will fetch the USFM for the book from Door43 and return the TSV string
88
+ console.log(tsv);
89
+ ```
131
90
 
132
- ## Output Format
91
+ ---
133
92
 
134
- The generated TSV contains these columns:
93
+ ### API Reference
135
94
 
136
- - **Reference**: Chapter:verse (e.g., "1:1")
137
- - **ID**: Unique 4-character identifier
138
- - **Tags**: Article category ("keyterm", "name", or empty)
139
- - **OrigWords**: The matched text from the source
140
- - **Occurrence**: Occurrence number for this term in this verse
141
- - **TWLink**: Link to the translation words article
142
- - **Disambiguation**: Multiple article options (if applicable)
143
- - **Context**: Verse text with [matched term] in brackets
95
+ #### `generateTWLWithUsfm(book, usfmContent?)`
144
96
 
145
- ## Requirements
97
+ - `book`: (string) Book code (e.g., 'mat', 'rut'). Required if `usfmContent` is not provided.
98
+ - `usfmContent`: (string, optional) USFM file content. If provided, this is used instead of fetching from Door43.
99
+ - **Returns:** `Promise<string>` — TSV string of TWL matches.
146
100
 
147
- - **Node.js**: >=18.0.0 (for native fetch support)
148
- - **Browser**: Modern browser with ES6 modules support
149
- - **React.js**: >=16.8.0 (for React usage)
101
+ ---
150
102
 
151
103
  ## License
152
104
 
153
- MIT License - see LICENSE file for details.
105
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "twl-generator",
3
- "version": "1.2.11",
3
+ "version": "1.2.13",
4
4
  "description": "Generate term-to-article lists from unfoldingWord en_tw archive for Bible books. Works in both Node.js (CLI) and React.js (browser) environments.",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -22,15 +22,15 @@
22
22
  "unfoldingword",
23
23
  "translation-words"
24
24
  ],
25
- "author": "Rich Mahn <richmahn@example.com>",
25
+ "author": "Richard Mahn <rich.mahn@unfoldingword.org>",
26
26
  "license": "MIT",
27
- "homepage": "https://github.com/yourusername/twl-generator#readme",
27
+ "homepage": "https://github.com/unfoldingWord/node-twl-generator#readme",
28
28
  "repository": {
29
29
  "type": "git",
30
- "url": "git+https://github.com/yourusername/twl-generator.git"
30
+ "url": "git+https://github.com/unfoldingWord/node-twl-generator.git"
31
31
  },
32
32
  "bugs": {
33
- "url": "https://github.com/yourusername/twl-generator/issues"
33
+ "url": "https://github.com/unfoldingWord/node-twl-generator/issues"
34
34
  },
35
35
  "files": [
36
36
  "src/cli.js",