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
|
@@ -18,6 +18,8 @@ import { Null_literalContext } from "./YiniParser.js";
|
|
|
18
18
|
import { String_literalContext } from "./YiniParser.js";
|
|
19
19
|
import { String_concatContext } from "./YiniParser.js";
|
|
20
20
|
import { Boolean_literalContext } from "./YiniParser.js";
|
|
21
|
+
import { Empty_objectContext } from "./YiniParser.js";
|
|
22
|
+
import { Empty_listContext } from "./YiniParser.js";
|
|
21
23
|
/**
|
|
22
24
|
* This interface defines a complete generic visitor for a parse tree produced
|
|
23
25
|
* by `YiniParser`.
|
|
@@ -140,4 +142,16 @@ export default class YiniParserVisitor<Result> extends ParseTreeVisitor<Result>
|
|
|
140
142
|
* @return the visitor result
|
|
141
143
|
*/
|
|
142
144
|
visitBoolean_literal?: (ctx: Boolean_literalContext) => Result;
|
|
145
|
+
/**
|
|
146
|
+
* Visit a parse tree produced by `YiniParser.empty_object`.
|
|
147
|
+
* @param ctx the parse tree
|
|
148
|
+
* @return the visitor result
|
|
149
|
+
*/
|
|
150
|
+
visitEmpty_object?: (ctx: Empty_objectContext) => Result;
|
|
151
|
+
/**
|
|
152
|
+
* Visit a parse tree produced by `YiniParser.empty_list`.
|
|
153
|
+
* @param ctx the parse tree
|
|
154
|
+
* @return the visitor result
|
|
155
|
+
*/
|
|
156
|
+
visitEmpty_list?: (ctx: Empty_listContext) => Result;
|
|
143
157
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import YINI from './YINI';
|
|
2
|
+
export declare const parse: (yiniContent: string, strictMode?: boolean, bailSensitivity?: "auto" | 0 | 1 | 2, includeMetaData?: boolean) => import("./core/types").TJSObject;
|
|
3
|
+
export declare const parseFile: (filePath: string, strictMode?: boolean, bailSensitivity?: "auto" | 0 | 1 | 2, includeMetaData?: boolean) => import("./core/types").TJSObject;
|
|
4
|
+
export default YINI;
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
};
|
|
6
6
|
var _a, _b, _c;
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.
|
|
8
|
+
exports.parseFile = exports.parse = void 0;
|
|
9
9
|
/*
|
|
10
10
|
https://pauloe-me.medium.com/typescript-npm-package-publishing-a-beginners-guide-40b95908e69c
|
|
11
11
|
|
|
@@ -19,8 +19,10 @@ exports.default = void 0;
|
|
|
19
19
|
const env_1 = require("./config/env");
|
|
20
20
|
const system_1 = require("./utils/system");
|
|
21
21
|
const YINI_1 = __importDefault(require("./YINI"));
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
// export { default } from './YINI'
|
|
23
|
+
exports.parse = YINI_1.default.parse;
|
|
24
|
+
exports.parseFile = YINI_1.default.parseFile;
|
|
25
|
+
exports.default = YINI_1.default;
|
|
24
26
|
(0, system_1.debugPrint)();
|
|
25
27
|
(0, system_1.debugPrint)('-> Entered index.ts');
|
|
26
28
|
(0, system_1.debugPrint)();
|
|
@@ -173,18 +175,35 @@ Expected JS output:
|
|
|
173
175
|
// id = 32403 # The correct app id.
|
|
174
176
|
// title = "My Program"
|
|
175
177
|
// `
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
178
|
+
const yini = `
|
|
179
|
+
/*
|
|
180
|
+
nested.yini
|
|
181
|
+
Demonstrates nested sections in YINI format.
|
|
182
|
+
*/
|
|
183
|
+
|
|
184
|
+
@yini
|
|
185
|
+
|
|
186
|
+
^ App // Top-level section: App
|
|
187
|
+
name = 'Nested Demo App'
|
|
188
|
+
version = "1.2.3"
|
|
189
|
+
|
|
190
|
+
^^ Theme // Nested under App: App.Theme
|
|
191
|
+
primaryColor = #336699
|
|
192
|
+
darkMode = true
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
^^^ Overrides // Nested under Theme: App.Theme.Overrides
|
|
196
|
+
darkMode = false
|
|
197
|
+
fontSize = 14
|
|
198
|
+
|
|
199
|
+
^ Database // Another top-level section: Database
|
|
200
|
+
host = "db.local"
|
|
201
|
+
port = 5432
|
|
202
|
+
|
|
203
|
+
^^ Credentials // Nested under Database: Database.Credentials username = "admin"
|
|
204
|
+
password = "secret"
|
|
205
|
+
`;
|
|
206
|
+
YINI_1.default.parse(yini);
|
|
188
207
|
// YINI.parse(`
|
|
189
208
|
// ^ Section1
|
|
190
209
|
// ^^ Section2
|
|
@@ -55,6 +55,8 @@ const extractYiniLine = (rawYiniContent) => {
|
|
|
55
55
|
break;
|
|
56
56
|
default:
|
|
57
57
|
(0, system_1.debugPrint)('(!) Did find several significant lines in rawYiniContent! - Maybe internal error...');
|
|
58
|
+
(0, system_1.debugPrint)('significantLines[0] = >>>' + significantLines[0] + '<<<');
|
|
59
|
+
(0, system_1.debugPrint)('significantLines[1] = >>>' + significantLines[1] + '<<<');
|
|
58
60
|
// throw new Error(
|
|
59
61
|
// 'Internal error: Detected several row lines in rawYiniContent: >>>' +
|
|
60
62
|
// rawYiniContent +
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
basic-explained.yini
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
@yini // Optional marker indicating this is a YINI config file.
|
|
6
|
+
|
|
7
|
+
^ App // Section header: defines the "App" section.
|
|
8
|
+
title = 'My App' // A string (single-quoted or double-quoted are both supported).
|
|
9
|
+
items = 10 // A number value.
|
|
10
|
+
debug = ON // Boolean true (ON/OFF are case-insensitive aliases for true/false).
|
|
11
|
+
|
|
12
|
+
^ Server // Another top-level section.
|
|
13
|
+
host = "localhost" // A string using double quotes.
|
|
14
|
+
port = 8080 // A number value.
|
|
15
|
+
useTLS = OFF // Boolean false.
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# YINI vs JSON, YAML, INI, and TOML
|
|
2
|
+
|
|
3
|
+
This document shows how the same configuration would look in different formats.
|
|
4
|
+
|
|
5
|
+
It highlights YINI's goal: *clean, human-friendly config syntax* - with full support for nesting, comments, and typed values - while remaining simpler than YAML or JSON.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 🔵 YINI
|
|
10
|
+
|
|
11
|
+
This example shows how YINI compares to other formats for common configuration needs.
|
|
12
|
+
|
|
13
|
+
```yini
|
|
14
|
+
@yini
|
|
15
|
+
|
|
16
|
+
^ App
|
|
17
|
+
name = 'Demo App'
|
|
18
|
+
items = 25
|
|
19
|
+
darkMode = true
|
|
20
|
+
|
|
21
|
+
^^ Special
|
|
22
|
+
color = #336699
|
|
23
|
+
isCaching = false
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 🟠 JSON
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"App": {
|
|
31
|
+
"name": "Demo App",
|
|
32
|
+
"items": 25,
|
|
33
|
+
"darkMode": true,
|
|
34
|
+
"Special": {
|
|
35
|
+
"color": 3368601,
|
|
36
|
+
"isCaching": false
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 🟡 YAML
|
|
43
|
+
|
|
44
|
+
```yaml
|
|
45
|
+
App:
|
|
46
|
+
name: "Demo App"
|
|
47
|
+
items: 25
|
|
48
|
+
darkMode: true
|
|
49
|
+
Special:
|
|
50
|
+
color: 0x336699
|
|
51
|
+
isCaching: false
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 🟢 INI
|
|
55
|
+
|
|
56
|
+
```ini
|
|
57
|
+
[App]
|
|
58
|
+
name = Demo App
|
|
59
|
+
items = 25
|
|
60
|
+
darkMode = true
|
|
61
|
+
|
|
62
|
+
[App.Special]
|
|
63
|
+
color = 3368601
|
|
64
|
+
isCaching = false
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 🔴 TOML
|
|
68
|
+
|
|
69
|
+
```toml
|
|
70
|
+
[App]
|
|
71
|
+
name = "Demo App"
|
|
72
|
+
items = 25
|
|
73
|
+
darkMode = true
|
|
74
|
+
|
|
75
|
+
[App.Special]
|
|
76
|
+
color = 0x336699
|
|
77
|
+
isCaching = false
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## ✅ Summary
|
|
81
|
+
|
|
82
|
+
| Feature | **YINI** | **JSON** | **YAML** | **INI** | **TOML** |
|
|
83
|
+
|--------------------|---------------|-------------|------------|-------------|----------|
|
|
84
|
+
| Comments | ✅ Yes | ❌ No | ✅ Yes | ✅ Yes | ✅ Yes |
|
|
85
|
+
| Nesting | ✅ Clean | ✅ Manual | ✅ Native | ⚠️ Limited | ✅ Native |
|
|
86
|
+
| Data Types | ✅ Rich | ✅ Rich | ✅ Rich | ⚠️ Limited | ✅ Rich |
|
|
87
|
+
| Syntax Noise | 🚫 Minimal | 🔺 High | ⚠️ Medium | ✅ Minimal | ⚠️ Medium |
|
|
88
|
+
| Human-Writable | ✅ Yes | ❌ Verbose | ✅ Yes | ✅ Yes | ✅ Yes |
|
|
89
|
+
| Designed for Config| ✅ Purposeful | ❌ General | ✅ Yes | ✅ Yes | ✅ Yes |
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
nested.yini
|
|
3
|
+
Demonstrates nested sections in YINI format.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
@yini
|
|
7
|
+
|
|
8
|
+
^ App // Top-level section: App
|
|
9
|
+
name = 'Nested Demo App'
|
|
10
|
+
version = "1.2.3"
|
|
11
|
+
|
|
12
|
+
^^ Theme // Nested under App: App.Theme
|
|
13
|
+
primaryColor = #336699
|
|
14
|
+
darkMode = true
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
^^^ Overrides // Nested under Theme: App.Theme.Overrides
|
|
18
|
+
darkMode = false
|
|
19
|
+
fontSize = 14
|
|
20
|
+
|
|
21
|
+
^ Database // Another top-level section: Database
|
|
22
|
+
host = "db.local"
|
|
23
|
+
port = 5432
|
|
24
|
+
|
|
25
|
+
^^ Credentials // Nested under Database: Database.Credentials username = "admin"
|
|
26
|
+
password = "secret"
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* parse-example.ts
|
|
3
|
+
*
|
|
4
|
+
* Demonstrates reading and parsing a YINI configuration file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import path from 'path'
|
|
8
|
+
import YINI from 'yini-parser'
|
|
9
|
+
|
|
10
|
+
// Resolve path to the example config file.
|
|
11
|
+
const configPath = path.resolve(__dirname, './basic.yini')
|
|
12
|
+
|
|
13
|
+
// Parse the YINI config file.
|
|
14
|
+
const config = YINI.parseFile(configPath)
|
|
15
|
+
|
|
16
|
+
// Output some example values.
|
|
17
|
+
console.log('App Title:', config.App.title)
|
|
18
|
+
console.log('Items:', config.App.items)
|
|
19
|
+
console.log('Dark Theme Enabled:', config.App.isDarkTheme)
|
|
20
|
+
|
|
21
|
+
console.log('\nFull Config:')
|
|
22
|
+
console.dir(config, { depth: null })
|
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.7x",
|
|
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",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"package.json",
|
|
27
27
|
"README.md",
|
|
28
28
|
"LICENSE",
|
|
29
|
-
"CHANGELOG.md"
|
|
29
|
+
"CHANGELOG.md",
|
|
30
|
+
"examples/"
|
|
30
31
|
],
|
|
31
32
|
"main": "dist/index.js",
|
|
32
33
|
"types": "dist/index.d.ts",
|