usfm3 0.1.0 → 0.1.4

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 ADDED
@@ -0,0 +1,81 @@
1
+ # usfm3
2
+
3
+ An error-tolerant [USFM 3.x](https://docs.usfm.bible/usfm/3.1.1/index.html) parser for JavaScript and TypeScript. Outputs [USJ](https://docs.usfm.bible/usfm/3.1.1/usj/index.html) (JSON), [USX](https://docs.usfm.bible/usfm/3.1.1/usx/index.html) (XML), and normalized USFM.
4
+
5
+ Built in Rust and compiled to WebAssembly. Works in browsers, Node.js, Deno, and Bun.
6
+
7
+ Also available as a [Rust crate](https://crates.io/crates/usfm3) and [Python package](https://pypi.org/project/usfm3/).
8
+
9
+ ## Installation
10
+
11
+ ```sh
12
+ npm install usfm3
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```typescript
18
+ import init, { parse } from "usfm3";
19
+
20
+ await init(); // load WASM (browser only — not needed in Node.js)
21
+
22
+ const result = parse(usfmText);
23
+
24
+ if (result.hasErrors()) {
25
+ console.error("Document has errors");
26
+ }
27
+
28
+ // Output formats (lazy — only serialized when called)
29
+ const usj = result.toUsj(); // plain JS object
30
+ const usx = result.toUsx(); // XML string
31
+ const usfm = result.toUsfm(); // USFM string
32
+
33
+ // Diagnostics
34
+ for (const d of result.diagnostics) {
35
+ console.log(`[${d.severity}] ${d.message} (${d.start}..${d.end})`);
36
+ // d.code is a machine-readable string like "UnknownMarker", "ImplicitClose", etc.
37
+ }
38
+
39
+ // Skip semantic validation
40
+ const result2 = parse(usfmText, { validate: false });
41
+
42
+ // Free WASM memory when done
43
+ result.free();
44
+ ```
45
+
46
+ ## API
47
+
48
+ ### `parse(usfm: string, options?: ParseOptions): ParseResult`
49
+
50
+ Parse a USFM string. Returns a `ParseResult` with lazy output methods and diagnostics.
51
+
52
+ **ParseOptions:**
53
+
54
+ | Field | Type | Default | Description |
55
+ |---|---|---|---|
56
+ | `validate` | `boolean` | `true` | Run semantic validation after parsing |
57
+
58
+ ### `ParseResult`
59
+
60
+ | Method / Property | Returns | Description |
61
+ |---|---|---|
62
+ | `toUsj()` | `object` | USJ (Unified Scripture JSON) |
63
+ | `toUsx()` | `string` | USX (Unified Scripture XML) |
64
+ | `toUsfm()` | `string` | Normalized USFM |
65
+ | `hasErrors()` | `boolean` | True if any error-severity diagnostics |
66
+ | `diagnostics` | `Diagnostic[]` | Parser and validation diagnostics |
67
+ | `free()` | `void` | Free WASM memory |
68
+
69
+ ### `Diagnostic`
70
+
71
+ | Property | Type | Description |
72
+ |---|---|---|
73
+ | `severity` | `string` | `"error"`, `"warning"`, or `"info"` |
74
+ | `code` | `string` | Machine-readable code (e.g. `"UnknownMarker"`) |
75
+ | `message` | `string` | Human-readable message |
76
+ | `start` | `number` | Start byte offset in source |
77
+ | `end` | `number` | End byte offset in source |
78
+
79
+ ## License
80
+
81
+ MIT
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "usfm3",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.1.4",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/jcuenod/usfm3"
8
+ },
5
9
  "files": [
6
10
  "usfm3_wasm_bg.wasm",
7
11
  "usfm3_wasm.js",
@@ -12,4 +16,4 @@
12
16
  "sideEffects": [
13
17
  "./snippets/*"
14
18
  ]
15
- }
19
+ }
Binary file