@agentshouse/mdmodel 0.1.0-c0bdbbc92d020 → 0.1.0-c2224db91aaa3
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/API.md +159 -103
- package/dist/blocks.d.ts.map +1 -1
- package/dist/blocks.js +31 -17
- package/dist/condition.d.ts +18 -5
- package/dist/condition.d.ts.map +1 -1
- package/dist/condition.js +218 -110
- package/dist/definition.d.ts +8 -0
- package/dist/definition.d.ts.map +1 -1
- package/dist/definition.js +50 -2
- package/dist/document.d.ts +6 -8
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +77 -26
- package/dist/fields.d.ts +2 -0
- package/dist/fields.d.ts.map +1 -1
- package/dist/fields.js +7 -0
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -4
- package/dist/links.d.ts +1 -0
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +1 -1
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +92 -12
- package/dist/schema.js +2 -2
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +19 -25
- package/dist/yaml.d.ts +7 -3
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +72 -43
- package/fixtures/README.md +1 -1
- package/package.json +4 -2
package/dist/yaml.js
CHANGED
|
@@ -84,6 +84,30 @@ export function interpretPlain(text) {
|
|
|
84
84
|
return Number(text);
|
|
85
85
|
return text;
|
|
86
86
|
}
|
|
87
|
+
const ESCAPES = {
|
|
88
|
+
b: '\b',
|
|
89
|
+
f: '\f',
|
|
90
|
+
n: '\n',
|
|
91
|
+
r: '\r',
|
|
92
|
+
t: '\t',
|
|
93
|
+
'"': '"',
|
|
94
|
+
'/': '/',
|
|
95
|
+
'\\': '\\',
|
|
96
|
+
};
|
|
97
|
+
function parseEscape(c) {
|
|
98
|
+
c.i += 1;
|
|
99
|
+
const escaped = peek(c);
|
|
100
|
+
const held = ESCAPES[escaped];
|
|
101
|
+
if (held !== undefined) {
|
|
102
|
+
c.i += 1;
|
|
103
|
+
return held;
|
|
104
|
+
}
|
|
105
|
+
const hex = c.text.slice(c.i + 1, c.i + 5);
|
|
106
|
+
if (escaped !== 'u' || c.i + 5 > c.end || !/^[0-9A-Fa-f]{4}$/.test(hex))
|
|
107
|
+
throw new YamlError(c.i);
|
|
108
|
+
c.i += 5;
|
|
109
|
+
return String.fromCharCode(Number.parseInt(hex, 16));
|
|
110
|
+
}
|
|
87
111
|
function parseQuoted(c) {
|
|
88
112
|
const quote = peek(c);
|
|
89
113
|
const start = c.i;
|
|
@@ -91,31 +115,19 @@ function parseQuoted(c) {
|
|
|
91
115
|
let out = '';
|
|
92
116
|
while (c.i < c.end) {
|
|
93
117
|
const ch = peek(c);
|
|
118
|
+
if (quote === "'" && ch === "'" && c.i + 1 < c.end && c.text[c.i + 1] === "'") {
|
|
119
|
+
out += "'";
|
|
120
|
+
c.i += 2;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
94
123
|
if (ch === quote) {
|
|
95
124
|
c.i += 1;
|
|
96
125
|
return scalar(out, start, c.i);
|
|
97
126
|
}
|
|
98
127
|
if (ch === '\n' || ch === '\r')
|
|
99
128
|
throw new YamlError(c.i);
|
|
100
|
-
if (quote === "'" && ch === "'" && c.text[c.i + 1] === "'") {
|
|
101
|
-
out += "'";
|
|
102
|
-
c.i += 2;
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
129
|
if (quote === '"' && ch === '\\') {
|
|
106
|
-
|
|
107
|
-
const escaped = peek(c);
|
|
108
|
-
if (escaped === 'n')
|
|
109
|
-
out += '\n';
|
|
110
|
-
else if (escaped === 't')
|
|
111
|
-
out += '\t';
|
|
112
|
-
else if (escaped === '"')
|
|
113
|
-
out += '"';
|
|
114
|
-
else if (escaped === '\\')
|
|
115
|
-
out += '\\';
|
|
116
|
-
else
|
|
117
|
-
throw new YamlError(c.i);
|
|
118
|
-
c.i += 1;
|
|
130
|
+
out += parseEscape(c);
|
|
119
131
|
continue;
|
|
120
132
|
}
|
|
121
133
|
out += ch;
|
|
@@ -208,11 +220,12 @@ function parseFlowMap(c) {
|
|
|
208
220
|
if (peek(c) !== ':')
|
|
209
221
|
throw new YamlError(c.i);
|
|
210
222
|
c.i += 1;
|
|
223
|
+
const after = c.i;
|
|
211
224
|
const value = parseFlowValue(c);
|
|
212
225
|
if (seen.has(key.name))
|
|
213
226
|
throw new YamlError(key.start);
|
|
214
227
|
seen.add(key.name);
|
|
215
|
-
entries.push({ key: key.name,
|
|
228
|
+
entries.push({ key: key.name, after, value });
|
|
216
229
|
skipFlowSpace(c);
|
|
217
230
|
if (peek(c) === ',') {
|
|
218
231
|
c.i += 1;
|
|
@@ -254,6 +267,7 @@ function parseFlowSeq(c) {
|
|
|
254
267
|
throw new YamlError(c.i);
|
|
255
268
|
}
|
|
256
269
|
function parseValue(c, parentKeyIndent) {
|
|
270
|
+
const at = c.i;
|
|
257
271
|
skipSpaces(c);
|
|
258
272
|
if (peek(c) === '#')
|
|
259
273
|
skipToEol(c);
|
|
@@ -262,12 +276,12 @@ function parseValue(c, parentKeyIndent) {
|
|
|
262
276
|
skipEol(c);
|
|
263
277
|
skipBlankAndComments(c);
|
|
264
278
|
if (c.i >= c.end)
|
|
265
|
-
return scalar(null,
|
|
279
|
+
return scalar(null, at, at);
|
|
266
280
|
const nextIndent = indentAt(c);
|
|
267
281
|
if (nextIndent === parentKeyIndent && seqAhead(c))
|
|
268
282
|
return parseBlockSeq(c, nextIndent);
|
|
269
283
|
if (nextIndent <= parentKeyIndent)
|
|
270
|
-
return scalar(null,
|
|
284
|
+
return scalar(null, at, at);
|
|
271
285
|
if (peek(c) === '-')
|
|
272
286
|
return parseBlockSeq(c, nextIndent);
|
|
273
287
|
if (peek(c) === '[')
|
|
@@ -315,9 +329,6 @@ function lineStartOf(c) {
|
|
|
315
329
|
j -= 1;
|
|
316
330
|
return j;
|
|
317
331
|
}
|
|
318
|
-
function valueEnd(value, marked) {
|
|
319
|
-
return value.kind === 'scalar' && value.start === value.end ? marked : value.end;
|
|
320
|
-
}
|
|
321
332
|
function parseSeqItem(c, indent) {
|
|
322
333
|
skipSpaces(c);
|
|
323
334
|
if (peek(c) !== '#' && peek(c) !== '\n' && peek(c) !== '\r' && c.i < c.end && mappingAhead(c))
|
|
@@ -337,10 +348,9 @@ function parseBlockSeq(c, indent) {
|
|
|
337
348
|
if (peek(c) !== '-')
|
|
338
349
|
break;
|
|
339
350
|
c.i += 1;
|
|
340
|
-
const marked = c.i;
|
|
341
351
|
const item = parseSeqItem(c, indent);
|
|
342
352
|
items.push(item);
|
|
343
|
-
end =
|
|
353
|
+
end = item.end;
|
|
344
354
|
}
|
|
345
355
|
return { kind: 'seq', items, start, end };
|
|
346
356
|
}
|
|
@@ -366,13 +376,13 @@ function parseBlockMap(c, indent, inline = false) {
|
|
|
366
376
|
if (peek(c) !== ':')
|
|
367
377
|
throw new YamlError(c.i);
|
|
368
378
|
c.i += 1;
|
|
369
|
-
const
|
|
379
|
+
const after = c.i;
|
|
370
380
|
const value = parseValue(c, indent);
|
|
371
381
|
if (seen.has(key.name))
|
|
372
382
|
throw new YamlError(key.start);
|
|
373
383
|
seen.add(key.name);
|
|
374
|
-
entries.push({ key: key.name,
|
|
375
|
-
end =
|
|
384
|
+
entries.push({ key: key.name, after, value });
|
|
385
|
+
end = value.end;
|
|
376
386
|
}
|
|
377
387
|
return { kind: 'map', entries, start, end };
|
|
378
388
|
}
|
|
@@ -418,24 +428,42 @@ export function isPlainSafe(text) {
|
|
|
418
428
|
return false;
|
|
419
429
|
return true;
|
|
420
430
|
}
|
|
431
|
+
export function plain(value) {
|
|
432
|
+
if (!isRecord(value))
|
|
433
|
+
return false;
|
|
434
|
+
const prototype = Object.getPrototypeOf(value);
|
|
435
|
+
return prototype === Object.prototype || prototype === null;
|
|
436
|
+
}
|
|
437
|
+
function listed(value) {
|
|
438
|
+
const keys = Object.keys(value);
|
|
439
|
+
return keys.length === value.length && keys.every((key, index) => key === String(index));
|
|
440
|
+
}
|
|
441
|
+
function heldWithin(value, within) {
|
|
442
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean')
|
|
443
|
+
return true;
|
|
444
|
+
if (typeof value === 'number')
|
|
445
|
+
return Number.isFinite(value);
|
|
446
|
+
if (typeof value !== 'object' || within.includes(value))
|
|
447
|
+
return false;
|
|
448
|
+
const path = [...within, value];
|
|
449
|
+
const held = (item) => heldWithin(item, path);
|
|
450
|
+
if (Array.isArray(value))
|
|
451
|
+
return listed(value) && value.every(held);
|
|
452
|
+
return plain(value) && Object.values(value).every(held);
|
|
453
|
+
}
|
|
454
|
+
export function frontmatterValue(value) {
|
|
455
|
+
return heldWithin(value, []);
|
|
456
|
+
}
|
|
421
457
|
export function serializeJs(value) {
|
|
422
|
-
if (value === null)
|
|
423
|
-
return 'null';
|
|
424
|
-
if (value === true)
|
|
425
|
-
return 'true';
|
|
426
|
-
if (value === false)
|
|
427
|
-
return 'false';
|
|
428
|
-
if (typeof value === 'number' && Number.isFinite(value))
|
|
429
|
-
return JSON.stringify(value);
|
|
430
458
|
if (typeof value === 'string')
|
|
431
459
|
return isPlainSafe(value) ? value : JSON.stringify(value);
|
|
460
|
+
if (value === null || typeof value !== 'object')
|
|
461
|
+
return JSON.stringify(value);
|
|
432
462
|
if (Array.isArray(value))
|
|
433
463
|
return `[${value.map(serializeJs).join(', ')}]`;
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
.join(', ')}}`;
|
|
438
|
-
throw new YamlError(0);
|
|
464
|
+
return `{${Object.entries(value)
|
|
465
|
+
.map(([key, held]) => `${serializeKey(key)}: ${serializeJs(held)}`)
|
|
466
|
+
.join(', ')}}`;
|
|
439
467
|
}
|
|
440
468
|
export function isRecord(value) {
|
|
441
469
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -485,7 +513,8 @@ export function equalValue(left, right) {
|
|
|
485
513
|
if (left === right)
|
|
486
514
|
return true;
|
|
487
515
|
if (Array.isArray(left) && Array.isArray(right)) {
|
|
488
|
-
return (left.length === right.length &&
|
|
516
|
+
return (left.length === right.length &&
|
|
517
|
+
Array.from(left).every((item, index) => equalValue(item, right[index])));
|
|
489
518
|
}
|
|
490
519
|
if (isRecord(left) && isRecord(right)) {
|
|
491
520
|
const keys = Object.keys(left);
|
package/fixtures/README.md
CHANGED
|
@@ -136,6 +136,6 @@ Library is accepted too, so `unresolved-link` never names it and
|
|
|
136
136
|
## YAML subset
|
|
137
137
|
|
|
138
138
|
Frontmatter and a schema text are each a mapping in a closed YAML subset: block and flow mappings,
|
|
139
|
-
block and flow sequences, a block sequence item that opens a mapping, plain and quoted scalars, `true`, `false`, `null`,
|
|
139
|
+
block and flow sequences, a block sequence item that opens a mapping, plain and quoted scalars (a single-quoted scalar doubles its apostrophe, a double-quoted one takes JSON's escapes), `true`, `false`, `null`,
|
|
140
140
|
and decimal numbers. It does not take YAML 1.1 boolean or timestamp aliases,
|
|
141
141
|
octal numbers, anchors, tags, or block scalars. A mapping carries each key once.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/mdmodel",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-c2224db91aaa3",
|
|
4
4
|
"description": "MD Type language, parser, validator, structured change application, Markdown syntax profile, and conformance fixtures",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
"README.md"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@cfworker/json-schema": "4.1.1"
|
|
29
|
+
"@cfworker/json-schema": "4.1.1",
|
|
30
|
+
"decode-named-character-reference": "1.3.0",
|
|
31
|
+
"micromark-util-decode-numeric-character-reference": "2.0.2"
|
|
30
32
|
}
|
|
31
33
|
}
|