usfm-grammar-web 3.0.0-alpha.1

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/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2021 Bridge Connectivity Solutions
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # USFM Grammar
2
+
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.
5
+
6
+ ## Installation
7
+ You can install USFM Grammar via npm:
8
+
9
+ ```bash
10
+ npm install usfm-grammar
11
+ ```
12
+
13
+ ## Usage
14
+ Here's how you can use USFM Grammar in your JavaScript/TypeScript projects:
15
+
16
+ ```javascript
17
+ const { USFMParser} = require('usfm-grammar');
18
+
19
+ (async () => {
20
+ await USFMParser.init();
21
+ const usfmParser = new USFMParser()
22
+ const output = usfmParser.usfmToUsj('\\id GEN\n\\c 1\n\\p\n\\v 1 In the begining..\\v 2 more text')
23
+ console.log({ output })
24
+ const usfm = usfmParser.usjToUsfm(output)
25
+ console.log({ usfm })
26
+ })();
27
+ ```
28
+
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
+
36
+ If using from react, please refer the instructions for it [here](../docs/react-usage.md).
37
+
38
+ ## API Documentation
39
+
40
+ ### `USFMParser.init()`
41
+ Initializes the USFMParser. This function must be called before creating instances of `USFMParser`. And can take the grammar and the tree-sitter files (in wasm format) as arguments, that is included in the package.
42
+
43
+ ### `USFMParser.usfmToUsj(usfmString: string): Object`
44
+ Converts a USFM string to a USJ object.
45
+
46
+ - `usfmString`: The input USFM string.
47
+
48
+ Returns: A JSON-like object representing the USJ.
49
+
50
+ ### `USFMParser.usjToUsfm(usjObject: Object): string`
51
+ Converts a USJ object to a USFM string.
52
+
53
+ - `usjObject`: The input USJ object.
54
+
55
+ Returns: The converted USFM string.
56
+
57
+ ## Contributing
58
+ Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or create a pull request on [GitHub](https://github.com/your-username/usfm-grammar).
59
+
60
+ ## License
61
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.