usfm-grammar-web 3.0.0-alpha.1 → 3.0.0-alpha.2

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
@@ -1,37 +1,74 @@
1
1
  # USFM Grammar
2
2
 
3
3
  ## Description
4
- USFM Grammar is a JavaScript library for parsing and converting USFM (Unified Standard Format Markers) to/from USJ (Unified Standard JSON) format. This library provides functionalities to parse USFM strings into a syntax tree and convert them into a JSON-like structure (USJ), and vice versa.
4
+ This is the web alternative to the (USFM-Grammar 3.x)[https://www.npmjs.com/package/usfm-grammar] library to be used from HTML, react etc. USFM Grammar is a JavaScript library for parsing and converting USFM (Unified Standard Format Markers) to/from USJ (Unified Standard JSON) format. This library provides functionalities to parse USFM strings into a syntax tree and convert them into a JSON-like structure (USJ), and vice versa.
5
5
 
6
6
  ## Installation
7
7
  You can install USFM Grammar via npm:
8
8
 
9
- ```bash
10
- npm install usfm-grammar
11
- ```
12
9
 
13
10
  ## Usage
14
- Here's how you can use USFM Grammar in your JavaScript/TypeScript projects:
11
+ Here's how you can use USFM Grammar in your react projects:
12
+ ```bash
13
+ npm install usfm-grammar-web
14
+ ```
15
15
 
16
16
  ```javascript
17
- const { USFMParser} = require('usfm-grammar');
17
+ import React, { useState, useEffect } from 'react';
18
+ import { USFMParser } from 'usfm-grammar-web';
19
+
20
+ function App() {
21
+ const [result, setResult] = useState(null);
22
+ const [result2, setResult2] = useState(null);
23
+
24
+ useEffect(() => {
25
+ const initParser = async () => {
26
+ await USFMParser.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.0.0-alpha.1/tree-sitter-usfm.wasm",
27
+ "https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.0.0-alpha.1/tree-sitter.wasm");
28
+ };
29
+ initParser();
30
+ }, []);
31
+
32
+ const calculateValue = async () => {
33
+ const usfmParser = new USFMParser();
34
+ const output = await usfmParser.usfmToUsj('\\id GEN\n\\c 1\n\\p\n\\v 1 In the begining..\\v 2 more text');
35
+ setResult(JSON.stringify(output));
36
+ const usfm = usfmParser.usjToUsfm(output);
37
+ setResult2(usfm);
38
+ };
39
+
40
+ return (
41
+ <div className="App">
42
+ <div>
43
+ <button onClick={calculateValue}>Test</button>
44
+ <p>USJ: {result}</p>
45
+ <p>USFM: {result2}</p>
46
+ </div>
47
+ </div>
48
+ );
49
+ }
50
+
51
+ export default App;
52
+ ```
18
53
 
19
- (async () => {
20
- await USFMParser.init();
54
+ It can be used directly in the HTML script tag too.
55
+
56
+ ```html
57
+ <script type="module">
58
+ import { USFMParser } from 'https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.0.0-alpha.2/dist/bundle.mjs';
59
+ console.log('Hello world');
60
+ (async () => {
61
+ await USFMParser.init("https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.0.0-alpha.2/tree-sitter-usfm.wasm",
62
+ "https://cdn.jsdelivr.net/npm/usfm-grammar-web@3.0.0-alpha.2/tree-sitter.wasm");
21
63
  const usfmParser = new USFMParser()
22
64
  const output = usfmParser.usfmToUsj('\\id GEN\n\\c 1\n\\p\n\\v 1 In the begining..\\v 2 more text')
23
65
  console.log({ output })
24
66
  const usfm = usfmParser.usjToUsfm(output)
25
67
  console.log({ usfm })
26
- })();
68
+ })();
69
+ </script>
27
70
  ```
28
71
 
29
- If the above import cause issue in an esm project use the below format:
30
- ```javascript
31
- import pkg from 'usfm-grammar';
32
- const USFMParser = pkg.USFMParser;
33
-
34
- ```
35
72
 
36
73
  If using from react, please refer the instructions for it [here](../docs/react-usage.md).
37
74
 
@@ -2510,4 +2510,4 @@ console.log("COmes in index.js");
2510
2510
 
2511
2511
 
2512
2512
  export {$236d01ba6f80be5e$export$2e2bcd8739ae039 as USFMParser};
2513
- //# sourceMappingURL=index.mjs.map
2513
+ //# sourceMappingURL=bundle.mjs.map