yini-parser 1.0.0-alpha.6 → 1.0.0-alpha.7x
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/CHANGELOG.md +13 -1
- package/README.md +309 -156
- package/dist/YINI.d.ts +27 -5
- package/dist/YINI.js +27 -5
- package/dist/core/ErrorDataHandler.js +28 -32
- package/dist/core/YINIVisitor.d.ts +2 -2
- package/dist/core/YINIVisitor.js +99 -5
- package/dist/grammar/YiniLexer.js +4 -1
- package/dist/grammar/YiniParser.d.ts +27 -3
- package/dist/grammar/YiniParser.js +544 -294
- package/dist/grammar/YiniParserVisitor.d.ts +14 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +34 -15
- package/dist/parsers/extractSignificantYiniLine.js +2 -0
- package/examples/basic-with-comments.yini +15 -0
- package/examples/basic.yini +11 -0
- package/examples/compare-formats.md +89 -0
- package/examples/nested.yini +26 -0
- package/examples/parse-example.ts +22 -0
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## --Upcoming-- -beta
|
|
4
|
+
- Package updated to **beta**. The core API is stabilizing, some more advanced features may still change.
|
|
5
|
+
- Implemented support for colon lists, both empty and with elements, including nested lists. Also updated to the latest grammar, which fixes handling of empty lists with or without spaces or tabs between the brackets.
|
|
6
|
+
- Optimized the top part of readme for npmjs Short Page.
|
|
7
|
+
- Added a dir `examples/` with a few example Yini files, `compare-formats.md` and TS file.
|
|
8
|
+
|
|
9
|
+
## 1.0.0-alpha.7
|
|
10
|
+
- Fixed serious bug that on error did exit process.
|
|
11
|
+
- Pached and updated JSDoc for remaing params for the functions parse(..) and parseFile(..).
|
|
12
|
+
- Changed the WIPs in the readme to "Planned – not yet implemented"-tag.
|
|
13
|
+
- Updated readme and especially "Intro to YINI Config Format".
|
|
14
|
+
|
|
3
15
|
## 1.0.0-alpha.6
|
|
4
16
|
- The YINI specificaiton discontinued alternative marker character `~` (visually ambiguous) in favor of `<`.
|
|
5
17
|
- The parser can now detect invalid . characters in identifiers (both keys and section names), allowing it to emit a clear error message to the user.
|
|
6
18
|
- Detect and emit error on defining already existing key or section name in a scope/section.
|
|
7
|
-
- Updated readme with "Intro to YINI Config Format" among other updates.
|
|
19
|
+
- Updated readme with "Intro to YINI Config Format" among other misc. updates.
|
|
8
20
|
|
|
9
21
|
## 1.0.0-alpha.5
|
|
10
22
|
- Readme updated with correct examples for CommonJS.
|
package/README.md
CHANGED
|
@@ -1,168 +1,101 @@
|
|
|
1
|
-
# YINI Parser
|
|
1
|
+
# YINI Parser for Node.js
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
> ⚠️ This package is in **alpha**. The API and features may change. Not all parts of the YINI specification are implemented yet.
|
|
6
|
-
|
|
7
|
-
**YINI Parser in TypeScript** — a runtime library for Node.js.
|
|
8
|
-
A parser / reader for the [YINI configuration file format](https://github.com/YINI-lang/YINI-spec).
|
|
9
|
-
|
|
10
|
-
This library implements the official YINI specification using TypeScript + ANTLR4.
|
|
11
|
-
|
|
12
|
-
YINI is a simple, human-friendly configuration format inspired by INI and JSON.
|
|
13
|
-
|
|
14
|
-
---
|
|
15
|
-
|
|
16
|
-
## Quick Start
|
|
17
|
-
|
|
18
|
-
A simple configuration:
|
|
19
|
-
```yini
|
|
20
|
-
^ App
|
|
21
|
-
name = 'My Title'
|
|
22
|
-
items = 25
|
|
23
|
-
enabled = true
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
That's it!
|
|
27
|
-
|
|
28
|
-
---
|
|
29
|
-
|
|
30
|
-
## 💡 Why YINI?
|
|
31
|
-
- **Easy to read and write**, minimal syntax, maximum clarity.
|
|
32
|
-
- **Clear section nesting** without painful indentation rules.
|
|
33
|
-
- **Supports strict/lenient modes**, and all major data types.
|
|
34
|
-
- A perfect alternative to messy JSON, legacy INI, or complex YAML.
|
|
35
|
-
- Built for both **JavaScript and TypeScript**.
|
|
36
|
-
- Both **human-friendly**, and **machine-friendly**.
|
|
37
|
-
|
|
38
|
-
## ✨ Features
|
|
39
|
-
- Simple syntax (supports both strict and lenient modes).
|
|
40
|
-
- Familiar config file style (inspired by INI, JSON, Python, and Markdown).
|
|
41
|
-
- Easy programmatic usage.
|
|
42
|
-
- Only the `YINI` class is exported; all internal details are private.
|
|
43
|
-
- --wip-- Supports alternative list notation (colon‑style lists):
|
|
44
|
-
```yini
|
|
45
|
-
fruits:
|
|
46
|
-
'Pear',
|
|
47
|
-
'Cherry',
|
|
48
|
-
'Banana'
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Limitations
|
|
52
|
-
Not all features of the full YINI are implemented yet.
|
|
3
|
+
YINI is a clean, minimal, and human-readable config format for structured configuration. This parser implements the YINI spec in TypeScript for Node.js, with support for nested sections, strict/lenient modes, and typed values.
|
|
53
4
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
---
|
|
57
|
-
|
|
58
|
-
## 🚀 Installation
|
|
5
|
+
[](https://www.npmjs.com/package/yini-parser) [](https://github.com/YINI-lang/yini-parser-typescript/actions/workflows/run-all-tests.yml)
|
|
59
6
|
|
|
60
|
-
With **npm**:
|
|
61
7
|
```sh
|
|
62
8
|
npm install yini-parser
|
|
63
9
|
```
|
|
64
10
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
With **pnpm**:
|
|
71
|
-
```sh
|
|
72
|
-
pnpm add yini-parser
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
---
|
|
76
|
-
|
|
77
|
-
## Usage
|
|
78
|
-
|
|
79
|
-
### Node.js (CommonJS)
|
|
80
|
-
**Note:** Only a default export (YINI) is provided. Named imports are not supported.
|
|
81
|
-
```js
|
|
82
|
-
const YINI = require('yini-parser');
|
|
83
|
-
// If you get undefined, try:
|
|
84
|
-
const YINI = require('yini-parser').default;
|
|
85
|
-
|
|
86
|
-
// Parse from string.
|
|
87
|
-
const config = YINI.parse(`
|
|
88
|
-
^ App
|
|
89
|
-
title = 'My App Title'
|
|
90
|
-
items = 25
|
|
91
|
-
isDarkTheme = true
|
|
92
|
-
`);
|
|
93
|
-
|
|
94
|
-
// Parse from file.
|
|
95
|
-
const configFromFile = YINI.parseFile('./config.yini');
|
|
11
|
+
```ts
|
|
12
|
+
import YINI from 'yini-parser'
|
|
13
|
+
const config = YINI.parseFile('./config.yini')
|
|
96
14
|
```
|
|
97
15
|
|
|
98
|
-
|
|
99
|
-
```ts
|
|
100
|
-
import YINI from 'yini-parser';
|
|
16
|
+
A clean, minimal, human-readable config format—designed as an alternative to INI, YAML, and JSON.
|
|
101
17
|
|
|
102
|
-
|
|
103
|
-
const config = YINI.parse(`
|
|
104
|
-
^ App
|
|
105
|
-
title = "My App Title"
|
|
106
|
-
items = 25
|
|
107
|
-
isDarkTheme = OFF
|
|
108
|
-
`);
|
|
18
|
+
➡️ See full [documentation or YINI format specification](https://github.com/YINI-lang/YINI-spec)
|
|
109
19
|
|
|
110
|
-
|
|
111
|
-
const configFromFile = YINI.parseFile('./config.yini');
|
|
112
|
-
```
|
|
20
|
+
⭐ **Enjoying YINI?** If you find this project useful, please consider [starring it on GitHub](https://github.com/YINI-lang/yini-parser-typescript) — it helps others discover it!
|
|
113
21
|
|
|
114
22
|
---
|
|
115
23
|
|
|
116
|
-
##
|
|
24
|
+
## YINI Parser – TypeScript
|
|
117
25
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
### `YINI.parse(yiniContent: string, strictMode?: boolean, bailSensitivity: 'auto' | 0 | 1 | 2 = "auto", includeMetaData = false): object`
|
|
121
|
-
|
|
122
|
-
Parses YINI code from a string.
|
|
26
|
+
> 🚧 This package is in **beta**. The core API is stabilizing, some more advanced features may still change. Feedback and bug reports are welcome!
|
|
123
27
|
|
|
124
|
-
**
|
|
125
|
-
|
|
126
|
-
- `strictMode`: (optional, default `false`) Parse in strict mode.
|
|
127
|
-
- `bailSensitivity`: (optional, default `"auto"`) Error tolerance level.
|
|
128
|
-
* If `bailSensitivity` is `"auto"` then bail sensitivity level will be set to 0 if in non-strict mode, if in strict mode then level 1 will be used automatically.
|
|
129
|
-
- `includeMetaData`: If true then additional meta data will be returned along the object.
|
|
28
|
+
**YINI Parser in TypeScript** — a runtime library for Node.js.
|
|
29
|
+
A parser / reader for the [YINI configuration file format](https://github.com/YINI-lang/YINI-spec).
|
|
130
30
|
|
|
131
|
-
|
|
132
|
-
- 0 = 'Ignore-Errors' // Don't bail on errors, persist and try to recover.
|
|
133
|
-
- 1 = 'Abort-on-Errors'
|
|
134
|
-
- 2 = 'Abort-Even-on-Warnings'
|
|
31
|
+
This library implements the official YINI specification using TypeScript + ANTLR4.
|
|
135
32
|
|
|
136
|
-
|
|
33
|
+
YINI is a simple, human-friendly configuration format inspired by INI and JSON.
|
|
137
34
|
|
|
138
|
-
|
|
35
|
+
---
|
|
139
36
|
|
|
140
|
-
|
|
141
|
-
- `filePath`: Path to the `.yini` file.
|
|
142
|
-
- Other parameters are the same as `parse(..)`.
|
|
37
|
+
## Quick Start
|
|
143
38
|
|
|
144
|
-
|
|
39
|
+
A minimal example using YINI in TypeScript:
|
|
40
|
+
```ts
|
|
41
|
+
import YINI from 'yini-parser'
|
|
145
42
|
|
|
146
|
-
|
|
43
|
+
const config = YINI.parse(`
|
|
44
|
+
^ App
|
|
45
|
+
name = 'My Title' // App display name.
|
|
46
|
+
items = 25
|
|
47
|
+
darkMode = true
|
|
48
|
+
|
|
49
|
+
// Sub-section of App.
|
|
50
|
+
^^ Special
|
|
51
|
+
primaryColor = #336699
|
|
52
|
+
isCaching = false
|
|
53
|
+
`)
|
|
54
|
+
|
|
55
|
+
// To parse from a file instead:
|
|
56
|
+
// const config = YINI.parseFile('./config.yini')
|
|
57
|
+
|
|
58
|
+
console.log(config.App.name) // My Title
|
|
59
|
+
console.log(config.App.Special.isCaching) // false
|
|
60
|
+
console.log()
|
|
61
|
+
console.log(config)
|
|
62
|
+
```
|
|
147
63
|
|
|
148
|
-
|
|
64
|
+
**Output:**
|
|
149
65
|
```js
|
|
150
|
-
|
|
66
|
+
My Title
|
|
67
|
+
false
|
|
68
|
+
|
|
151
69
|
{
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
70
|
+
App: {
|
|
71
|
+
name: 'My Title',
|
|
72
|
+
items: 25,
|
|
73
|
+
darkMode: true,
|
|
74
|
+
Special: { primaryColor: 3368601, isCaching: false }
|
|
75
|
+
}
|
|
157
76
|
}
|
|
158
77
|
```
|
|
159
78
|
|
|
79
|
+
That's it!
|
|
80
|
+
|
|
81
|
+
▶️ Link to [examples/](https://github.com/YINI-lang/yini-parser-typescript/tree/main/examples) files.
|
|
82
|
+
|
|
83
|
+
## 💡 Why YINI?
|
|
84
|
+
- **Easy to read and write**, minimal syntax noise, maximum clarity.
|
|
85
|
+
- **Clear and minimal section nesting** without painful indentation rules or long dot nested strings, etc.
|
|
86
|
+
- A perfect alternative to messy JSON, legacy INI, or complex YAML.
|
|
87
|
+
- Built for both **JavaScript and TypeScript**.
|
|
88
|
+
- **Supports strict/lenient modes**, and all major data types.
|
|
89
|
+
- Both **human-friendly**, and **machine-friendly**.
|
|
90
|
+
- 👉 See [how YINI compares to JSON, YAML, INI, and TOML](https://github.com/YINI-lang/yini-parser-typescript/tree/main/examples/compare-formats.md).
|
|
91
|
+
- Want the full syntax reference? See the [YINI Specification](https://github.com/YINI-lang/YINI-spec).
|
|
92
|
+
|
|
160
93
|
---
|
|
161
94
|
|
|
162
95
|
## Intro to YINI Config Format
|
|
163
96
|
|
|
164
97
|
### 1. Sections
|
|
165
|
-
Group settings under a named header. A section header starts with `^`.
|
|
98
|
+
Group settings under a named header. A section header name starts with `^`.
|
|
166
99
|
|
|
167
100
|
Start a section with `^`, e.g.:
|
|
168
101
|
```yini
|
|
@@ -170,6 +103,10 @@ Start a section with `^`, e.g.:
|
|
|
170
103
|
title = "AppName"
|
|
171
104
|
```
|
|
172
105
|
|
|
106
|
+
> Alternative section markers to `^` are also supported: `<`, `§`, `€` (e.g. `< Section`).
|
|
107
|
+
|
|
108
|
+
> See section 9 for more advanced marker and naming options.
|
|
109
|
+
|
|
173
110
|
### 2. Key = Value
|
|
174
111
|
Each line inside a section is a **key** (name) and **value**, separated by `=`.
|
|
175
112
|
|
|
@@ -179,21 +116,27 @@ maxConnections = 100
|
|
|
179
116
|
enableLogging = true
|
|
180
117
|
```
|
|
181
118
|
|
|
119
|
+
> See section 9 for more advanced marker and naming options.
|
|
120
|
+
|
|
121
|
+
#### 💡Tip
|
|
122
|
+
Use backticks (\`) to quote section or key names that contain spaces or special characters.
|
|
123
|
+
|
|
124
|
+
Key names with spaces/special characters can be backticked:
|
|
125
|
+
|
|
126
|
+
```yini
|
|
127
|
+
user id = 1 # Invalid ❌
|
|
128
|
+
`user id` = 1 # Valid ✅
|
|
129
|
+
```
|
|
130
|
+
|
|
182
131
|
### 3. Values
|
|
183
132
|
Values can be:
|
|
184
|
-
- **Strings** (always quoted): `
|
|
133
|
+
- **Strings** (always quoted): `'hello'` or `"world"` (either single or double quoted)
|
|
185
134
|
- **Numbers:** `42`, `3.14` or `-10`
|
|
186
135
|
- **Booleans:** `true`, `false`, `on`, `off`, `yes`, `no` (all case-insensitive)
|
|
187
|
-
- **Nulls:** `null` or
|
|
188
|
-
-
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
```yini
|
|
192
|
-
fruits:
|
|
193
|
-
"Pear",
|
|
194
|
-
"Cherry",
|
|
195
|
-
"Banana"
|
|
196
|
-
```
|
|
136
|
+
- **Nulls:** Use `null` or leave the value blank after `=` (in lenient mode)
|
|
137
|
+
- **Lists:**
|
|
138
|
+
* JSON‑style: `["red", "green", "blue"]`
|
|
139
|
+
* Colon‑style: *(Planned – not yet implemented in parser)*
|
|
197
140
|
|
|
198
141
|
### 4. Comments
|
|
199
142
|
Various commenting styles are supported:
|
|
@@ -207,15 +150,25 @@ interval = 30 # inline comment (must have a space after #)
|
|
|
207
150
|
; Full line comment (must be whole line).
|
|
208
151
|
```
|
|
209
152
|
|
|
210
|
-
|
|
153
|
+
> **Tip:** You can add comments anywhere—above, beside, or below any setting or section.
|
|
154
|
+
>
|
|
155
|
+
👆 **Caveat 1:** If you use `#` for comments, always put a space after the `#`.
|
|
156
|
+
(Otherwise, the parser might misinterpret it as part of a value.)
|
|
157
|
+
|
|
158
|
+
👆 **Caveat 2:** `;` is used only for full-line comments. The `;` must be the first non-whitespace character on a line (only spaces or tabs are allowed before it).
|
|
159
|
+
(If `;` appears later in the line, the parser may treat it as part of a value or as a line delimiter, not as a comment.)
|
|
211
160
|
|
|
212
|
-
|
|
161
|
+
💡**Tip:** You can use any comment style in your file.
|
|
162
|
+
For best readability, try to stick to one style per file.
|
|
213
163
|
|
|
214
164
|
### 5. Nested Sections
|
|
215
165
|
Use extra carets `^` for sub‑sections:
|
|
216
166
|
```yini
|
|
217
167
|
^ Parent
|
|
218
168
|
^^ Child
|
|
169
|
+
|
|
170
|
+
// Add another caret `^` and you get a sub-section
|
|
171
|
+
// of the previous section, and so...
|
|
219
172
|
^^^ SubChild
|
|
220
173
|
```
|
|
221
174
|
|
|
@@ -259,20 +212,33 @@ The above Yini code will produce the following JavaScript object:
|
|
|
259
212
|
}
|
|
260
213
|
```
|
|
261
214
|
|
|
215
|
+
> See section 9 for more advanced marker and naming options.
|
|
216
|
+
|
|
262
217
|
### 6. Lists
|
|
263
|
-
--Work-in-Progress--
|
|
264
218
|
```yini
|
|
265
|
-
// JSON‑style
|
|
219
|
+
// JSON‑style lists
|
|
266
220
|
colors = ["red", "green", "blue"]
|
|
267
221
|
|
|
222
|
+
numberList = [
|
|
223
|
+
10,
|
|
224
|
+
20,
|
|
225
|
+
30
|
|
226
|
+
]
|
|
227
|
+
|
|
228
|
+
|
|
268
229
|
// Colon‑style list
|
|
230
|
+
// 👆 Colon‑style list support is planned for an upcoming release.
|
|
269
231
|
fruits:
|
|
270
232
|
"Pear",
|
|
271
233
|
"Cherry",
|
|
272
234
|
"Banana"
|
|
273
235
|
```
|
|
274
236
|
|
|
237
|
+
> You can use either single or double quotes for string values in YINI.
|
|
238
|
+
|
|
275
239
|
### 7. Document Terminator (strict mode)
|
|
240
|
+
The `/END` marker is required only in strict mode, and optional in lenient (default) mode.
|
|
241
|
+
|
|
276
242
|
End a file explicitly with:
|
|
277
243
|
```yini
|
|
278
244
|
^ App
|
|
@@ -282,12 +248,45 @@ title = "MyTitle"
|
|
|
282
248
|
```
|
|
283
249
|
|
|
284
250
|
### 8. Disabled Lines
|
|
285
|
-
Prefix any valid line with
|
|
251
|
+
Prefix any valid line with `--` to skip it entirely:
|
|
286
252
|
```yini
|
|
287
253
|
--maxRetries = 5
|
|
288
254
|
```
|
|
289
255
|
|
|
290
|
-
### 9.
|
|
256
|
+
### 9. Advanced: Alternative Section Markers & Naming
|
|
257
|
+
In addition to the standard syntax, YINI supports several advanced options:
|
|
258
|
+
|
|
259
|
+
- (a.) **Alternative section markers:**
|
|
260
|
+
Besides `^`, you can use `<`, `§`, or `€` as section header markers.
|
|
261
|
+
|
|
262
|
+
```yini
|
|
263
|
+
< MySection
|
|
264
|
+
§ Settings
|
|
265
|
+
€ MyApp
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
- (b.) **Backticked section names and key names:**
|
|
269
|
+
Use backticks (`) to allow spaces or special characters in section or key names:
|
|
270
|
+
|
|
271
|
+
```yini
|
|
272
|
+
^ `Section name with spaces`
|
|
273
|
+
`user id` = 42
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
- (c.) **Numeric shorthand section markers:**
|
|
277
|
+
To create deeply nested sections (beyond 6 levels), use numeric shorthand:
|
|
278
|
+
|
|
279
|
+
```yini
|
|
280
|
+
^7 DeepSection # Equivalent to 7 carets: ^^^^^^^ DeepSection
|
|
281
|
+
<10 VeryDeep # Equivalent to <<<<<<<<<<< VeryDeep
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
👆 Though, can not mix standard/classic and numeric shorthand markers in the same section header.
|
|
285
|
+
|
|
286
|
+
- (d.) **More features:**
|
|
287
|
+
The YINI format supports even more features than listed here, such as additional number notations, string types, and advanced escaping. For full details, see the [latest release of the YINI specification](https://github.com/YINI-lang/YINI-spec/blob/release/YINI-Specification.md).
|
|
288
|
+
|
|
289
|
+
### 10. Complete Example
|
|
291
290
|
|
|
292
291
|
```yini
|
|
293
292
|
@yini # Optional marker to identify YINI format.
|
|
@@ -300,18 +299,132 @@ debug = off // Turn on for debugging.
|
|
|
300
299
|
^^ Database
|
|
301
300
|
host = "db.local"
|
|
302
301
|
port = 5432
|
|
303
|
-
--user = "secret" # This line is disabled
|
|
304
|
-
|
|
302
|
+
--user = "secret" # This line is disabled due to --.
|
|
303
|
+
userList = ["alice", "bob", "carol"]
|
|
305
304
|
|
|
306
305
|
/END
|
|
307
306
|
```
|
|
308
307
|
|
|
309
308
|
---
|
|
310
309
|
|
|
311
|
-
|
|
310
|
+
## Usage
|
|
312
311
|
|
|
312
|
+
### Installation
|
|
313
|
+
|
|
314
|
+
With **npm**:
|
|
315
|
+
```sh
|
|
316
|
+
npm install yini-parser
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
With **yarn**:
|
|
320
|
+
```sh
|
|
321
|
+
yarn add yini-parser
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
With **pnpm**:
|
|
325
|
+
```sh
|
|
326
|
+
pnpm add yini-parser
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### Node.js (CommonJS)
|
|
330
|
+
**Note:** Only a default export (YINI) is provided. Named imports are not supported.
|
|
313
331
|
```js
|
|
314
|
-
const YINI = require('yini-parser');
|
|
332
|
+
const YINI = require('yini-parser').default;
|
|
333
|
+
// (!) If you get undefined, try:
|
|
334
|
+
// (Some Node.js setups require the .default property, others don't, due to ESM/CommonJS interop quirks.)
|
|
335
|
+
const YINI = require('yini-parser');
|
|
336
|
+
|
|
337
|
+
// Parse from string.
|
|
338
|
+
const config = YINI.parse(`
|
|
339
|
+
^ App
|
|
340
|
+
title = 'My App Title'
|
|
341
|
+
items = 25
|
|
342
|
+
isDarkTheme = true
|
|
343
|
+
`);
|
|
344
|
+
|
|
345
|
+
// Parse from file.
|
|
346
|
+
const configFromFile = YINI.parseFile('./config.yini');
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### TypeScript (with `"esModuleInterop": true`)
|
|
350
|
+
```ts
|
|
351
|
+
import YINI from 'yini-parser';
|
|
352
|
+
|
|
353
|
+
// Parse from string.
|
|
354
|
+
const config = YINI.parse(`
|
|
355
|
+
^ App
|
|
356
|
+
title = "My App Title"
|
|
357
|
+
items = 25
|
|
358
|
+
isDarkTheme = OFF
|
|
359
|
+
`);
|
|
360
|
+
|
|
361
|
+
// Parse from file.
|
|
362
|
+
const configFromFile = YINI.parseFile('./config.yini');
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### Example Output
|
|
366
|
+
```js
|
|
367
|
+
// JS object
|
|
368
|
+
{
|
|
369
|
+
App: {
|
|
370
|
+
title: "My App Title",
|
|
371
|
+
items: 25,
|
|
372
|
+
isDarkTheme: false
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
---
|
|
378
|
+
|
|
379
|
+
## ✨ Features
|
|
380
|
+
- Simple syntax (supports both strict and lenient modes).
|
|
381
|
+
- Familiar config file style (inspired by INI, JSON, Python, and Markdown).
|
|
382
|
+
- Easy programmatic usage.
|
|
383
|
+
- Only the `YINI` class is exported; all internal details are private.
|
|
384
|
+
- Lists (bracketed): `list = [10, 20, 30]`
|
|
385
|
+
- 🚧 *(Planned – not yet implemented in parser)* Supports alternative list notation (colon‑style lists):
|
|
386
|
+
```yini
|
|
387
|
+
fruits:
|
|
388
|
+
'Pear',
|
|
389
|
+
'Cherry',
|
|
390
|
+
'Banana'
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
### Limitations
|
|
394
|
+
Not all features of the full YINI are implemented yet.
|
|
395
|
+
|
|
396
|
+
See [FEATURE-CHECKLIST.md](https://github.com/YINI-lang/yini-parser-typescript/blob/main/FEATURE-CHECKLIST.md) for the current list of implemented YINI features.
|
|
397
|
+
|
|
398
|
+
## 🚧 Missing or Upcoming Features
|
|
399
|
+
|
|
400
|
+
This parser currently supports all core YINI syntax for values, comments, section headers, and basic nesting.
|
|
401
|
+
|
|
402
|
+
The following features from the [YINI specification](https://github.com/YINI-lang/YINI-spec) are **planned but not yet fully implemented**:
|
|
403
|
+
|
|
404
|
+
- Object literals
|
|
405
|
+
- Advanced escape sequences
|
|
406
|
+
- String types and triple-quoted strings
|
|
407
|
+
- All number format literals
|
|
408
|
+
- Full strict mode validation
|
|
409
|
+
|
|
410
|
+
You can follow progress in the [YINI parser GitHub repo-FEATURE-CHECKLIST](https://github.com/YINI-lang/yini-parser-typescript/blob/main/FEATURE-CHECKLIST.md). Contributions and feature requests are welcome!
|
|
411
|
+
|
|
412
|
+
## 📂 Examples
|
|
413
|
+
|
|
414
|
+
See the [examples/](https://github.com/YINI-lang/yini-parser-typescript/tree/main/examples) folder for:
|
|
415
|
+
|
|
416
|
+
- Basic YINI file with common types and comments
|
|
417
|
+
- Nested sections example
|
|
418
|
+
- Comparison with JSON/YAML config
|
|
419
|
+
|
|
420
|
+
These examples are also included in the npm package.
|
|
421
|
+
|
|
422
|
+
---
|
|
423
|
+
|
|
424
|
+
## Advanced Example
|
|
425
|
+
|
|
426
|
+
```js
|
|
427
|
+
const YINI = require('yini-parser').default; // Or: import YINI from 'yini-parser';
|
|
315
428
|
|
|
316
429
|
const config = YINI.parse(`
|
|
317
430
|
/*
|
|
@@ -352,7 +465,7 @@ const config = YINI.parse(`
|
|
|
352
465
|
console.log(config);
|
|
353
466
|
```
|
|
354
467
|
|
|
355
|
-
|
|
468
|
+
### Output:
|
|
356
469
|
```js
|
|
357
470
|
// JS object
|
|
358
471
|
{
|
|
@@ -379,11 +492,51 @@ console.log(config);
|
|
|
379
492
|
}
|
|
380
493
|
}
|
|
381
494
|
```
|
|
495
|
+
|
|
496
|
+
---
|
|
497
|
+
|
|
498
|
+
## API
|
|
499
|
+
|
|
500
|
+
Only the `YINI` class is exposed in the public API, with two static methods: `parse` and `parseFile`.
|
|
501
|
+
|
|
502
|
+
### `YINI.parse(yiniContent: string, strictMode?: boolean, bailSensitivity: 'auto' | 0 | 1 | 2 = "auto", includeMetaData = false): object`
|
|
503
|
+
|
|
504
|
+
Parses YINI code from a string.
|
|
505
|
+
|
|
506
|
+
**Params:**
|
|
507
|
+
- `yiniContent`: The YINI configuration as a string.
|
|
508
|
+
- `strictMode`: (optional, default `false`) Parse in strict mode.
|
|
509
|
+
- `bailSensitivity`: (optional, default `"auto"`) Error tolerance level.
|
|
510
|
+
* If `bailSensitivity` is `"auto"` then bail sensitivity level will be set to 0 if in non-strict mode, if in strict mode then level 1 will be used automatically.
|
|
511
|
+
- `includeMetaData`: If true then additional meta data will be returned along the object.
|
|
512
|
+
|
|
513
|
+
**Bail sensitivity levels:**
|
|
514
|
+
- 0 = 'Ignore-Errors' // Don't bail on errors, persist and try to recover.
|
|
515
|
+
- 1 = 'Abort-on-Errors'
|
|
516
|
+
- 2 = 'Abort-Even-on-Warnings'
|
|
517
|
+
|
|
518
|
+
Returns a JavaScript object representing the parsed configuration (YINI content).
|
|
519
|
+
|
|
520
|
+
### `YINI.parseFile(filePath: string, strictMode?: boolean, bailSensitivity: 'auto' | 0 | 1 | 2 = "auto", includeMetaData = false): object`
|
|
521
|
+
|
|
522
|
+
Parses YINI code from a file.
|
|
523
|
+
- `filePath`: Path to the `.yini` file.
|
|
524
|
+
- Other parameters are the same as `parse(..)`.
|
|
525
|
+
|
|
526
|
+
Returns a JavaScript object representing the parsed YINI configuration file.
|
|
527
|
+
|
|
528
|
+
---
|
|
529
|
+
|
|
530
|
+
## 🤝 Contributing
|
|
531
|
+
We welcome feedback, bug reports, feature requests, and code contributions!
|
|
532
|
+
- [Open an Issue](https://github.com/YINI-lang/yini-parser-typescript/issues)
|
|
533
|
+
- [Start a Discussion](https://github.com/YINI-lang/yini-parser-typescript/discussions)
|
|
534
|
+
|
|
382
535
|
---
|
|
383
536
|
|
|
384
537
|
## 📚 Documentation
|
|
385
|
-
- [Development Setup](
|
|
386
|
-
- [Conventions](
|
|
538
|
+
- [Development Setup](https://github.com/YINI-lang/yini-parser-typescript/blob/main/docs/Development-Setup.md) — How to run, test, and build the project, etc.
|
|
539
|
+
- [Conventions](https://github.com/YINI-lang/yini-parser-typescript/blob/main/docs/Conventions.md) — Project conventions, naming patterns, etc.
|
|
387
540
|
|
|
388
541
|
---
|
|
389
542
|
|
package/dist/YINI.d.ts
CHANGED
|
@@ -7,15 +7,37 @@ import { TJSObject } from './core/types';
|
|
|
7
7
|
export default class YINI {
|
|
8
8
|
static filePath: string;
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @
|
|
10
|
+
* Parse YINI content into a JavaScript object.
|
|
11
|
+
*
|
|
12
|
+
* @param yiniContent YINI code as a string (multi‑line content supported).
|
|
13
|
+
* @param strictMode If `true`, enforce strict parsing rules (e.g. require `/END`, disallow trailing commas).
|
|
14
|
+
* @param bailSensitivity Controls how errors and warnings are handled:
|
|
15
|
+
* - `'auto'` : Auto‑select level (strict→1, lenient→0)
|
|
16
|
+
* - `0` / `'Ignore-Errors'` : Continue parsing despite errors; log them and attempt recovery.
|
|
17
|
+
* - `1` / `'Abort-on-Errors'` : Stop parsing on the first error.
|
|
18
|
+
* - `2` / `'Abort-Even-on-Warnings'`: Stop parsing on the first warning **or** error.
|
|
19
|
+
* @param includeMetaData If `true`, return additional metadata (e.g. warnings, statistics) alongside the parsed object.
|
|
20
|
+
*
|
|
21
|
+
* @note The order of properties in each output object may differ from their order in the YINI source.
|
|
22
|
+
*
|
|
23
|
+
* @returns A JavaScript object representing the parsed YINI content.
|
|
13
24
|
*/
|
|
14
25
|
static parse: (yiniContent: string, strictMode?: boolean, bailSensitivity?: "auto" | 0 | 1 | 2, includeMetaData?: boolean) => TJSObject;
|
|
15
26
|
/**
|
|
27
|
+
* Parse a YINI file into a JavaScript object.
|
|
28
|
+
*
|
|
16
29
|
* @param yiniFile Path to the YINI file.
|
|
17
|
-
* @
|
|
18
|
-
* @
|
|
30
|
+
* @param strictMode If `true`, enforce strict parsing rules (e.g. require `/END`, disallow trailing commas).
|
|
31
|
+
* @param bailSensitivity Controls how errors and warnings are handled:
|
|
32
|
+
* - `'auto'` : Auto‑select level (strict→1, lenient→0)
|
|
33
|
+
* - `0` / `'Ignore-Errors'` : Continue parsing despite errors; log them and attempt recovery.
|
|
34
|
+
* - `1` / `'Abort-on-Errors'` : Stop parsing on the first error.
|
|
35
|
+
* - `2` / `'Abort-Even-on-Warnings'`: Stop parsing on the first warning **or** error.
|
|
36
|
+
* @param includeMetaData If `true`, return additional metadata (e.g. warnings, statistics) alongside the parsed object.
|
|
37
|
+
*
|
|
38
|
+
* @note The order of properties in each output object may differ from their order in the YINI source.
|
|
39
|
+
*
|
|
40
|
+
* @returns A JavaScript object representing the parsed YINI content.
|
|
19
41
|
*/
|
|
20
42
|
static parseFile: (filePath: string, strictMode?: boolean, bailSensitivity?: "auto" | 0 | 1 | 2, includeMetaData?: boolean) => TJSObject;
|
|
21
43
|
}
|