twl-generator 1.1.4 → 1.2.0

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 CHANGED
@@ -134,7 +134,7 @@ All standard Bible book abbreviations are supported:
134
134
  The generated TSV contains these columns:
135
135
 
136
136
  - **Reference**: Chapter:verse (e.g., "1:1")
137
- - **ID**: Unique 4-character hex identifier
137
+ - **ID**: Unique 4-character identifier
138
138
  - **Tags**: Article category ("keyterm", "name", or empty)
139
139
  - **OrigWords**: The matched text from the source
140
140
  - **Occurrence**: Occurrence number for this term in this verse
@@ -144,7 +144,7 @@ The generated TSV contains these columns:
144
144
 
145
145
  ## Requirements
146
146
 
147
- - **Node.js**: >=16.0.0
147
+ - **Node.js**: >=18.0.0 (for native fetch support)
148
148
  - **Browser**: Modern browser with ES6 modules support
149
149
  - **React.js**: >=16.8.0 (for React usage)
150
150
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "twl-generator",
3
- "version": "1.1.4",
3
+ "version": "1.2.0",
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": {
@@ -43,11 +43,10 @@
43
43
  "LICENSE"
44
44
  ],
45
45
  "engines": {
46
- "node": ">=16.0.0"
46
+ "node": ">=18.0.0"
47
47
  },
48
48
  "dependencies": {
49
- "jszip": "^3.10.1",
50
- "node-fetch": "^3.3.2"
49
+ "jszip": "^3.10.1"
51
50
  },
52
51
  "peerDependencies": {
53
52
  "react": ">=16.8.0"
@@ -282,14 +282,14 @@ function findMatches(verseText, termTrie) {
282
282
  }
283
283
 
284
284
  /**
285
- * Generate a 4-character hex ID starting with a letter
285
+ * Generate a 4-character ID starting with a letter
286
286
  */
287
287
  function generateId() {
288
- const letters = 'abcdef';
289
- const hex = '0123456789abcdef';
288
+ const letters = 'abcdefghijklmnopqrstuvwxyz';
289
+ const lettersAndDigits = 'abcdefghijklmnopqrstuvwxyz0123456789';
290
290
  let id = letters[Math.floor(Math.random() * letters.length)];
291
291
  for (let i = 0; i < 3; i++) {
292
- id += hex[Math.floor(Math.random() * hex.length)];
292
+ id += lettersAndDigits[Math.floor(Math.random() * lettersAndDigits.length)];
293
293
  }
294
294
  return id;
295
295
  }
@@ -8,8 +8,16 @@ const isNode = typeof window === 'undefined' && typeof process !== 'undefined' &
8
8
  // Get appropriate fetch implementation
9
9
  async function getFetch() {
10
10
  if (isNode) {
11
- const nodeFetch = await import('node-fetch');
12
- return nodeFetch.default;
11
+ // Use native fetch in Node.js 18+ or fallback to node-fetch
12
+ if (typeof globalThis.fetch !== 'undefined') {
13
+ return globalThis.fetch;
14
+ }
15
+ try {
16
+ const nodeFetch = await import('node-fetch');
17
+ return nodeFetch.default;
18
+ } catch (error) {
19
+ throw new Error('fetch not available. Please use Node.js 18+ or install node-fetch');
20
+ }
13
21
  }
14
22
  return globalThis.fetch;
15
23
  }
@@ -31,10 +31,19 @@ async function getDeps() {
31
31
  JSZip: jsZipModule.default
32
32
  };
33
33
 
34
- // Add Node.js-specific fetch if needed
34
+ // Add Node.js-specific fetch if needed (fallback for Node.js < 18)
35
35
  if (isNode) {
36
- const nodeModule = await import('node-fetch');
37
- deps.fetch = nodeModule.default;
36
+ if (typeof globalThis.fetch === 'undefined') {
37
+ try {
38
+ const nodeModule = await import('node-fetch');
39
+ deps.fetch = nodeModule.default;
40
+ } catch (error) {
41
+ console.warn('node-fetch not available, please use Node.js 18+ or install node-fetch');
42
+ deps.fetch = null;
43
+ }
44
+ } else {
45
+ deps.fetch = globalThis.fetch;
46
+ }
38
47
  }
39
48
 
40
49
  return deps;