Debian Codegraph @

one-ini-wasm/README.md

raw symbols SCIP
1 # One INI
2
3 The core implementation of an AST based, idiomatic INI parser which aims to provide an easy to implement and consistent INI-standard.
4
5 This reference implementation is provided as Rust-library and WASM-package.
6
7 <!-- markdownlint-disable -->
8
9 [![GitHub Actions](https://github.com/jedmao/editorconfig-ini/workflows/Rust/badge.svg?event=push)](https://github.com/jedmao/editorconfig-ini/actions)
10
11 <!-- markdownlint-restore -->
12
13 <!-- markdownlint-disable commands-show-output -->
14
15 The work on this project started with the search for an universal parser for the [EditorConfig INI file format specification](https://spec.editorconfig.org/#file-format).
16
17 ## WASM
18
19 To use from [Web Assembly](https://webassembly.org/), compile with:
20
21 ```sh
22 wasm-pack build --release --target nodejs
23 ```
24
25 and run the (limited) WASM tests with:
26
27 ```sh
28 wasm-pack test --node
29 ```
30
31 You can call the generated JS wrapper with either:
32
33 ```js
34 import { parse_to_json } from './pkg/one_ini.js'
35
36 const results = parse_to_json(`
37 root = true
38
39 [*]
40 # always use unix line endings
41 end_of_line = lf
42 `)
43
44 // {
45 // "version": "0.1.0",
46 // "body": [
47 // { "type": "Pair", "key": "root", "value": "true" },
48 // {
49 // "type": "Section",
50 // "name": "*",
51 // "body": [
52 // { "type": "Comment", "indicator": "#", "value": "always use unix line endings" },
53 // { "type": "Pair", "key": "end_of_line", "value": "lf" }
54 // ]
55 // }
56 // ]
57 // }
58 ```
59
60 or:
61
62 ```js
63 import { parse_to_uint32array, TokenTypes } from './pkg/editorconfig_ini.js'
64 const buf = Buffer.from(`
65 root = true
66
67 [*]
68 # always use unix line endings
69 end_of_line = lf
70 `, 'utf8')
71 const ary = parse_to_uint32array(buf)
72
73 // Array with token type, start byte offset, end byte offset for each token
74 // Uint32Array(21) [
75 // TokenTypes.Key, 1, 5,
76 // TokenTypes.Value, 8, 12,
77 // TokenTypes.Section, 15, 16,
78 // TokenTypes.CommentIndicator, 18, 19,
79 // TokenTypes.CommentValue, 20, 48,
80 // TokenTypes.Key, 49, 60,
81 // TokenTypes.Value, 63, 65
82 // ]
83 ```