mason-parser 1.0.1 → 1.0.2
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/README.md +12 -5
- package/dist/index.d.mts +18 -4
- package/dist/index.d.ts +18 -4
- package/dist/index.js +708 -144
- package/dist/index.mjs +704 -144
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -160,6 +160,7 @@ Document
|
|
|
160
160
|
5. **Explicit Array Suffix (`[]`):** To define an array of complex objects, append `[]` to the heading name (e.g., `# Users[]`). Any nested heading under it (e.g. `## User` or `##`) pushes a new object into that array.
|
|
161
161
|
6. **Top-Level Anonymous Arrays:** To make the entire document parse as a top-level array, define `[]` on the very first non-empty line of the file. Each subsequent item header (like `##`) directly pushes a new anonymous object into this array.
|
|
162
162
|
7. **Anonymous & Descriptive Heading Labels:** When defining elements of an array (explicit or top-level), heading names are fully optional. You can use empty heading lines (e.g., `## ` or `##`) or descriptive notes (e.g., `## Alice (Admin)`) without affecting the structured JSON properties.
|
|
163
|
+
8. **Multiline Values:** Wrap any multi-line text block or formatted string in backticks (`` ` ``). The parser will automatically preserve formatting and newlines within the block.
|
|
163
164
|
|
|
164
165
|
---
|
|
165
166
|
|
|
@@ -207,15 +208,21 @@ name: Bob
|
|
|
207
208
|
```
|
|
208
209
|
* **Behavior:** Resolves to `{}`. Encountering a heading immediately instantiates an empty object placeholder in the parent node.
|
|
209
210
|
|
|
210
|
-
### 5.
|
|
211
|
-
|
|
211
|
+
### 5. Backtick Delimiters (Matching)
|
|
212
|
+
MaSON handles backticks dynamically based on matching the count of opening and closing backticks:
|
|
213
|
+
* **Matching Delimiters & Language Tags:** A block or string starts with any count of backticks `N` (e.g. `1` backtick or `3` backticks) and ends with exactly `N` backticks. The surrounding delimiters on both ends are completely stripped.
|
|
214
|
+
* **Language Tag Stripping:** If opening with 3 or more backticks (e.g. ```` ```javascript ````), a single alphanumeric language identifier following the backticks is automatically stripped to enable seamless Markdown copying.
|
|
212
215
|
```markdown
|
|
213
|
-
|
|
216
|
+
script: ```javascript
|
|
217
|
+
function calculateTotal() {}
|
|
214
218
|
```
|
|
215
|
-
|
|
219
|
+
```
|
|
220
|
+
* **Behavior:** Resolves to `"function calculateTotal() {}"`.
|
|
221
|
+
* **Embedding Backticks:** By using `N` backticks as the delimiter, you can easily embed backticks of other lengths (such as code spans of length `1`) without them being treated as delimiters.
|
|
216
222
|
```markdown
|
|
217
|
-
|
|
223
|
+
literalText: `` `code` ``
|
|
218
224
|
```
|
|
225
|
+
* **Behavior:** Resolves to `"`code`"`.
|
|
219
226
|
|
|
220
227
|
---
|
|
221
228
|
|
package/dist/index.d.mts
CHANGED
|
@@ -24,11 +24,21 @@ interface ParseResult {
|
|
|
24
24
|
tokenSavingsPercent: number;
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
+
interface ParseOptions {
|
|
28
|
+
noTrace?: boolean;
|
|
29
|
+
}
|
|
27
30
|
/**
|
|
28
31
|
* Casts a string value to its implicit primitive type or returns the string.
|
|
29
|
-
* Strips quotes if they enclose the string explicitly.
|
|
32
|
+
* Strips quotes if they enclose the string explicitly and restores escaped characters.
|
|
30
33
|
*/
|
|
31
34
|
declare function parsePrimitiveValue(val: string): any;
|
|
35
|
+
/**
|
|
36
|
+
* Parses a single-line or multiline value, advancing the line reader index if needed.
|
|
37
|
+
*/
|
|
38
|
+
declare function parseValueWithMultiline(initialValStr: string, lines: string[], currentLineIndex: number): {
|
|
39
|
+
value: any;
|
|
40
|
+
nextLineIndex: number;
|
|
41
|
+
};
|
|
32
42
|
/**
|
|
33
43
|
* Formats a value for MSON stringification.
|
|
34
44
|
* Wraps in quotes if it has special characters or looks like a keyword but is a string.
|
|
@@ -37,14 +47,18 @@ declare function stringifyPrimitiveValue(val: any): string;
|
|
|
37
47
|
/**
|
|
38
48
|
* Parses MSON text into a JavaScript Object / Array.
|
|
39
49
|
*/
|
|
40
|
-
declare function parse(text: string): any;
|
|
50
|
+
declare function parse(text: string, options?: ParseOptions): any;
|
|
51
|
+
/**
|
|
52
|
+
* Ultra-performance, trace-free parser for MSON.
|
|
53
|
+
*/
|
|
54
|
+
declare function fastParseWithTrace(text: string): ParseResult;
|
|
41
55
|
/**
|
|
42
56
|
* Parses MSON text into a JavaScript Object / Array with step-by-step trace info.
|
|
43
57
|
*/
|
|
44
|
-
declare function parseWithTrace(text: string): ParseResult;
|
|
58
|
+
declare function parseWithTrace(text: string, options?: ParseOptions): ParseResult;
|
|
45
59
|
/**
|
|
46
60
|
* Stringifies a JavaScript object/array back into MSON text recursively.
|
|
47
61
|
*/
|
|
48
62
|
declare function stringify(obj: any, level?: number, parentKey?: string): string;
|
|
49
63
|
|
|
50
|
-
export { type ParseResult, type ParserTraceStep, parse, parse as parseMSON, parsePrimitiveValue, parseWithTrace, stringify, stringify as stringifyMSON, stringifyPrimitiveValue };
|
|
64
|
+
export { type ParseOptions, type ParseResult, type ParserTraceStep, fastParseWithTrace, parse, parse as parseMSON, parseWithTrace as parseMaSON, parsePrimitiveValue, parseValueWithMultiline, parseWithTrace, stringify, stringify as stringifyMSON, stringify as stringifyMaSON, stringifyPrimitiveValue };
|
package/dist/index.d.ts
CHANGED
|
@@ -24,11 +24,21 @@ interface ParseResult {
|
|
|
24
24
|
tokenSavingsPercent: number;
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
+
interface ParseOptions {
|
|
28
|
+
noTrace?: boolean;
|
|
29
|
+
}
|
|
27
30
|
/**
|
|
28
31
|
* Casts a string value to its implicit primitive type or returns the string.
|
|
29
|
-
* Strips quotes if they enclose the string explicitly.
|
|
32
|
+
* Strips quotes if they enclose the string explicitly and restores escaped characters.
|
|
30
33
|
*/
|
|
31
34
|
declare function parsePrimitiveValue(val: string): any;
|
|
35
|
+
/**
|
|
36
|
+
* Parses a single-line or multiline value, advancing the line reader index if needed.
|
|
37
|
+
*/
|
|
38
|
+
declare function parseValueWithMultiline(initialValStr: string, lines: string[], currentLineIndex: number): {
|
|
39
|
+
value: any;
|
|
40
|
+
nextLineIndex: number;
|
|
41
|
+
};
|
|
32
42
|
/**
|
|
33
43
|
* Formats a value for MSON stringification.
|
|
34
44
|
* Wraps in quotes if it has special characters or looks like a keyword but is a string.
|
|
@@ -37,14 +47,18 @@ declare function stringifyPrimitiveValue(val: any): string;
|
|
|
37
47
|
/**
|
|
38
48
|
* Parses MSON text into a JavaScript Object / Array.
|
|
39
49
|
*/
|
|
40
|
-
declare function parse(text: string): any;
|
|
50
|
+
declare function parse(text: string, options?: ParseOptions): any;
|
|
51
|
+
/**
|
|
52
|
+
* Ultra-performance, trace-free parser for MSON.
|
|
53
|
+
*/
|
|
54
|
+
declare function fastParseWithTrace(text: string): ParseResult;
|
|
41
55
|
/**
|
|
42
56
|
* Parses MSON text into a JavaScript Object / Array with step-by-step trace info.
|
|
43
57
|
*/
|
|
44
|
-
declare function parseWithTrace(text: string): ParseResult;
|
|
58
|
+
declare function parseWithTrace(text: string, options?: ParseOptions): ParseResult;
|
|
45
59
|
/**
|
|
46
60
|
* Stringifies a JavaScript object/array back into MSON text recursively.
|
|
47
61
|
*/
|
|
48
62
|
declare function stringify(obj: any, level?: number, parentKey?: string): string;
|
|
49
63
|
|
|
50
|
-
export { type ParseResult, type ParserTraceStep, parse, parse as parseMSON, parsePrimitiveValue, parseWithTrace, stringify, stringify as stringifyMSON, stringifyPrimitiveValue };
|
|
64
|
+
export { type ParseOptions, type ParseResult, type ParserTraceStep, fastParseWithTrace, parse, parse as parseMSON, parseWithTrace as parseMaSON, parsePrimitiveValue, parseValueWithMultiline, parseWithTrace, stringify, stringify as stringifyMSON, stringify as stringifyMaSON, stringifyPrimitiveValue };
|