@agentshouse/mdmodel 0.1.0-alpha.8 → 0.1.0-c83456e1cebfb

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.
Files changed (205) hide show
  1. package/API.md +298 -0
  2. package/README.md +29 -172
  3. package/dist/blocks.d.ts +11 -0
  4. package/dist/blocks.d.ts.map +1 -0
  5. package/dist/blocks.js +62 -0
  6. package/dist/definition.d.ts +15 -9
  7. package/dist/definition.d.ts.map +1 -1
  8. package/dist/definition.js +148 -133
  9. package/dist/divide.d.ts +3 -0
  10. package/dist/divide.d.ts.map +1 -0
  11. package/dist/divide.js +310 -0
  12. package/dist/document.d.ts +2 -0
  13. package/dist/document.d.ts.map +1 -1
  14. package/dist/document.js +89 -120
  15. package/dist/fields.d.ts +4 -0
  16. package/dist/fields.d.ts.map +1 -0
  17. package/dist/fields.js +3 -0
  18. package/dist/index.d.ts +6 -2
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +4 -3
  21. package/dist/links.d.ts +1 -0
  22. package/dist/links.d.ts.map +1 -1
  23. package/dist/links.js +618 -224
  24. package/dist/paths.d.ts +2 -3
  25. package/dist/paths.d.ts.map +1 -1
  26. package/dist/paths.js +27 -37
  27. package/dist/profile.js +1 -3
  28. package/dist/project.d.ts +19 -1
  29. package/dist/project.d.ts.map +1 -1
  30. package/dist/project.js +83 -73
  31. package/dist/refuse.d.ts.map +1 -1
  32. package/dist/refuse.js +2 -10
  33. package/dist/schema.d.ts +2 -1
  34. package/dist/schema.d.ts.map +1 -1
  35. package/dist/schema.js +22 -33
  36. package/dist/sections.d.ts +2 -1
  37. package/dist/sections.d.ts.map +1 -1
  38. package/dist/sections.js +45 -67
  39. package/dist/types.d.ts +30 -2
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/types.js +1 -3
  42. package/dist/validate.d.ts +3 -2
  43. package/dist/validate.d.ts.map +1 -1
  44. package/dist/validate.js +145 -122
  45. package/dist/version.d.ts +1 -1
  46. package/dist/version.d.ts.map +1 -1
  47. package/dist/version.js +1 -3
  48. package/dist/yaml.d.ts +1 -0
  49. package/dist/yaml.d.ts.map +1 -1
  50. package/dist/yaml.js +196 -187
  51. package/fixtures/README.md +77 -52
  52. package/fixtures/cases/binary-any-reference/expected.json +0 -1
  53. package/fixtures/cases/binary-any-reference/schema.yaml +4 -0
  54. package/fixtures/cases/binary-document-collision/expected.json +1 -2
  55. package/fixtures/cases/binary-document-collision/schema.yaml +2 -0
  56. package/fixtures/cases/binary-link-outside-collection/expected.json +1 -2
  57. package/fixtures/cases/binary-link-outside-collection/schema.yaml +2 -0
  58. package/fixtures/cases/binary-prototype-reference/expected.json +0 -1
  59. package/fixtures/cases/binary-prototype-reference/schema.yaml +4 -0
  60. package/fixtures/cases/binary-typed-reference/expected.json +0 -1
  61. package/fixtures/cases/binary-typed-reference/schema.yaml +5 -0
  62. package/fixtures/cases/bracketed-link-definition/schema.yaml +6 -0
  63. package/fixtures/cases/declared-binary-links/schema.yaml +2 -0
  64. package/fixtures/cases/duplicate-link-definition/schema.yaml +6 -0
  65. package/fixtures/cases/fenced-link-definition/schema.yaml +6 -0
  66. package/fixtures/cases/field-enum/expected.json +1 -2
  67. package/fixtures/cases/field-enum/schema.yaml +7 -0
  68. package/fixtures/cases/frontmatter-schema/expected.json +5 -0
  69. package/fixtures/cases/frontmatter-schema/schema.yaml +6 -0
  70. package/fixtures/cases/interrupted-link-definition/schema.yaml +2 -0
  71. package/fixtures/cases/long-fence-link-definition/schema.yaml +2 -0
  72. package/fixtures/cases/malformed-definition/expected.json +2 -4
  73. package/fixtures/cases/malformed-definition/schema.yaml +4 -0
  74. package/fixtures/cases/member-document/context.json +1 -0
  75. package/fixtures/cases/member-document/library/people/ana.md +5 -0
  76. package/fixtures/cases/member-document/schema.yaml +5 -0
  77. package/fixtures/cases/missing-binary-image/expected.json +1 -2
  78. package/fixtures/cases/missing-binary-image/schema.yaml +2 -0
  79. package/fixtures/cases/missing-binary-link/expected.json +1 -2
  80. package/fixtures/cases/missing-binary-link/schema.yaml +2 -0
  81. package/fixtures/cases/missing-required-field/expected.json +1 -2
  82. package/fixtures/cases/missing-required-field/schema.yaml +7 -0
  83. package/fixtures/cases/missing-section-item-kind/context.json +1 -0
  84. package/fixtures/cases/missing-section-item-kind/expected.json +5 -0
  85. package/fixtures/cases/missing-section-item-kind/schema.yaml +6 -0
  86. package/fixtures/cases/paragraph-link-definition/schema.yaml +2 -0
  87. package/fixtures/cases/prototype-field/context.json +1 -0
  88. package/fixtures/cases/prototype-field/expected.json +6 -0
  89. package/fixtures/cases/prototype-field/library/item.md +9 -0
  90. package/fixtures/cases/prototype-field/schema.yaml +6 -0
  91. package/fixtures/cases/quoted-link-definition/expected.json +1 -2
  92. package/fixtures/cases/quoted-link-definition/schema.yaml +2 -0
  93. package/fixtures/cases/referenced-missing-file/expected.json +0 -1
  94. package/fixtures/cases/referenced-missing-file/schema.yaml +10 -0
  95. package/fixtures/cases/second-member-document/context.json +1 -0
  96. package/fixtures/cases/second-member-document/expected.json +5 -0
  97. package/fixtures/cases/second-member-document/schema.yaml +5 -0
  98. package/fixtures/cases/section-item-enum/context.json +1 -0
  99. package/fixtures/cases/section-item-enum/expected.json +6 -0
  100. package/fixtures/cases/section-item-enum/library/task.md +8 -0
  101. package/fixtures/cases/section-item-enum/schema.yaml +4 -0
  102. package/fixtures/cases/section-item-kind/context.json +1 -0
  103. package/fixtures/cases/section-item-kind/expected.json +6 -0
  104. package/fixtures/cases/section-item-kind/library/task.md +8 -0
  105. package/fixtures/cases/section-item-kind/schema.yaml +4 -0
  106. package/fixtures/cases/section-items/context.json +1 -0
  107. package/fixtures/cases/section-items/expected.json +1 -0
  108. package/fixtures/cases/section-items/library/other.md +3 -0
  109. package/fixtures/cases/section-items/library/page.md +28 -0
  110. package/fixtures/cases/section-items/schema.yaml +8 -0
  111. package/fixtures/cases/section-reference-path/context.json +1 -0
  112. package/fixtures/cases/section-reference-path/expected.json +6 -0
  113. package/fixtures/cases/section-reference-path/library/other.md +3 -0
  114. package/fixtures/cases/section-reference-path/library/page.md +7 -0
  115. package/fixtures/cases/section-reference-path/schema.yaml +4 -0
  116. package/fixtures/cases/section-reference-type/context.json +1 -0
  117. package/fixtures/cases/section-reference-type/expected.json +6 -0
  118. package/fixtures/cases/section-reference-type/library/note.md +1 -0
  119. package/fixtures/cases/section-reference-type/library/page.md +7 -0
  120. package/fixtures/cases/section-reference-type/schema.yaml +4 -0
  121. package/fixtures/cases/shortcut-reference-link/context.json +1 -0
  122. package/fixtures/cases/shortcut-reference-link/expected.json +5 -0
  123. package/fixtures/cases/shortcut-reference-link/library/item.md +10 -0
  124. package/fixtures/cases/shortcut-reference-link/schema.yaml +6 -0
  125. package/fixtures/cases/structured-section/expected.json +1 -2
  126. package/fixtures/cases/structured-section/schema.yaml +7 -0
  127. package/fixtures/cases/submission-keys/context.json +1 -0
  128. package/fixtures/cases/submission-keys/expected.json +1 -0
  129. package/fixtures/cases/submission-keys/library/notes/visitor.md +8 -0
  130. package/fixtures/cases/submission-keys/schema.yaml +4 -0
  131. package/fixtures/cases/text-field-kind/context.json +1 -0
  132. package/fixtures/cases/text-field-kind/expected.json +6 -0
  133. package/fixtures/cases/text-field-kind/library/page.md +4 -0
  134. package/fixtures/cases/text-field-kind/schema.yaml +4 -0
  135. package/fixtures/cases/truncated-link-definition/expected.json +1 -2
  136. package/fixtures/cases/truncated-link-definition/schema.yaml +2 -0
  137. package/fixtures/cases/types-folder-content/context.json +1 -0
  138. package/fixtures/cases/types-folder-content/expected.json +1 -0
  139. package/fixtures/cases/types-folder-content/library/types/task.md +4 -0
  140. package/fixtures/cases/types-folder-content/schema.yaml +4 -0
  141. package/fixtures/cases/unclosed-frontmatter/expected.json +1 -2
  142. package/fixtures/cases/undeclared-field/context.json +1 -0
  143. package/fixtures/cases/undeclared-field/expected.json +6 -0
  144. package/fixtures/cases/undeclared-field/library/item.md +9 -0
  145. package/fixtures/cases/undeclared-field/schema.yaml +6 -0
  146. package/fixtures/cases/unknown-type/context.json +1 -0
  147. package/fixtures/cases/unknown-type/expected.json +6 -0
  148. package/fixtures/cases/unknown-type/library/item.md +3 -0
  149. package/fixtures/cases/unknown-type/schema.yaml +4 -0
  150. package/fixtures/cases/unlisted-reference-type/context.json +1 -0
  151. package/fixtures/cases/unlisted-reference-type/expected.json +5 -0
  152. package/fixtures/cases/unlisted-reference-type/schema.yaml +4 -0
  153. package/fixtures/cases/unresolved-link/expected.json +1 -2
  154. package/fixtures/cases/unresolved-link/schema.yaml +6 -0
  155. package/fixtures/cases/valid-typed-document/library/tasks/one.md +1 -0
  156. package/fixtures/cases/valid-typed-document/schema.yaml +15 -0
  157. package/fixtures/cases/wide-item-fence-link/schema.yaml +2 -0
  158. package/fixtures/division.json +409 -0
  159. package/fixtures/projection.json +77 -28
  160. package/package.json +3 -12
  161. package/dist/definition.js.map +0 -1
  162. package/dist/document.js.map +0 -1
  163. package/dist/index.js.map +0 -1
  164. package/dist/links.js.map +0 -1
  165. package/dist/paths.js.map +0 -1
  166. package/dist/profile.js.map +0 -1
  167. package/dist/project.js.map +0 -1
  168. package/dist/refuse.js.map +0 -1
  169. package/dist/schema.js.map +0 -1
  170. package/dist/sections.js.map +0 -1
  171. package/dist/types.js.map +0 -1
  172. package/dist/validate.js.map +0 -1
  173. package/dist/version.js.map +0 -1
  174. package/dist/yaml.js.map +0 -1
  175. package/fixtures/cases/binary-any-reference/library/types/note.md +0 -5
  176. package/fixtures/cases/binary-document-collision/library/types/note.md +0 -3
  177. package/fixtures/cases/binary-link-outside-collection/library/types/note.md +0 -3
  178. package/fixtures/cases/binary-prototype-reference/library/types/note.md +0 -5
  179. package/fixtures/cases/binary-typed-reference/library/types/note.md +0 -5
  180. package/fixtures/cases/binary-typed-reference/library/types/person.md +0 -3
  181. package/fixtures/cases/bracketed-link-definition/library/types/task.md +0 -7
  182. package/fixtures/cases/declared-binary-links/library/types/note.md +0 -3
  183. package/fixtures/cases/duplicate-link-definition/library/types/task.md +0 -7
  184. package/fixtures/cases/fenced-link-definition/library/types/task.md +0 -7
  185. package/fixtures/cases/field-enum/library/types/task.md +0 -8
  186. package/fixtures/cases/interrupted-link-definition/library/types/note.md +0 -3
  187. package/fixtures/cases/long-fence-link-definition/library/types/note.md +0 -3
  188. package/fixtures/cases/malformed-definition/library/types/task.md +0 -5
  189. package/fixtures/cases/missing-binary-image/library/types/note.md +0 -3
  190. package/fixtures/cases/missing-binary-link/library/types/note.md +0 -3
  191. package/fixtures/cases/missing-required-field/library/types/task.md +0 -8
  192. package/fixtures/cases/paragraph-link-definition/library/types/note.md +0 -3
  193. package/fixtures/cases/prd-definition/library/types/task.md +0 -15
  194. package/fixtures/cases/quoted-link-definition/library/types/note.md +0 -3
  195. package/fixtures/cases/referenced-missing-file/library/types/person.md +0 -5
  196. package/fixtures/cases/referenced-missing-file/library/types/task.md +0 -8
  197. package/fixtures/cases/structured-section/library/types/task.md +0 -8
  198. package/fixtures/cases/truncated-link-definition/library/types/note.md +0 -3
  199. package/fixtures/cases/unresolved-link/library/types/task.md +0 -7
  200. package/fixtures/cases/valid-typed-document/library/types/person.md +0 -5
  201. package/fixtures/cases/valid-typed-document/library/types/task.md +0 -12
  202. package/fixtures/cases/wide-item-fence-link/library/types/note.md +0 -3
  203. package/markdown-syntax-profile.md +0 -9
  204. /package/fixtures/cases/{prd-definition → frontmatter-schema}/context.json +0 -0
  205. /package/fixtures/cases/{prd-definition → member-document}/expected.json +0 -0
package/dist/yaml.js CHANGED
@@ -1,7 +1,8 @@
1
1
  export class YamlError extends Error {
2
2
  offset;
3
- constructor(offset){
4
- super('yaml'), this.offset = offset;
3
+ constructor(offset) {
4
+ super('yaml');
5
+ this.offset = offset;
5
6
  this.name = 'YamlError';
6
7
  }
7
8
  }
@@ -9,20 +10,26 @@ function peek(c) {
9
10
  return c.i < c.end ? c.text[c.i] : '';
10
11
  }
11
12
  function skipEol(c) {
12
- if (peek(c) === '\r') c.i += 1;
13
- if (peek(c) === '\n') c.i += 1;
13
+ if (peek(c) === '\r')
14
+ c.i += 1;
15
+ if (peek(c) === '\n')
16
+ c.i += 1;
14
17
  }
15
18
  function skipSpaces(c) {
16
- while(peek(c) === ' ')c.i += 1;
17
- if (peek(c) === '\t') throw new YamlError(c.i);
19
+ while (peek(c) === ' ')
20
+ c.i += 1;
21
+ if (peek(c) === '\t')
22
+ throw new YamlError(c.i);
18
23
  }
19
24
  function skipToEol(c) {
20
- while(c.i < c.end && peek(c) !== '\n' && peek(c) !== '\r')c.i += 1;
25
+ while (c.i < c.end && peek(c) !== '\n' && peek(c) !== '\r')
26
+ c.i += 1;
21
27
  }
22
28
  function skipBlankAndComments(c) {
23
- while(c.i < c.end){
29
+ while (c.i < c.end) {
24
30
  skipSpaces(c);
25
- if (peek(c) === '#') skipToEol(c);
31
+ if (peek(c) === '#')
32
+ skipToEol(c);
26
33
  if (peek(c) === '\r' || peek(c) === '\n') {
27
34
  skipEol(c);
28
35
  continue;
@@ -31,7 +38,7 @@ function skipBlankAndComments(c) {
31
38
  }
32
39
  }
33
40
  function skipFlowSpace(c) {
34
- while(c.i < c.end){
41
+ while (c.i < c.end) {
35
42
  const ch = peek(c);
36
43
  if (ch === ' ' || ch === '\n' || ch === '\r') {
37
44
  c.i += 1;
@@ -41,36 +48,40 @@ function skipFlowSpace(c) {
41
48
  skipToEol(c);
42
49
  continue;
43
50
  }
44
- if (ch === '\t') throw new YamlError(c.i);
51
+ if (ch === '\t')
52
+ throw new YamlError(c.i);
45
53
  break;
46
54
  }
47
55
  }
48
56
  function indentAt(c) {
49
57
  let j = c.i;
50
- while(j > 0 && c.text[j - 1] !== '\n')j -= 1;
58
+ while (j > 0 && c.text[j - 1] !== '\n' && c.text[j - 1] !== '\r')
59
+ j -= 1;
51
60
  let n = 0;
52
- while(j < c.i){
61
+ while (j < c.i) {
53
62
  const ch = c.text[j];
54
- if (ch === ' ') n += 1;
55
- else if (ch === '\t') throw new YamlError(j);
56
- else break;
63
+ if (ch === ' ')
64
+ n += 1;
65
+ else if (ch === '\t')
66
+ throw new YamlError(j);
67
+ else
68
+ break;
57
69
  j += 1;
58
70
  }
59
71
  return n;
60
72
  }
61
73
  function scalar(value, start, end) {
62
- return {
63
- kind: 'scalar',
64
- value,
65
- start,
66
- end
67
- };
68
- }
69
- function interpretPlain(text) {
70
- if (text === 'true') return true;
71
- if (text === 'false') return false;
72
- if (text === 'null' || text === '') return null;
73
- if (/^-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?$/.test(text)) return Number(text);
74
+ return { kind: 'scalar', value, start, end };
75
+ }
76
+ export function interpretPlain(text) {
77
+ if (text === 'true')
78
+ return true;
79
+ if (text === 'false')
80
+ return false;
81
+ if (text === 'null' || text === '')
82
+ return null;
83
+ if (/^-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?$/.test(text))
84
+ return Number(text);
74
85
  return text;
75
86
  }
76
87
  function parseQuoted(c) {
@@ -78,13 +89,14 @@ function parseQuoted(c) {
78
89
  const start = c.i;
79
90
  c.i += 1;
80
91
  let out = '';
81
- while(c.i < c.end){
92
+ while (c.i < c.end) {
82
93
  const ch = peek(c);
83
94
  if (ch === quote) {
84
95
  c.i += 1;
85
96
  return scalar(out, start, c.i);
86
97
  }
87
- if (ch === '\n' || ch === '\r') throw new YamlError(c.i);
98
+ if (ch === '\n' || ch === '\r')
99
+ throw new YamlError(c.i);
88
100
  if (quote === "'" && ch === "'" && c.text[c.i + 1] === "'") {
89
101
  out += "'";
90
102
  c.i += 2;
@@ -93,11 +105,16 @@ function parseQuoted(c) {
93
105
  if (quote === '"' && ch === '\\') {
94
106
  c.i += 1;
95
107
  const escaped = peek(c);
96
- if (escaped === 'n') out += '\n';
97
- else if (escaped === 't') out += '\t';
98
- else if (escaped === '"') out += '"';
99
- else if (escaped === '\\') out += '\\';
100
- else throw new YamlError(c.i);
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);
101
118
  c.i += 1;
102
119
  continue;
103
120
  }
@@ -108,90 +125,94 @@ function parseQuoted(c) {
108
125
  }
109
126
  function parsePlain(c, flow) {
110
127
  const start = c.i;
111
- while(c.i < c.end){
128
+ while (c.i < c.end) {
112
129
  const ch = peek(c);
113
- if (flow && (ch === ',' || ch === ']' || ch === '}')) break;
114
- if (ch === '\n' || ch === '\r') break;
115
- if (ch === '#' && (c.i === start || c.text[c.i - 1] === ' ' || c.text[c.i - 1] === '\t')) break;
130
+ if (flow && (ch === ',' || ch === ']' || ch === '}'))
131
+ break;
132
+ if (ch === '\n' || ch === '\r')
133
+ break;
134
+ if (ch === '#' && (c.i === start || c.text[c.i - 1] === ' ' || c.text[c.i - 1] === '\t'))
135
+ break;
116
136
  c.i += 1;
117
137
  }
118
- if (c.i === start) throw new YamlError(c.i);
138
+ if (c.i === start)
139
+ throw new YamlError(c.i);
119
140
  const raw = c.text.slice(start, c.i);
120
141
  const trimmed = raw.trimEnd();
121
142
  return scalar(interpretPlain(trimmed), start, start + trimmed.length);
122
143
  }
123
144
  function parseScalar(c, flow) {
124
145
  const ch = peek(c);
125
- if (ch === '"' || ch === "'") return parseQuoted(c);
146
+ if (ch === '"' || ch === "'")
147
+ return parseQuoted(c);
126
148
  return parsePlain(c, flow);
127
149
  }
128
150
  function parseKey(c) {
129
151
  const start = c.i;
130
152
  if (peek(c) === '"' || peek(c) === "'") {
131
153
  const quoted = parseQuoted(c);
132
- if (typeof quoted.value !== 'string') throw new YamlError(start);
133
- return {
134
- name: quoted.value,
135
- start,
136
- end: c.i
137
- };
154
+ if (typeof quoted.value !== 'string')
155
+ throw new YamlError(start);
156
+ return { name: quoted.value, start, end: c.i };
138
157
  }
139
158
  let end = c.i;
140
- while(c.i < c.end){
159
+ while (c.i < c.end) {
141
160
  const ch = peek(c);
142
- if (ch === ':' || ch === '\n' || ch === '\r' || ch === ',' || ch === '}' || ch === ']' || ch === '#' || ch === '{' || ch === '[') {
161
+ if (ch === ':' ||
162
+ ch === '\n' ||
163
+ ch === '\r' ||
164
+ ch === ',' ||
165
+ ch === '}' ||
166
+ ch === ']' ||
167
+ ch === '#' ||
168
+ ch === '{' ||
169
+ ch === '[') {
143
170
  break;
144
171
  }
145
172
  c.i += 1;
146
- if (ch !== ' ' && ch !== '\t') end = c.i;
173
+ if (ch !== ' ' && ch !== '\t')
174
+ end = c.i;
147
175
  }
148
- if (end === start) throw new YamlError(c.i);
176
+ if (end === start)
177
+ throw new YamlError(c.i);
149
178
  c.i = end;
150
- return {
151
- name: c.text.slice(start, end),
152
- start,
153
- end
154
- };
179
+ return { name: c.text.slice(start, end), start, end };
155
180
  }
156
181
  function parseFlowValue(c) {
157
182
  skipFlowSpace(c);
158
183
  const ch = peek(c);
159
- if (ch === '{') return parseFlowMap(c);
160
- if (ch === '[') return parseFlowSeq(c);
161
- if (ch === '|' || ch === '>') throw new YamlError(c.i);
184
+ if (ch === '{')
185
+ return parseFlowMap(c);
186
+ if (ch === '[')
187
+ return parseFlowSeq(c);
188
+ if (ch === '|' || ch === '>')
189
+ throw new YamlError(c.i);
162
190
  return parseScalar(c, true);
163
191
  }
164
192
  function parseFlowMap(c) {
165
193
  const start = c.i;
166
- if (peek(c) !== '{') throw new YamlError(c.i);
194
+ if (peek(c) !== '{')
195
+ throw new YamlError(c.i);
167
196
  c.i += 1;
168
197
  skipFlowSpace(c);
169
198
  const entries = [];
170
199
  const seen = new Set();
171
200
  if (peek(c) === '}') {
172
201
  c.i += 1;
173
- return {
174
- kind: 'map',
175
- entries,
176
- start,
177
- end: c.i
178
- };
202
+ return { kind: 'map', entries, start, end: c.i };
179
203
  }
180
- while(c.i < c.end){
204
+ while (c.i < c.end) {
181
205
  skipFlowSpace(c);
182
206
  const key = parseKey(c);
183
207
  skipFlowSpace(c);
184
- if (peek(c) !== ':') throw new YamlError(c.i);
208
+ if (peek(c) !== ':')
209
+ throw new YamlError(c.i);
185
210
  c.i += 1;
186
211
  const value = parseFlowValue(c);
187
- if (seen.has(key.name)) throw new YamlError(key.start);
212
+ if (seen.has(key.name))
213
+ throw new YamlError(key.start);
188
214
  seen.add(key.name);
189
- entries.push({
190
- key: key.name,
191
- keyStart: key.start,
192
- keyEnd: key.end,
193
- value
194
- });
215
+ entries.push({ key: key.name, keyStart: key.start, keyEnd: key.end, value });
195
216
  skipFlowSpace(c);
196
217
  if (peek(c) === ',') {
197
218
  c.i += 1;
@@ -199,12 +220,7 @@ function parseFlowMap(c) {
199
220
  }
200
221
  if (peek(c) === '}') {
201
222
  c.i += 1;
202
- return {
203
- kind: 'map',
204
- entries,
205
- start,
206
- end: c.i
207
- };
223
+ return { kind: 'map', entries, start, end: c.i };
208
224
  }
209
225
  throw new YamlError(c.i);
210
226
  }
@@ -212,20 +228,16 @@ function parseFlowMap(c) {
212
228
  }
213
229
  function parseFlowSeq(c) {
214
230
  const start = c.i;
215
- if (peek(c) !== '[') throw new YamlError(c.i);
231
+ if (peek(c) !== '[')
232
+ throw new YamlError(c.i);
216
233
  c.i += 1;
217
234
  skipFlowSpace(c);
218
235
  const items = [];
219
236
  if (peek(c) === ']') {
220
237
  c.i += 1;
221
- return {
222
- kind: 'seq',
223
- items,
224
- start,
225
- end: c.i
226
- };
238
+ return { kind: 'seq', items, start, end: c.i };
227
239
  }
228
- while(c.i < c.end){
240
+ while (c.i < c.end) {
229
241
  items.push(parseFlowValue(c));
230
242
  skipFlowSpace(c);
231
243
  if (peek(c) === ',') {
@@ -235,12 +247,7 @@ function parseFlowSeq(c) {
235
247
  }
236
248
  if (peek(c) === ']') {
237
249
  c.i += 1;
238
- return {
239
- kind: 'seq',
240
- items,
241
- start,
242
- end: c.i
243
- };
250
+ return { kind: 'seq', items, start, end: c.i };
244
251
  }
245
252
  throw new YamlError(c.i);
246
253
  }
@@ -248,124 +255,133 @@ function parseFlowSeq(c) {
248
255
  }
249
256
  function parseValue(c, parentKeyIndent) {
250
257
  skipSpaces(c);
251
- if (peek(c) === '#') skipToEol(c);
258
+ if (peek(c) === '#')
259
+ skipToEol(c);
252
260
  const ch = peek(c);
253
261
  if (ch === '' || ch === '\n' || ch === '\r') {
254
262
  skipEol(c);
255
263
  skipBlankAndComments(c);
256
- if (c.i >= c.end) return scalar(null, c.i, c.i);
264
+ if (c.i >= c.end)
265
+ return scalar(null, c.i, c.i);
257
266
  const nextIndent = indentAt(c);
258
- if (nextIndent <= parentKeyIndent) return scalar(null, c.i, c.i);
259
- if (peek(c) === '-') return parseBlockSeq(c, nextIndent);
260
- if (peek(c) === '[') return parseFlowSeq(c);
261
- if (peek(c) === '{') return parseFlowMap(c);
267
+ if (nextIndent <= parentKeyIndent)
268
+ return scalar(null, c.i, c.i);
269
+ if (peek(c) === '-')
270
+ return parseBlockSeq(c, nextIndent);
271
+ if (peek(c) === '[')
272
+ return parseFlowSeq(c);
273
+ if (peek(c) === '{')
274
+ return parseFlowMap(c);
262
275
  return parseBlockMap(c, nextIndent);
263
276
  }
264
- if (ch === '{') return parseFlowMap(c);
265
- if (ch === '[') return parseFlowSeq(c);
266
- if (ch === '|' || ch === '>') throw new YamlError(c.i);
277
+ if (ch === '{')
278
+ return parseFlowMap(c);
279
+ if (ch === '[')
280
+ return parseFlowSeq(c);
281
+ if (ch === '|' || ch === '>')
282
+ throw new YamlError(c.i);
267
283
  return parseScalar(c, false);
268
284
  }
269
285
  function parseBlockSeq(c, indent) {
270
286
  const start = c.i;
271
287
  const items = [];
272
288
  let end = start;
273
- while(c.i < c.end){
289
+ while (c.i < c.end) {
274
290
  skipBlankAndComments(c);
275
- if (c.i >= c.end) break;
276
- if (indentAt(c) !== indent) break;
277
- if (peek(c) !== '-') break;
291
+ if (c.i >= c.end)
292
+ break;
293
+ if (indentAt(c) !== indent)
294
+ break;
295
+ if (peek(c) !== '-')
296
+ break;
278
297
  c.i += 1;
279
298
  items.push(parseValue(c, indent));
280
299
  end = c.i;
281
300
  }
282
- return {
283
- kind: 'seq',
284
- items,
285
- start,
286
- end
287
- };
301
+ return { kind: 'seq', items, start, end };
288
302
  }
289
303
  function parseBlockMap(c, indent) {
290
304
  const start = c.i;
291
305
  const entries = [];
292
306
  const seen = new Set();
293
307
  let end = start;
294
- while(c.i < c.end){
308
+ while (c.i < c.end) {
295
309
  skipBlankAndComments(c);
296
- if (c.i >= c.end) break;
297
- if (indentAt(c) < indent) break;
298
- if (indentAt(c) > indent) throw new YamlError(c.i);
310
+ if (c.i >= c.end)
311
+ break;
312
+ if (indentAt(c) < indent)
313
+ break;
314
+ if (indentAt(c) > indent)
315
+ throw new YamlError(c.i);
299
316
  const key = parseKey(c);
300
317
  skipSpaces(c);
301
- if (peek(c) !== ':') throw new YamlError(c.i);
318
+ if (peek(c) !== ':')
319
+ throw new YamlError(c.i);
302
320
  c.i += 1;
303
321
  const value = parseValue(c, indent);
304
- if (seen.has(key.name)) throw new YamlError(key.start);
322
+ if (seen.has(key.name))
323
+ throw new YamlError(key.start);
305
324
  seen.add(key.name);
306
- entries.push({
307
- key: key.name,
308
- keyStart: key.start,
309
- keyEnd: key.end,
310
- value
311
- });
325
+ entries.push({ key: key.name, keyStart: key.start, keyEnd: key.end, value });
312
326
  end = c.i;
313
327
  }
314
- return {
315
- kind: 'map',
316
- entries,
317
- start,
318
- end
319
- };
328
+ return { kind: 'map', entries, start, end };
320
329
  }
321
330
  export function parseYamlMapping(text, start, end) {
322
- const c = {
323
- text,
324
- i: start,
325
- end
326
- };
331
+ const c = { text, i: start, end };
327
332
  skipBlankAndComments(c);
328
- if (c.i >= end) return {
329
- kind: 'map',
330
- entries: [],
331
- start,
332
- end
333
- };
333
+ if (c.i >= end)
334
+ return { kind: 'map', entries: [], start, end };
334
335
  if (peek(c) === '{') {
335
336
  const mapped = parseFlowMap(c);
336
337
  skipBlankAndComments(c);
337
- if (c.i < end) throw new YamlError(c.i);
338
+ if (c.i < end)
339
+ throw new YamlError(c.i);
338
340
  return mapped;
339
341
  }
340
342
  const mapped = parseBlockMap(c, indentAt(c));
341
343
  skipBlankAndComments(c);
342
- if (c.i < end) throw new YamlError(c.i);
344
+ if (c.i < end)
345
+ throw new YamlError(c.i);
343
346
  return mapped;
344
347
  }
345
348
  export function jsValue(node) {
346
- if (node.kind === 'scalar') return node.value;
347
- if (node.kind === 'seq') return node.items.map(jsValue);
348
- const record = {};
349
- for (const entry of node.entries)record[entry.key] = jsValue(entry.value);
349
+ if (node.kind === 'scalar')
350
+ return node.value;
351
+ if (node.kind === 'seq')
352
+ return node.items.map(jsValue);
353
+ const record = Object.create(null);
354
+ for (const entry of node.entries)
355
+ record[entry.key] = jsValue(entry.value);
350
356
  return record;
351
357
  }
352
358
  export function mapEntry(map, key) {
353
- return map.entries.find((entry)=>entry.key === key);
359
+ return map.entries.find((entry) => entry.key === key);
354
360
  }
355
361
  export function isPlainSafe(text) {
356
- if (text === '' || text === 'true' || text === 'false' || text === 'null') return false;
357
- if (/[\s#:{}[\],&*!|>'"%@`]/.test(text)) return false;
358
- if (text.startsWith('-') || text.startsWith('?') || text.startsWith(':')) return false;
359
- if (/^-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?$/.test(text)) return false;
362
+ if (text === '' || text === 'true' || text === 'false' || text === 'null')
363
+ return false;
364
+ if (/[\s#:{}[\],&*!|>'"%@`]/.test(text))
365
+ return false;
366
+ if (text.startsWith('-') || text.startsWith('?') || text.startsWith(':'))
367
+ return false;
368
+ if (/^-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?$/.test(text))
369
+ return false;
360
370
  return true;
361
371
  }
362
372
  export function serializeJs(value) {
363
- if (value === null) return 'null';
364
- if (value === true) return 'true';
365
- if (value === false) return 'false';
366
- if (typeof value === 'number' && Number.isFinite(value)) return JSON.stringify(value);
367
- if (typeof value === 'string') return isPlainSafe(value) ? value : JSON.stringify(value);
368
- if (Array.isArray(value)) return `[${value.map(serializeJs).join(', ')}]`;
373
+ if (value === null)
374
+ return 'null';
375
+ if (value === true)
376
+ return 'true';
377
+ if (value === false)
378
+ return 'false';
379
+ if (typeof value === 'number' && Number.isFinite(value))
380
+ return JSON.stringify(value);
381
+ if (typeof value === 'string')
382
+ return isPlainSafe(value) ? value : JSON.stringify(value);
383
+ if (Array.isArray(value))
384
+ return `[${value.map(serializeJs).join(', ')}]`;
369
385
  throw new YamlError(0);
370
386
  }
371
387
  export function serializeKey(name) {
@@ -383,47 +399,40 @@ export function bodyAfterFrontmatter(content) {
383
399
  return content.slice(bodyStartOf(content));
384
400
  }
385
401
  export function extractFrontmatter(content) {
386
- if (!content.startsWith('---')) return {
387
- kind: 'none'
388
- };
402
+ if (!content.startsWith('---'))
403
+ return { kind: 'none' };
389
404
  const firstNl = content.indexOf('\n');
390
- const firstLine = firstNl === -1 ? content : content.slice(0, content[firstNl - 1] === '\r' ? firstNl - 1 : firstNl);
391
- if (!/^---[ \t]*$/.test(firstLine)) return {
392
- kind: 'none'
393
- };
394
- if (firstNl === -1) return {
395
- kind: 'unclosed'
396
- };
405
+ const firstLine = firstNl === -1
406
+ ? content
407
+ : content.slice(0, content[firstNl - 1] === '\r' ? firstNl - 1 : firstNl);
408
+ if (!/^---[ \t]*$/.test(firstLine))
409
+ return { kind: 'none' };
410
+ if (firstNl === -1)
411
+ return { kind: 'unclosed' };
397
412
  const yamlStart = firstNl + 1;
398
413
  let i = yamlStart;
399
- while(i <= content.length){
414
+ while (i <= content.length) {
400
415
  const nl = content.indexOf('\n', i);
401
416
  const lineEnd = nl === -1 ? content.length : nl;
402
417
  let line = content.slice(i, lineEnd);
403
- if (line.endsWith('\r')) line = line.slice(0, -1);
404
- if (/^---[ \t]*$/.test(line)) return {
405
- kind: 'ok',
406
- yamlStart,
407
- yamlEnd: i
408
- };
409
- if (nl === -1) return {
410
- kind: 'unclosed'
411
- };
418
+ if (line.endsWith('\r'))
419
+ line = line.slice(0, -1);
420
+ if (/^---[ \t]*$/.test(line))
421
+ return { kind: 'ok', yamlStart, yamlEnd: i };
422
+ if (nl === -1)
423
+ return { kind: 'unclosed' };
412
424
  i = nl + 1;
413
425
  }
414
- return {
415
- kind: 'unclosed'
416
- };
426
+ return { kind: 'unclosed' };
417
427
  }
418
428
  export function equalValue(left, right) {
419
- if (left === right) return true;
429
+ if (left === right)
430
+ return true;
420
431
  if (Array.isArray(left) && Array.isArray(right)) {
421
- return left.length === right.length && left.every((item, index)=>equalValue(item, right[index]));
432
+ return (left.length === right.length && left.every((item, index) => equalValue(item, right[index])));
422
433
  }
423
434
  return false;
424
435
  }
425
436
  export function lineEnding(content) {
426
437
  return content.includes('\r\n') ? '\r\n' : '\n';
427
438
  }
428
-
429
- //# sourceMappingURL=yaml.js.map