yini-parser 1.0.0-alpha.6 → 1.0.0-alpha.7
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 +7 -1
- package/README.md +74 -14
- package/dist/YINI.d.ts +27 -5
- package/dist/YINI.js +27 -5
- package/dist/core/ErrorDataHandler.js +28 -32
- package/dist/index.js +7 -11
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 1.0.0-alpha.7
|
|
4
|
+
- Fixed serious bug that on error did exit process.
|
|
5
|
+
- Pached and updated JSDoc for remaing params for the functions parse(..) and parseFile(..).
|
|
6
|
+
- Changed the WIPs in the readme to "Planned – not yet implemented"-tag.
|
|
7
|
+
- Updated readme and especially "Intro to YINI Config Format".
|
|
8
|
+
|
|
3
9
|
## 1.0.0-alpha.6
|
|
4
10
|
- The YINI specificaiton discontinued alternative marker character `~` (visually ambiguous) in favor of `<`.
|
|
5
11
|
- 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
12
|
- 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.
|
|
13
|
+
- Updated readme with "Intro to YINI Config Format" among other misc. updates.
|
|
8
14
|
|
|
9
15
|
## 1.0.0-alpha.5
|
|
10
16
|
- Readme updated with correct examples for CommonJS.
|
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ YINI is a simple, human-friendly configuration format inspired by INI and JSON.
|
|
|
18
18
|
A simple configuration:
|
|
19
19
|
```yini
|
|
20
20
|
^ App
|
|
21
|
-
name = 'My Title'
|
|
21
|
+
name = 'My Title' // App display name.
|
|
22
22
|
items = 25
|
|
23
23
|
enabled = true
|
|
24
24
|
```
|
|
@@ -40,7 +40,7 @@ That's it!
|
|
|
40
40
|
- Familiar config file style (inspired by INI, JSON, Python, and Markdown).
|
|
41
41
|
- Easy programmatic usage.
|
|
42
42
|
- Only the `YINI` class is exported; all internal details are private.
|
|
43
|
-
-
|
|
43
|
+
- 🚧 *(Planned – not yet implemented in parser)* Supports alternative list notation (colon‑style lists):
|
|
44
44
|
```yini
|
|
45
45
|
fruits:
|
|
46
46
|
'Pear',
|
|
@@ -79,9 +79,10 @@ pnpm add yini-parser
|
|
|
79
79
|
### Node.js (CommonJS)
|
|
80
80
|
**Note:** Only a default export (YINI) is provided. Named imports are not supported.
|
|
81
81
|
```js
|
|
82
|
-
const YINI = require('yini-parser');
|
|
83
|
-
// If you get undefined, try:
|
|
84
82
|
const YINI = require('yini-parser').default;
|
|
83
|
+
// (!) If you get undefined, try:
|
|
84
|
+
// (Some Node.js setups require the .default property, others don't, due to ESM/CommonJS interop quirks.)
|
|
85
|
+
const YINI = require('yini-parser');
|
|
85
86
|
|
|
86
87
|
// Parse from string.
|
|
87
88
|
const config = YINI.parse(`
|
|
@@ -162,7 +163,7 @@ Returns a JavaScript object representing the parsed YINI configuration file.
|
|
|
162
163
|
## Intro to YINI Config Format
|
|
163
164
|
|
|
164
165
|
### 1. Sections
|
|
165
|
-
Group settings under a named header. A section header starts with `^`.
|
|
166
|
+
Group settings under a named header. A section header name starts with `^`.
|
|
166
167
|
|
|
167
168
|
Start a section with `^`, e.g.:
|
|
168
169
|
```yini
|
|
@@ -170,6 +171,10 @@ Start a section with `^`, e.g.:
|
|
|
170
171
|
title = "AppName"
|
|
171
172
|
```
|
|
172
173
|
|
|
174
|
+
> Alternative section markers to `^` are also supported: `<`, `§`, `€` (e.g. `< Section`).
|
|
175
|
+
|
|
176
|
+
> See section 9 for more advanced marker and naming options.
|
|
177
|
+
|
|
173
178
|
### 2. Key = Value
|
|
174
179
|
Each line inside a section is a **key** (name) and **value**, separated by `=`.
|
|
175
180
|
|
|
@@ -179,13 +184,25 @@ maxConnections = 100
|
|
|
179
184
|
enableLogging = true
|
|
180
185
|
```
|
|
181
186
|
|
|
187
|
+
> See section 9 for more advanced marker and naming options.
|
|
188
|
+
|
|
189
|
+
#### 💡Tip
|
|
190
|
+
Use backticks (\`) to quote section or key names that contain spaces or special characters.
|
|
191
|
+
|
|
192
|
+
Key names with spaces/special characters can be backticked:
|
|
193
|
+
|
|
194
|
+
```yini
|
|
195
|
+
user id = 1 # Invalid ❌
|
|
196
|
+
`user id` = 1 # Valid ✅
|
|
197
|
+
```
|
|
198
|
+
|
|
182
199
|
### 3. Values
|
|
183
200
|
Values can be:
|
|
184
201
|
- **Strings** (always quoted): `"hello"` or `'world'` (either single or double quoted)
|
|
185
202
|
- **Numbers:** `42`, `3.14` or `-10`
|
|
186
203
|
- **Booleans:** `true`, `false`, `on`, `off`, `yes`, `no` (all case-insensitive)
|
|
187
|
-
- **Nulls:** `null` or
|
|
188
|
-
-
|
|
204
|
+
- **Nulls:** Use `null` or leave the value blank after `=` (in lenient mode)
|
|
205
|
+
- *(Planned – not yet implemented in parser)* **Lists:**
|
|
189
206
|
* JSON‑style: `["red", "green", "blue"]`
|
|
190
207
|
* Colon‑style:
|
|
191
208
|
```yini
|
|
@@ -207,15 +224,22 @@ interval = 30 # inline comment (must have a space after #)
|
|
|
207
224
|
; Full line comment (must be whole line).
|
|
208
225
|
```
|
|
209
226
|
|
|
210
|
-
|
|
227
|
+
> **Tip:** You can add comments anywhere—above, beside, or below any setting or section.
|
|
228
|
+
>
|
|
229
|
+
👆 **Caveat:** If you use `#` for comments, always put a space after the `#`.
|
|
230
|
+
(Otherwise, the parser might misinterpret it as part of a value.)
|
|
211
231
|
|
|
212
|
-
|
|
232
|
+
💡**Tip:** You can use any comment style in your file.
|
|
233
|
+
For best readability, try to stick to one style per file.
|
|
213
234
|
|
|
214
235
|
### 5. Nested Sections
|
|
215
236
|
Use extra carets `^` for sub‑sections:
|
|
216
237
|
```yini
|
|
217
238
|
^ Parent
|
|
218
239
|
^^ Child
|
|
240
|
+
|
|
241
|
+
// Add another caret `^` and you get a sub-section
|
|
242
|
+
// of the previous section, and so...
|
|
219
243
|
^^^ SubChild
|
|
220
244
|
```
|
|
221
245
|
|
|
@@ -259,8 +283,10 @@ The above Yini code will produce the following JavaScript object:
|
|
|
259
283
|
}
|
|
260
284
|
```
|
|
261
285
|
|
|
286
|
+
> See section 9 for more advanced marker and naming options.
|
|
287
|
+
|
|
262
288
|
### 6. Lists
|
|
263
|
-
|
|
289
|
+
👆 *List support is planned for an upcoming release.*
|
|
264
290
|
```yini
|
|
265
291
|
// JSON‑style list
|
|
266
292
|
colors = ["red", "green", "blue"]
|
|
@@ -272,7 +298,11 @@ fruits:
|
|
|
272
298
|
"Banana"
|
|
273
299
|
```
|
|
274
300
|
|
|
301
|
+
> You can use either single or double quotes for string values in YINI.
|
|
302
|
+
|
|
275
303
|
### 7. Document Terminator (strict mode)
|
|
304
|
+
The `/END` marker is required only in strict mode, and optional in lenient (default) mode.
|
|
305
|
+
|
|
276
306
|
End a file explicitly with:
|
|
277
307
|
```yini
|
|
278
308
|
^ App
|
|
@@ -282,12 +312,42 @@ title = "MyTitle"
|
|
|
282
312
|
```
|
|
283
313
|
|
|
284
314
|
### 8. Disabled Lines
|
|
285
|
-
Prefix any valid line with
|
|
315
|
+
Prefix any valid line with `--` to skip it entirely:
|
|
286
316
|
```yini
|
|
287
317
|
--maxRetries = 5
|
|
288
318
|
```
|
|
289
319
|
|
|
290
|
-
### 9.
|
|
320
|
+
### 9. Advanced: Alternative Section Markers & Naming
|
|
321
|
+
In addition to the standard syntax, YINI supports several advanced options:
|
|
322
|
+
|
|
323
|
+
- (a.) **Alternative section markers:**
|
|
324
|
+
Besides `^`, you can use `<`, `§`, or `€` as section header markers.
|
|
325
|
+
|
|
326
|
+
```yini
|
|
327
|
+
< MySection
|
|
328
|
+
§ Settings
|
|
329
|
+
€ MyApp
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
- (b.) **Backticked section names and key names:**
|
|
333
|
+
Use backticks (`) to allow spaces or special characters in section or key names:
|
|
334
|
+
|
|
335
|
+
```yini
|
|
336
|
+
^ `Section name with spaces`
|
|
337
|
+
`user id` = 42
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
- (c.) **Numeric shorthand section markers:**
|
|
341
|
+
To create deeply nested sections (beyond 6 levels), use numeric shorthand:
|
|
342
|
+
|
|
343
|
+
```yini
|
|
344
|
+
^7 DeepSection # Equivalent to 7 carets: ^^^^^^^ DeepSection
|
|
345
|
+
<10 VeryDeep # Equivalent to <<<<<<<<<<< VeryDeep
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
👆 Though, can not mix standard/classic and numeric shorthand markers in the same section header.
|
|
349
|
+
|
|
350
|
+
### 10. Complete Example
|
|
291
351
|
|
|
292
352
|
```yini
|
|
293
353
|
@yini # Optional marker to identify YINI format.
|
|
@@ -300,7 +360,7 @@ debug = off // Turn on for debugging.
|
|
|
300
360
|
^^ Database
|
|
301
361
|
host = "db.local"
|
|
302
362
|
port = 5432
|
|
303
|
-
--user = "secret" # This line is disabled
|
|
363
|
+
--user = "secret" # This line is disabled due to --.
|
|
304
364
|
--userList = ["alice", "bob", "carol"]
|
|
305
365
|
|
|
306
366
|
/END
|
|
@@ -311,7 +371,7 @@ port = 5432
|
|
|
311
371
|
### Advanced Example
|
|
312
372
|
|
|
313
373
|
```js
|
|
314
|
-
const YINI = require('yini-parser'); // Or: import YINI from 'yini-parser';
|
|
374
|
+
const YINI = require('yini-parser').default; // Or: import YINI from 'yini-parser';
|
|
315
375
|
|
|
316
376
|
const config = YINI.parse(`
|
|
317
377
|
/*
|
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
|
}
|
package/dist/YINI.js
CHANGED
|
@@ -17,9 +17,20 @@ class YINI {
|
|
|
17
17
|
}
|
|
18
18
|
YINI.filePath = ''; // Used in error reporting.
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* @
|
|
20
|
+
* Parse YINI content into a JavaScript object.
|
|
21
|
+
*
|
|
22
|
+
* @param yiniContent YINI code as a string (multi‑line content supported).
|
|
23
|
+
* @param strictMode If `true`, enforce strict parsing rules (e.g. require `/END`, disallow trailing commas).
|
|
24
|
+
* @param bailSensitivity Controls how errors and warnings are handled:
|
|
25
|
+
* - `'auto'` : Auto‑select level (strict→1, lenient→0)
|
|
26
|
+
* - `0` / `'Ignore-Errors'` : Continue parsing despite errors; log them and attempt recovery.
|
|
27
|
+
* - `1` / `'Abort-on-Errors'` : Stop parsing on the first error.
|
|
28
|
+
* - `2` / `'Abort-Even-on-Warnings'`: Stop parsing on the first warning **or** error.
|
|
29
|
+
* @param includeMetaData If `true`, return additional metadata (e.g. warnings, statistics) alongside the parsed object.
|
|
30
|
+
*
|
|
31
|
+
* @note The order of properties in each output object may differ from their order in the YINI source.
|
|
32
|
+
*
|
|
33
|
+
* @returns A JavaScript object representing the parsed YINI content.
|
|
23
34
|
*/
|
|
24
35
|
YINI.parse = (yiniContent, strictMode = false, bailSensitivity = 'auto', includeMetaData = false) => {
|
|
25
36
|
(0, system_1.debugPrint)('-> Entered static parse(..) in class YINI\n');
|
|
@@ -66,9 +77,20 @@ YINI.parse = (yiniContent, strictMode = false, bailSensitivity = 'auto', include
|
|
|
66
77
|
return result;
|
|
67
78
|
};
|
|
68
79
|
/**
|
|
80
|
+
* Parse a YINI file into a JavaScript object.
|
|
81
|
+
*
|
|
69
82
|
* @param yiniFile Path to the YINI file.
|
|
70
|
-
* @
|
|
71
|
-
* @
|
|
83
|
+
* @param strictMode If `true`, enforce strict parsing rules (e.g. require `/END`, disallow trailing commas).
|
|
84
|
+
* @param bailSensitivity Controls how errors and warnings are handled:
|
|
85
|
+
* - `'auto'` : Auto‑select level (strict→1, lenient→0)
|
|
86
|
+
* - `0` / `'Ignore-Errors'` : Continue parsing despite errors; log them and attempt recovery.
|
|
87
|
+
* - `1` / `'Abort-on-Errors'` : Stop parsing on the first error.
|
|
88
|
+
* - `2` / `'Abort-Even-on-Warnings'`: Stop parsing on the first warning **or** error.
|
|
89
|
+
* @param includeMetaData If `true`, return additional metadata (e.g. warnings, statistics) alongside the parsed object.
|
|
90
|
+
*
|
|
91
|
+
* @note The order of properties in each output object may differ from their order in the YINI source.
|
|
92
|
+
*
|
|
93
|
+
* @returns A JavaScript object representing the parsed YINI content.
|
|
72
94
|
*/
|
|
73
95
|
YINI.parseFile = (filePath, strictMode = false, bailSensitivity = 'auto', includeMetaData = false) => {
|
|
74
96
|
(0, system_1.debugPrint)('Current directory = ' + process.cwd());
|
|
@@ -95,13 +95,12 @@ class ErrorDataHandler {
|
|
|
95
95
|
this.emitInternalError(msgWhat, msgWhy, msgHint);
|
|
96
96
|
if (this.persistThreshold === '1-Abort-on-Errors' ||
|
|
97
97
|
this.persistThreshold === '2-Abort-Even-on-Warnings') {
|
|
98
|
-
if (process.env.NODE_ENV === 'test') {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
98
|
+
// if (process.env.NODE_ENV === 'test') {
|
|
99
|
+
// In test, throw an error instead of exiting.
|
|
100
|
+
throw new Error(`Internal-Error: ${msgWhat}`);
|
|
101
|
+
// } else {
|
|
102
|
+
// process.exit(2)
|
|
103
|
+
// }
|
|
105
104
|
}
|
|
106
105
|
break;
|
|
107
106
|
case 'Syntax-Error':
|
|
@@ -109,26 +108,24 @@ class ErrorDataHandler {
|
|
|
109
108
|
this.emitSyntaxError(msgWhat, msgWhy, msgHint);
|
|
110
109
|
if (this.persistThreshold === '1-Abort-on-Errors' ||
|
|
111
110
|
this.persistThreshold === '2-Abort-Even-on-Warnings') {
|
|
112
|
-
if (process.env.NODE_ENV === 'test') {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
111
|
+
// if (process.env.NODE_ENV === 'test') {
|
|
112
|
+
// In test, throw an error instead of exiting.
|
|
113
|
+
throw new Error(`Syntax-Error: ${'' + msgWhat}`);
|
|
114
|
+
// } else {
|
|
115
|
+
// process.exit(3)
|
|
116
|
+
// }
|
|
119
117
|
}
|
|
120
118
|
break;
|
|
121
119
|
case 'Syntax-Warning':
|
|
122
120
|
this.numSyntaxWarnings++;
|
|
123
121
|
this.emitSyntaxWarning(msgWhat, msgWhy, msgHint);
|
|
124
122
|
if (this.persistThreshold === '2-Abort-Even-on-Warnings') {
|
|
125
|
-
if (process.env.NODE_ENV === 'test') {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
123
|
+
// if (process.env.NODE_ENV === 'test') {
|
|
124
|
+
// In test, throw an error instead of exiting.
|
|
125
|
+
throw new Error(`Syntax-Warning: ${msgWhat}`);
|
|
126
|
+
// } else {
|
|
127
|
+
// process.exit(4)
|
|
128
|
+
// }
|
|
132
129
|
}
|
|
133
130
|
break;
|
|
134
131
|
case 'Notice':
|
|
@@ -143,17 +140,16 @@ class ErrorDataHandler {
|
|
|
143
140
|
this.numFatalErrors++;
|
|
144
141
|
this.emitFatalError(msgWhat, msgWhy, msgHint);
|
|
145
142
|
// CANNOT recover fatal errors, will lead to an exit!
|
|
146
|
-
if (process.env.NODE_ENV === 'test') {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
143
|
+
// if (process.env.NODE_ENV === 'test') {
|
|
144
|
+
// In test, throw an error instead of exiting.
|
|
145
|
+
throw new Error(`Internal-Error: ${msgWhat}`);
|
|
146
|
+
// } else {
|
|
147
|
+
// process.exit(1)
|
|
148
|
+
// (!) Not sure about the below yet, if it's preferable in this case...
|
|
149
|
+
// Use this instead of process.exit(1), this will
|
|
150
|
+
// lead to that the current thread(s) will exit as well.
|
|
151
|
+
// process.exitCode = 1
|
|
152
|
+
// }
|
|
157
153
|
}
|
|
158
154
|
};
|
|
159
155
|
this.emitFatalError = (msgWhat = 'Something went wrong!', msgWhy = '', msgHint = '') => {
|
package/dist/index.js
CHANGED
|
@@ -173,18 +173,14 @@ Expected JS output:
|
|
|
173
173
|
// id = 32403 # The correct app id.
|
|
174
174
|
// title = "My Program"
|
|
175
175
|
// `
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
value = 'At level 3'
|
|
183
|
-
|
|
184
|
-
^ BackToRoot
|
|
185
|
-
value = 'Bach at level 1'
|
|
176
|
+
const corruptYini = `
|
|
177
|
+
^ App
|
|
178
|
+
title = 'MyApp Title'
|
|
179
|
+
items = 25
|
|
180
|
+
items = 90 // (!) Redefinition!
|
|
181
|
+
isDarkTheme = true
|
|
186
182
|
`;
|
|
187
|
-
YINI_1.default.parse(
|
|
183
|
+
YINI_1.default.parse(corruptYini, false, 2);
|
|
188
184
|
// YINI.parse(`
|
|
189
185
|
// ^ Section1
|
|
190
186
|
// ^^ Section2
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yini-parser",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.7",
|
|
4
4
|
"description": "Simple and flexible config parser for Node.js. YINI: an enhanced, readable alternative to JSON, INI, and YAML—built for modern JavaScript and TypeScript projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yini",
|