@netfoundry/docusaurus-shared 0.0.168

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 (112) hide show
  1. package/dist/components/Alert/Alert.d.ts +8 -0
  2. package/dist/components/Alert/index.d.ts +2 -0
  3. package/dist/components/CodeBlock/CodeBlock.d.ts +9 -0
  4. package/dist/components/CodeBlock/index.d.ts +2 -0
  5. package/dist/components/Common/Common.d.ts +23 -0
  6. package/dist/components/Common/index.d.ts +1 -0
  7. package/dist/components/NetFoundry/Divider/Divider.d.ts +2 -0
  8. package/dist/components/NetFoundry/Divider/index.d.ts +1 -0
  9. package/dist/components/NetFoundry/index.d.ts +1 -0
  10. package/dist/components/NetFoundryFooter/NetFoundryFooter.d.ts +22 -0
  11. package/dist/components/NetFoundryFooter/index.d.ts +1 -0
  12. package/dist/components/NetFoundryHighlight/NetFoundryHighlight.d.ts +6 -0
  13. package/dist/components/NetFoundryHighlight/index.d.ts +2 -0
  14. package/dist/components/NetFoundryHorizontalSection/NetFoundryHorizontalSection.d.ts +8 -0
  15. package/dist/components/NetFoundryHorizontalSection/index.d.ts +2 -0
  16. package/dist/components/NetFoundryLayout/NetFoundryLayout.d.ts +29 -0
  17. package/dist/components/NetFoundryLayout/index.d.ts +1 -0
  18. package/dist/components/NetFoundryNavbarItems/NetFoundryNavbarItems.d.ts +9 -0
  19. package/dist/components/NetFoundryNavbarItems/index.d.ts +2 -0
  20. package/dist/components/OsTabs/OsTabs.d.ts +5 -0
  21. package/dist/components/OsTabs/index.d.ts +2 -0
  22. package/dist/components/StarUs/StarUs.d.ts +6 -0
  23. package/dist/components/StarUs/index.d.ts +2 -0
  24. package/dist/components/index.d.ts +11 -0
  25. package/dist/docusaurus-envhelper.d.ts +15 -0
  26. package/dist/docusaurus-plugins/index.d.ts +7 -0
  27. package/dist/docusaurus-plugins/logger.d.ts +12 -0
  28. package/dist/docusaurus-plugins/remarkCodeSections.d.ts +7 -0
  29. package/dist/docusaurus-plugins/remarkReplaceMetaUrl.d.ts +10 -0
  30. package/dist/docusaurus-plugins/remarkScopedPath.d.ts +12 -0
  31. package/dist/docusaurus-plugins/remarkYamlTable.d.ts +7 -0
  32. package/dist/docusaurus-plugins/remarkYouTube.d.ts +7 -0
  33. package/dist/docusaurus-plugins/timedPlugin.d.ts +5 -0
  34. package/dist/index.cjs +8 -0
  35. package/dist/index.cjs.map +1 -0
  36. package/dist/index.css +1 -0
  37. package/dist/index.d.ts +1 -0
  38. package/dist/index.esm.js +6 -0
  39. package/dist/index.esm.js.map +1 -0
  40. package/dist/node.cjs +80 -0
  41. package/dist/node.cjs.map +1 -0
  42. package/dist/node.d.ts +1 -0
  43. package/dist/node.esm.js +68 -0
  44. package/dist/node.esm.js.map +1 -0
  45. package/dist/plugins.cjs +4643 -0
  46. package/dist/plugins.cjs.map +1 -0
  47. package/dist/plugins.d.ts +1 -0
  48. package/dist/plugins.esm.js +4634 -0
  49. package/dist/plugins.esm.js.map +1 -0
  50. package/dist/ui.cjs +1312 -0
  51. package/dist/ui.cjs.map +1 -0
  52. package/dist/ui.d.ts +2 -0
  53. package/dist/ui.esm.js +1284 -0
  54. package/dist/ui.esm.js.map +1 -0
  55. package/dist/version.cjs +6 -0
  56. package/dist/version.cjs.map +1 -0
  57. package/dist/version.d.ts +1 -0
  58. package/dist/version.esm.js +4 -0
  59. package/dist/version.esm.js.map +1 -0
  60. package/package.json +82 -0
  61. package/src/components/Alert/Alert.module.css +39 -0
  62. package/src/components/Alert/Alert.tsx +24 -0
  63. package/src/components/Alert/index.ts +2 -0
  64. package/src/components/CodeBlock/CodeBlock.module.css +27 -0
  65. package/src/components/CodeBlock/CodeBlock.tsx +32 -0
  66. package/src/components/CodeBlock/index.ts +2 -0
  67. package/src/components/Common/Common.module.css +0 -0
  68. package/src/components/Common/Common.tsx +53 -0
  69. package/src/components/Common/index.ts +1 -0
  70. package/src/components/NetFoundry/Divider/Divider.module.css +23 -0
  71. package/src/components/NetFoundry/Divider/Divider.tsx +20 -0
  72. package/src/components/NetFoundry/Divider/index.ts +1 -0
  73. package/src/components/NetFoundry/index.ts +1 -0
  74. package/src/components/NetFoundryFooter/NetFoundryFooter.tsx +164 -0
  75. package/src/components/NetFoundryFooter/index.ts +1 -0
  76. package/src/components/NetFoundryFooter/styles.module.css +99 -0
  77. package/src/components/NetFoundryHighlight/NetFoundryHighlight.tsx +15 -0
  78. package/src/components/NetFoundryHighlight/index.ts +2 -0
  79. package/src/components/NetFoundryHighlight/styles.module.css +26 -0
  80. package/src/components/NetFoundryHorizontalSection/NetFoundryHorizontalSection.tsx +23 -0
  81. package/src/components/NetFoundryHorizontalSection/index.ts +2 -0
  82. package/src/components/NetFoundryHorizontalSection/styles.module.css +23 -0
  83. package/src/components/NetFoundryLayout/NetFoundryLayout.module.css +6 -0
  84. package/src/components/NetFoundryLayout/NetFoundryLayout.tsx +110 -0
  85. package/src/components/NetFoundryLayout/index.ts +1 -0
  86. package/src/components/NetFoundryNavbarItems/NetFoundryNavbarItems.tsx +22 -0
  87. package/src/components/NetFoundryNavbarItems/index.ts +2 -0
  88. package/src/components/OsTabs/OsTabs.tsx +30 -0
  89. package/src/components/OsTabs/index.ts +2 -0
  90. package/src/components/StarUs/StarUs.tsx +19 -0
  91. package/src/components/StarUs/index.ts +2 -0
  92. package/src/components/StarUs/styles.module.css +6 -0
  93. package/src/components/index.ts +11 -0
  94. package/src/css/layout.css +14 -0
  95. package/src/css/legacy.css +2348 -0
  96. package/src/css/vars-dark.css +7 -0
  97. package/src/css/vars.css +8 -0
  98. package/src/docusaurus-envhelper.ts +105 -0
  99. package/src/docusaurus-plugins/index.ts +7 -0
  100. package/src/docusaurus-plugins/logger.ts +38 -0
  101. package/src/docusaurus-plugins/remarkCodeSections.ts +115 -0
  102. package/src/docusaurus-plugins/remarkReplaceMetaUrl.ts +35 -0
  103. package/src/docusaurus-plugins/remarkScopedPath.ts +70 -0
  104. package/src/docusaurus-plugins/remarkYamlTable.ts +83 -0
  105. package/src/docusaurus-plugins/remarkYouTube.ts +56 -0
  106. package/src/docusaurus-plugins/timedPlugin.ts +22 -0
  107. package/src/global.d.ts +1 -0
  108. package/src/index.ts +3 -0
  109. package/src/node.ts +1 -0
  110. package/src/plugins.ts +1 -0
  111. package/src/ui.ts +2 -0
  112. package/src/version.ts +1 -0
@@ -0,0 +1,4643 @@
1
+ 'use strict';
2
+
3
+ var fs = require('fs');
4
+ var path = require('path');
5
+ var tslib = require('tslib');
6
+
7
+ exports.LogLevel = void 0;
8
+ (function (LogLevel) {
9
+ LogLevel[LogLevel["Silent"] = 0] = "Silent";
10
+ LogLevel[LogLevel["Info"] = 1] = "Info";
11
+ LogLevel[LogLevel["Debug"] = 2] = "Debug";
12
+ })(exports.LogLevel || (exports.LogLevel = {}));
13
+ var LOG = path.join(process.cwd(), 'remark-plugins.log');
14
+ var Logger = /** @class */ (function () {
15
+ function Logger(level, name) {
16
+ this.level = level;
17
+ this.name = name;
18
+ }
19
+ Logger.prototype.log = function (msg, level) {
20
+ if (level === void 0) { level = exports.LogLevel.Info; }
21
+ if (this.level === exports.LogLevel.Silent)
22
+ return;
23
+ if (level > this.level)
24
+ return;
25
+ var text = String(msg);
26
+ if (!text.trim())
27
+ return;
28
+ var line = "[".concat(this.name, "] ").concat(exports.LogLevel[level], " ").concat(text);
29
+ if (!fs.existsSync(LOG))
30
+ fs.writeFileSync(LOG, '');
31
+ fs.appendFileSync(LOG, "[".concat(new Date().toISOString(), "] ").concat(line, "\n"));
32
+ };
33
+ return Logger;
34
+ }());
35
+ function resolveLogLevel(val) {
36
+ if (typeof val === "number" && exports.LogLevel[val] !== undefined) {
37
+ return val;
38
+ }
39
+ if (typeof val === "string") {
40
+ var key = val[0].toUpperCase() + val.slice(1).toLowerCase();
41
+ if (key in exports.LogLevel) {
42
+ return exports.LogLevel[key];
43
+ }
44
+ }
45
+ return exports.LogLevel.Silent;
46
+ }
47
+
48
+ /**
49
+ * @typedef {import('unist').Node} Node
50
+ * @typedef {import('unist').Parent} Parent
51
+ */
52
+
53
+
54
+ /**
55
+ * Generate an assertion from a test.
56
+ *
57
+ * Useful if you’re going to test many nodes, for example when creating a
58
+ * utility where something else passes a compatible test.
59
+ *
60
+ * The created function is a bit faster because it expects valid input only:
61
+ * a `node`, `index`, and `parent`.
62
+ *
63
+ * @param {Test} test
64
+ * * when nullish, checks if `node` is a `Node`.
65
+ * * when `string`, works like passing `(node) => node.type === test`.
66
+ * * when `function` checks if function passed the node is true.
67
+ * * when `object`, checks that all keys in test are in node, and that they have (strictly) equal values.
68
+ * * when `array`, checks if any one of the subtests pass.
69
+ * @returns {Check}
70
+ * An assertion.
71
+ */
72
+ const convert =
73
+ // Note: overloads in JSDoc can’t yet use different `@template`s.
74
+ /**
75
+ * @type {(
76
+ * (<Condition extends string>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &
77
+ * (<Condition extends Props>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &
78
+ * (<Condition extends TestFunction>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate<Condition, Node>) &
79
+ * ((test?: null | undefined) => (node?: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &
80
+ * ((test?: Test) => Check)
81
+ * )}
82
+ */
83
+ (
84
+ /**
85
+ * @param {Test} [test]
86
+ * @returns {Check}
87
+ */
88
+ function (test) {
89
+ if (test === null || test === undefined) {
90
+ return ok
91
+ }
92
+
93
+ if (typeof test === 'function') {
94
+ return castFactory(test)
95
+ }
96
+
97
+ if (typeof test === 'object') {
98
+ return Array.isArray(test) ? anyFactory(test) : propsFactory(test)
99
+ }
100
+
101
+ if (typeof test === 'string') {
102
+ return typeFactory(test)
103
+ }
104
+
105
+ throw new Error('Expected function, string, or object as test')
106
+ }
107
+ );
108
+
109
+ /**
110
+ * @param {Array<Props | TestFunction | string>} tests
111
+ * @returns {Check}
112
+ */
113
+ function anyFactory(tests) {
114
+ /** @type {Array<Check>} */
115
+ const checks = [];
116
+ let index = -1;
117
+
118
+ while (++index < tests.length) {
119
+ checks[index] = convert(tests[index]);
120
+ }
121
+
122
+ return castFactory(any)
123
+
124
+ /**
125
+ * @this {unknown}
126
+ * @type {TestFunction}
127
+ */
128
+ function any(...parameters) {
129
+ let index = -1;
130
+
131
+ while (++index < checks.length) {
132
+ if (checks[index].apply(this, parameters)) return true
133
+ }
134
+
135
+ return false
136
+ }
137
+ }
138
+
139
+ /**
140
+ * Turn an object into a test for a node with a certain fields.
141
+ *
142
+ * @param {Props} check
143
+ * @returns {Check}
144
+ */
145
+ function propsFactory(check) {
146
+ const checkAsRecord = /** @type {Record<string, unknown>} */ (check);
147
+
148
+ return castFactory(all)
149
+
150
+ /**
151
+ * @param {Node} node
152
+ * @returns {boolean}
153
+ */
154
+ function all(node) {
155
+ const nodeAsRecord = /** @type {Record<string, unknown>} */ (
156
+ /** @type {unknown} */ (node)
157
+ );
158
+
159
+ /** @type {string} */
160
+ let key;
161
+
162
+ for (key in check) {
163
+ if (nodeAsRecord[key] !== checkAsRecord[key]) return false
164
+ }
165
+
166
+ return true
167
+ }
168
+ }
169
+
170
+ /**
171
+ * Turn a string into a test for a node with a certain type.
172
+ *
173
+ * @param {string} check
174
+ * @returns {Check}
175
+ */
176
+ function typeFactory(check) {
177
+ return castFactory(type)
178
+
179
+ /**
180
+ * @param {Node} node
181
+ */
182
+ function type(node) {
183
+ return node && node.type === check
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Turn a custom test into a test for a node that passes that test.
189
+ *
190
+ * @param {TestFunction} testFunction
191
+ * @returns {Check}
192
+ */
193
+ function castFactory(testFunction) {
194
+ return check
195
+
196
+ /**
197
+ * @this {unknown}
198
+ * @type {Check}
199
+ */
200
+ function check(value, index, parent) {
201
+ return Boolean(
202
+ looksLikeANode(value) &&
203
+ testFunction.call(
204
+ this,
205
+ value,
206
+ typeof index === 'number' ? index : undefined,
207
+ parent || undefined
208
+ )
209
+ )
210
+ }
211
+ }
212
+
213
+ function ok() {
214
+ return true
215
+ }
216
+
217
+ /**
218
+ * @param {unknown} value
219
+ * @returns {value is Node}
220
+ */
221
+ function looksLikeANode(value) {
222
+ return value !== null && typeof value === 'object' && 'type' in value
223
+ }
224
+
225
+ /**
226
+ * @param {string} d
227
+ * @returns {string}
228
+ */
229
+ function color(d) {
230
+ return d
231
+ }
232
+
233
+ /**
234
+ * @typedef {import('unist').Node} UnistNode
235
+ * @typedef {import('unist').Parent} UnistParent
236
+ */
237
+
238
+
239
+ /** @type {Readonly<ActionTuple>} */
240
+ const empty = [];
241
+
242
+ /**
243
+ * Continue traversing as normal.
244
+ */
245
+ const CONTINUE = true;
246
+
247
+ /**
248
+ * Stop traversing immediately.
249
+ */
250
+ const EXIT = false;
251
+
252
+ /**
253
+ * Do not traverse this node’s children.
254
+ */
255
+ const SKIP = 'skip';
256
+
257
+ /**
258
+ * Visit nodes, with ancestral information.
259
+ *
260
+ * This algorithm performs *depth-first* *tree traversal* in *preorder*
261
+ * (**NLR**) or if `reverse` is given, in *reverse preorder* (**NRL**).
262
+ *
263
+ * You can choose for which nodes `visitor` is called by passing a `test`.
264
+ * For complex tests, you should test yourself in `visitor`, as it will be
265
+ * faster and will have improved type information.
266
+ *
267
+ * Walking the tree is an intensive task.
268
+ * Make use of the return values of the visitor when possible.
269
+ * Instead of walking a tree multiple times, walk it once, use `unist-util-is`
270
+ * to check if a node matches, and then perform different operations.
271
+ *
272
+ * You can change the tree.
273
+ * See `Visitor` for more info.
274
+ *
275
+ * @overload
276
+ * @param {Tree} tree
277
+ * @param {Check} check
278
+ * @param {BuildVisitor<Tree, Check>} visitor
279
+ * @param {boolean | null | undefined} [reverse]
280
+ * @returns {undefined}
281
+ *
282
+ * @overload
283
+ * @param {Tree} tree
284
+ * @param {BuildVisitor<Tree>} visitor
285
+ * @param {boolean | null | undefined} [reverse]
286
+ * @returns {undefined}
287
+ *
288
+ * @param {UnistNode} tree
289
+ * Tree to traverse.
290
+ * @param {Visitor | Test} test
291
+ * `unist-util-is`-compatible test
292
+ * @param {Visitor | boolean | null | undefined} [visitor]
293
+ * Handle each node.
294
+ * @param {boolean | null | undefined} [reverse]
295
+ * Traverse in reverse preorder (NRL) instead of the default preorder (NLR).
296
+ * @returns {undefined}
297
+ * Nothing.
298
+ *
299
+ * @template {UnistNode} Tree
300
+ * Node type.
301
+ * @template {Test} Check
302
+ * `unist-util-is`-compatible test.
303
+ */
304
+ function visitParents(tree, test, visitor, reverse) {
305
+ /** @type {Test} */
306
+ let check;
307
+
308
+ if (typeof test === 'function' && typeof visitor !== 'function') {
309
+ reverse = visitor;
310
+ // @ts-expect-error no visitor given, so `visitor` is test.
311
+ visitor = test;
312
+ } else {
313
+ // @ts-expect-error visitor given, so `test` isn’t a visitor.
314
+ check = test;
315
+ }
316
+
317
+ const is = convert(check);
318
+ const step = reverse ? -1 : 1;
319
+
320
+ factory(tree, undefined, [])();
321
+
322
+ /**
323
+ * @param {UnistNode} node
324
+ * @param {number | undefined} index
325
+ * @param {Array<UnistParent>} parents
326
+ */
327
+ function factory(node, index, parents) {
328
+ const value = /** @type {Record<string, unknown>} */ (
329
+ node && typeof node === 'object' ? node : {}
330
+ );
331
+
332
+ if (typeof value.type === 'string') {
333
+ const name =
334
+ // `hast`
335
+ typeof value.tagName === 'string'
336
+ ? value.tagName
337
+ : // `xast`
338
+ typeof value.name === 'string'
339
+ ? value.name
340
+ : undefined;
341
+
342
+ Object.defineProperty(visit, 'name', {
343
+ value:
344
+ 'node (' + color(node.type + (name ? '<' + name + '>' : '')) + ')'
345
+ });
346
+ }
347
+
348
+ return visit
349
+
350
+ function visit() {
351
+ /** @type {Readonly<ActionTuple>} */
352
+ let result = empty;
353
+ /** @type {Readonly<ActionTuple>} */
354
+ let subresult;
355
+ /** @type {number} */
356
+ let offset;
357
+ /** @type {Array<UnistParent>} */
358
+ let grandparents;
359
+
360
+ if (!test || is(node, index, parents[parents.length - 1] || undefined)) {
361
+ // @ts-expect-error: `visitor` is now a visitor.
362
+ result = toResult(visitor(node, parents));
363
+
364
+ if (result[0] === EXIT) {
365
+ return result
366
+ }
367
+ }
368
+
369
+ if ('children' in node && node.children) {
370
+ const nodeAsParent = /** @type {UnistParent} */ (node);
371
+
372
+ if (nodeAsParent.children && result[0] !== SKIP) {
373
+ offset = (reverse ? nodeAsParent.children.length : -1) + step;
374
+ grandparents = parents.concat(nodeAsParent);
375
+
376
+ while (offset > -1 && offset < nodeAsParent.children.length) {
377
+ const child = nodeAsParent.children[offset];
378
+
379
+ subresult = factory(child, offset, grandparents)();
380
+
381
+ if (subresult[0] === EXIT) {
382
+ return subresult
383
+ }
384
+
385
+ offset =
386
+ typeof subresult[1] === 'number' ? subresult[1] : offset + step;
387
+ }
388
+ }
389
+ }
390
+
391
+ return result
392
+ }
393
+ }
394
+ }
395
+
396
+ /**
397
+ * Turn a return value into a clean result.
398
+ *
399
+ * @param {VisitorResult} value
400
+ * Valid return values from visitors.
401
+ * @returns {Readonly<ActionTuple>}
402
+ * Clean result.
403
+ */
404
+ function toResult(value) {
405
+ if (Array.isArray(value)) {
406
+ return value
407
+ }
408
+
409
+ if (typeof value === 'number') {
410
+ return [CONTINUE, value]
411
+ }
412
+
413
+ return value === null || value === undefined ? empty : [value]
414
+ }
415
+
416
+ /**
417
+ * @typedef {import('unist').Node} UnistNode
418
+ * @typedef {import('unist').Parent} UnistParent
419
+ * @typedef {import('unist-util-visit-parents').VisitorResult} VisitorResult
420
+ */
421
+
422
+
423
+ /**
424
+ * Visit nodes.
425
+ *
426
+ * This algorithm performs *depth-first* *tree traversal* in *preorder*
427
+ * (**NLR**) or if `reverse` is given, in *reverse preorder* (**NRL**).
428
+ *
429
+ * You can choose for which nodes `visitor` is called by passing a `test`.
430
+ * For complex tests, you should test yourself in `visitor`, as it will be
431
+ * faster and will have improved type information.
432
+ *
433
+ * Walking the tree is an intensive task.
434
+ * Make use of the return values of the visitor when possible.
435
+ * Instead of walking a tree multiple times, walk it once, use `unist-util-is`
436
+ * to check if a node matches, and then perform different operations.
437
+ *
438
+ * You can change the tree.
439
+ * See `Visitor` for more info.
440
+ *
441
+ * @overload
442
+ * @param {Tree} tree
443
+ * @param {Check} check
444
+ * @param {BuildVisitor<Tree, Check>} visitor
445
+ * @param {boolean | null | undefined} [reverse]
446
+ * @returns {undefined}
447
+ *
448
+ * @overload
449
+ * @param {Tree} tree
450
+ * @param {BuildVisitor<Tree>} visitor
451
+ * @param {boolean | null | undefined} [reverse]
452
+ * @returns {undefined}
453
+ *
454
+ * @param {UnistNode} tree
455
+ * Tree to traverse.
456
+ * @param {Visitor | Test} testOrVisitor
457
+ * `unist-util-is`-compatible test (optional, omit to pass a visitor).
458
+ * @param {Visitor | boolean | null | undefined} [visitorOrReverse]
459
+ * Handle each node (when test is omitted, pass `reverse`).
460
+ * @param {boolean | null | undefined} [maybeReverse=false]
461
+ * Traverse in reverse preorder (NRL) instead of the default preorder (NLR).
462
+ * @returns {undefined}
463
+ * Nothing.
464
+ *
465
+ * @template {UnistNode} Tree
466
+ * Node type.
467
+ * @template {Test} Check
468
+ * `unist-util-is`-compatible test.
469
+ */
470
+ function visit(tree, testOrVisitor, visitorOrReverse, maybeReverse) {
471
+ /** @type {boolean | null | undefined} */
472
+ let reverse;
473
+ /** @type {Test} */
474
+ let test;
475
+ /** @type {Visitor} */
476
+ let visitor;
477
+
478
+ if (
479
+ typeof testOrVisitor === 'function' &&
480
+ typeof visitorOrReverse !== 'function'
481
+ ) {
482
+ test = undefined;
483
+ visitor = testOrVisitor;
484
+ reverse = visitorOrReverse;
485
+ } else {
486
+ // @ts-expect-error: assume the overload with test was given.
487
+ test = testOrVisitor;
488
+ // @ts-expect-error: assume the overload with test was given.
489
+ visitor = visitorOrReverse;
490
+ reverse = maybeReverse;
491
+ }
492
+
493
+ visitParents(tree, test, overload, reverse);
494
+
495
+ /**
496
+ * @param {UnistNode} node
497
+ * @param {Array<UnistParent>} parents
498
+ */
499
+ function overload(node, parents) {
500
+ const parent = parents[parents.length - 1];
501
+ const index = parent ? parent.children.indexOf(node) : undefined;
502
+ return visitor(node, index, parent)
503
+ }
504
+ }
505
+
506
+ console.log("🦖 remarkYouTube plugin module loaded");
507
+ var remarkYouTube = function (options) {
508
+ var _a = (options !== null && options !== void 0 ? options : {}).logLevel; _a === void 0 ? exports.LogLevel.Silent : _a;
509
+ var logger = new Logger(resolveLogLevel(options === null || options === void 0 ? void 0 : options.logLevel), 'remarkYouTube');
510
+ logger.log('initialized');
511
+ return function (tree) {
512
+ visit(tree, ['link', 'text'], function (node, index, parent) {
513
+ if (!parent || typeof index !== 'number')
514
+ return;
515
+ var raw = node.url || node.value || '';
516
+ var ytUrl = raw.trim();
517
+ var hashnodeMatch = ytUrl.match(/^%\[(.+)\]$/);
518
+ if (hashnodeMatch) {
519
+ ytUrl = hashnodeMatch[1];
520
+ logger.log("hashnode-style embed detected: ".concat(ytUrl), exports.LogLevel.Info);
521
+ }
522
+ var m = ytUrl.match(/youtube\.com\/watch\?v=([A-Za-z0-9_-]+)/) ||
523
+ ytUrl.match(/youtu\.be\/([A-Za-z0-9_-]+)/) ||
524
+ ytUrl.match(/youtube-nocookie\.com\/watch\?v=([A-Za-z0-9_-]+)/);
525
+ if (m) {
526
+ logger.log("rewriting YouTube URL: ".concat(ytUrl, " \u2192 videoId=").concat(m[1]), exports.LogLevel.Debug);
527
+ parent.children.splice(index, 1, {
528
+ type: 'mdxJsxFlowElement',
529
+ name: 'LiteYouTubeEmbed',
530
+ attributes: [
531
+ { type: 'mdxJsxAttribute', name: 'id', value: m[1] },
532
+ { type: 'mdxJsxAttribute', name: 'title', value: 'YouTube video' },
533
+ ],
534
+ });
535
+ }
536
+ });
537
+ visit(tree, 'text', function (node, index, parent) {
538
+ if (!parent || typeof index !== 'number')
539
+ return;
540
+ if (node.value.trim() === '%[' || node.value.trim() === ']') {
541
+ logger.log("stripping hashnode bracket artifact: ".concat(node.value), exports.LogLevel.Debug);
542
+ parent.children.splice(index, 1);
543
+ }
544
+ });
545
+ };
546
+ };
547
+
548
+ console.log("🦖 remarkScopedPath plugin module loaded");
549
+ var remarkScopedPath = function (options) {
550
+ var _a = options !== null && options !== void 0 ? options : {}, _b = _a.mappings, mappings = _b === void 0 ? [] : _b, _c = _a.logLevel; _c === void 0 ? exports.LogLevel.Silent : _c;
551
+ var logger = new Logger(resolveLogLevel(options === null || options === void 0 ? void 0 : options.logLevel), 'remarkScopedPath');
552
+ logger.log("initialized with ".concat(mappings.length, " mappings"));
553
+ return function (tree, file) {
554
+ var _a;
555
+ var filePath = (file === null || file === void 0 ? void 0 : file.path) || ((_a = file === null || file === void 0 ? void 0 : file.history) === null || _a === void 0 ? void 0 : _a.slice(-1)[0]) || 'unknown';
556
+ logger.log("processing file: ".concat(filePath), exports.LogLevel.Debug);
557
+ var rewrite = function (val, from, to, ctx) {
558
+ if (val.startsWith(from)) {
559
+ var newVal = val.replace(from, to);
560
+ logger.log("\uD83D\uDD04 ".concat(ctx, " ").concat(val, " \u2192 ").concat(newVal), exports.LogLevel.Info);
561
+ return newVal;
562
+ }
563
+ return val;
564
+ };
565
+ visit(tree, 'image', function (node) {
566
+ for (var _i = 0, mappings_1 = mappings; _i < mappings_1.length; _i++) {
567
+ var _a = mappings_1[_i], from = _a.from, to = _a.to;
568
+ node.url = rewrite(node.url, from, to, 'img');
569
+ }
570
+ });
571
+ visit(tree, 'link', function (node) {
572
+ for (var _i = 0, mappings_2 = mappings; _i < mappings_2.length; _i++) {
573
+ var _a = mappings_2[_i], from = _a.from, to = _a.to;
574
+ node.url = rewrite(node.url, from, to, 'link');
575
+ }
576
+ });
577
+ visit(tree, 'mdxJsxFlowElement', function (node) {
578
+ var _a;
579
+ (_a = node.attributes) === null || _a === void 0 ? void 0 : _a.forEach(function (attr) {
580
+ if (attr.type === 'mdxJsxAttribute' && typeof attr.value === 'string') {
581
+ for (var _i = 0, mappings_3 = mappings; _i < mappings_3.length; _i++) {
582
+ var _a = mappings_3[_i], from = _a.from, to = _a.to;
583
+ attr.value = rewrite(attr.value, from, to, "jsx <".concat(node.name, "> ").concat(attr.name, ":"));
584
+ }
585
+ }
586
+ });
587
+ });
588
+ visit(tree, 'mdxjsEsm', function (node) {
589
+ for (var _i = 0, mappings_4 = mappings; _i < mappings_4.length; _i++) {
590
+ var _a = mappings_4[_i], from = _a.from, to = _a.to;
591
+ var re = new RegExp("(['\"])".concat(from, "/"), 'g');
592
+ var newVal = node.value.replace(re, "$1".concat(to, "/"));
593
+ if (newVal !== node.value) {
594
+ logger.log("esm rewrite (".concat(from, " \u2192 ").concat(to, "):\n--- before ---\n").concat(node.value, "\n--- after ---\n").concat(newVal), exports.LogLevel.Info);
595
+ node.value = newVal;
596
+ }
597
+ }
598
+ });
599
+ logger.log(" ", exports.LogLevel.Debug);
600
+ };
601
+ };
602
+
603
+ console.log("🦖 remarkReplaceMetaUrl plugin loaded");
604
+ var remarkReplaceMetaUrl = function (options) {
605
+ var _a = options !== null && options !== void 0 ? options : {}, _b = _a.from, from = _b === void 0 ? '' : _b, _c = _a.to, to = _c === void 0 ? '' : _c, _d = _a.logLevel; _d === void 0 ? exports.LogLevel.Silent : _d;
606
+ var logger = new Logger(resolveLogLevel(options === null || options === void 0 ? void 0 : options.logLevel), 'remarkReplaceMetaUrl');
607
+ logger.log("initialized: replacing \"".concat(from, "\" \u2192 \"").concat(to, "\""));
608
+ return function (tree) {
609
+ visit(tree, 'mdxJsxFlowElement', function (node) {
610
+ if (node.name === 'meta' && Array.isArray(node.attributes)) {
611
+ for (var _i = 0, _a = node.attributes; _i < _a.length; _i++) {
612
+ var attr = _a[_i];
613
+ if (attr.name === 'content' && typeof attr.value === 'string' && attr.value.includes(from)) {
614
+ var newVal = attr.value.replace(from, to);
615
+ logger.log("rewriting: \"".concat(attr.value, "\" \u2192 \"").concat(newVal, "\""), exports.LogLevel.Info);
616
+ attr.value = newVal;
617
+ }
618
+ }
619
+ }
620
+ });
621
+ };
622
+ };
623
+
624
+ var remarkCodeSections = function (options) {
625
+ var logger = new Logger(resolveLogLevel(options === null || options === void 0 ? void 0 : options.logLevel), "remarkCodeSections");
626
+ var desc_text = "@desc:";
627
+ var command_text = "@command:";
628
+ var code_text = "@code:";
629
+ var results_text = "@results:";
630
+ return function (tree) {
631
+ visit(tree, "code", function (node, index, parent) {
632
+ if (!(node === null || node === void 0 ? void 0 : node.value))
633
+ return;
634
+ var hasActivator = /@desc:|@command:|@code:|@results:/.test(node.value);
635
+ if (!hasActivator)
636
+ return;
637
+ logger.log(node, exports.LogLevel.Debug);
638
+ if (node.lang && node.lang.startsWith("example")) {
639
+ var lang = node.lang.replace("example-", "").trim();
640
+ var lines = node.value.split("\n");
641
+ var description_1 = "", command_1 = "", code_1 = "", results_1 = "", codeTitle_1 = "";
642
+ var currentSection_1 = "";
643
+ lines.forEach(function (line) {
644
+ if (line.startsWith(desc_text)) {
645
+ currentSection_1 = "description";
646
+ description_1 = line.replace(desc_text, "").trim();
647
+ }
648
+ else if (line.startsWith(command_text)) {
649
+ currentSection_1 = "command";
650
+ command_1 = line.replace(command_text, "").trim();
651
+ }
652
+ else if (line.startsWith(code_text)) {
653
+ currentSection_1 = "code";
654
+ codeTitle_1 = line.replace(code_text, "").trim();
655
+ }
656
+ else if (line.startsWith(results_text)) {
657
+ currentSection_1 = "results";
658
+ results_1 = line.replace(results_text, "").trim();
659
+ }
660
+ else {
661
+ if (currentSection_1 === "description")
662
+ description_1 += "\n".concat(line);
663
+ else if (currentSection_1 === "command")
664
+ command_1 += "\n".concat(line);
665
+ else if (currentSection_1 === "code")
666
+ code_1 += "\n".concat(line);
667
+ else if (currentSection_1 === "results")
668
+ results_1 += "\n".concat(line);
669
+ }
670
+ });
671
+ var divWrapper = {
672
+ type: "div",
673
+ data: { hName: "div", hProperties: { className: "code-section" } },
674
+ children: [],
675
+ };
676
+ if (description_1) {
677
+ var descDiv = {
678
+ type: "div",
679
+ data: { hName: "div", hProperties: { className: "code-section-desc" } },
680
+ children: [],
681
+ };
682
+ descDiv.children.push({ type: "paragraph", children: [{ type: "strong", children: [{ type: "text", value: "Description:" }] }] }, { type: "paragraph", children: [{ type: "text", value: description_1.trim() }], data: { hProperties: { style: "padding-bottom: 10px;" } } });
683
+ divWrapper.children.push(descDiv);
684
+ }
685
+ if (command_1) {
686
+ var cmdDiv = {
687
+ type: "div",
688
+ data: { hName: "div", hProperties: { className: "code-section-command" } },
689
+ children: [],
690
+ };
691
+ cmdDiv.children.push({ type: "paragraph", children: [{ type: "strong", children: [{ type: "text", value: "Command:" }] }] }, { type: "code", lang: "sh", value: command_1.trim() });
692
+ divWrapper.children.push(cmdDiv);
693
+ }
694
+ if (code_1) {
695
+ var codeDiv = {
696
+ type: "div",
697
+ data: { hName: "div", hProperties: { className: "code-section-code" } },
698
+ children: [],
699
+ };
700
+ codeDiv.children.push({ type: "paragraph", children: [{ type: "strong", children: [{ type: "text", value: codeTitle_1 }] }] }, { type: "code", lang: lang, value: code_1.trim() });
701
+ divWrapper.children.push(codeDiv);
702
+ }
703
+ if (results_1) {
704
+ var resultsDiv = {
705
+ type: "div",
706
+ data: { hName: "div", hProperties: { className: "code-section-results" } },
707
+ children: [],
708
+ };
709
+ resultsDiv.children.push({ type: "paragraph", children: [{ type: "strong", children: [{ type: "text", value: "Results:" }] }] }, { type: "code", lang: "buttonless", value: results_1.trim() });
710
+ divWrapper.children.push(resultsDiv);
711
+ }
712
+ parent.children.splice(index, 1, divWrapper);
713
+ }
714
+ });
715
+ };
716
+ };
717
+
718
+ /*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */
719
+ function isNothing(subject) {
720
+ return (typeof subject === 'undefined') || (subject === null);
721
+ }
722
+
723
+
724
+ function isObject(subject) {
725
+ return (typeof subject === 'object') && (subject !== null);
726
+ }
727
+
728
+
729
+ function toArray(sequence) {
730
+ if (Array.isArray(sequence)) return sequence;
731
+ else if (isNothing(sequence)) return [];
732
+
733
+ return [ sequence ];
734
+ }
735
+
736
+
737
+ function extend(target, source) {
738
+ var index, length, key, sourceKeys;
739
+
740
+ if (source) {
741
+ sourceKeys = Object.keys(source);
742
+
743
+ for (index = 0, length = sourceKeys.length; index < length; index += 1) {
744
+ key = sourceKeys[index];
745
+ target[key] = source[key];
746
+ }
747
+ }
748
+
749
+ return target;
750
+ }
751
+
752
+
753
+ function repeat(string, count) {
754
+ var result = '', cycle;
755
+
756
+ for (cycle = 0; cycle < count; cycle += 1) {
757
+ result += string;
758
+ }
759
+
760
+ return result;
761
+ }
762
+
763
+
764
+ function isNegativeZero(number) {
765
+ return (number === 0) && (Number.NEGATIVE_INFINITY === 1 / number);
766
+ }
767
+
768
+
769
+ var isNothing_1 = isNothing;
770
+ var isObject_1 = isObject;
771
+ var toArray_1 = toArray;
772
+ var repeat_1 = repeat;
773
+ var isNegativeZero_1 = isNegativeZero;
774
+ var extend_1 = extend;
775
+
776
+ var common = {
777
+ isNothing: isNothing_1,
778
+ isObject: isObject_1,
779
+ toArray: toArray_1,
780
+ repeat: repeat_1,
781
+ isNegativeZero: isNegativeZero_1,
782
+ extend: extend_1
783
+ };
784
+
785
+ // YAML error class. http://stackoverflow.com/questions/8458984
786
+
787
+
788
+ function formatError(exception, compact) {
789
+ var where = '', message = exception.reason || '(unknown reason)';
790
+
791
+ if (!exception.mark) return message;
792
+
793
+ if (exception.mark.name) {
794
+ where += 'in "' + exception.mark.name + '" ';
795
+ }
796
+
797
+ where += '(' + (exception.mark.line + 1) + ':' + (exception.mark.column + 1) + ')';
798
+
799
+ if (!compact && exception.mark.snippet) {
800
+ where += '\n\n' + exception.mark.snippet;
801
+ }
802
+
803
+ return message + ' ' + where;
804
+ }
805
+
806
+
807
+ function YAMLException$1(reason, mark) {
808
+ // Super constructor
809
+ Error.call(this);
810
+
811
+ this.name = 'YAMLException';
812
+ this.reason = reason;
813
+ this.mark = mark;
814
+ this.message = formatError(this, false);
815
+
816
+ // Include stack trace in error object
817
+ if (Error.captureStackTrace) {
818
+ // Chrome and NodeJS
819
+ Error.captureStackTrace(this, this.constructor);
820
+ } else {
821
+ // FF, IE 10+ and Safari 6+. Fallback for others
822
+ this.stack = (new Error()).stack || '';
823
+ }
824
+ }
825
+
826
+
827
+ // Inherit from Error
828
+ YAMLException$1.prototype = Object.create(Error.prototype);
829
+ YAMLException$1.prototype.constructor = YAMLException$1;
830
+
831
+
832
+ YAMLException$1.prototype.toString = function toString(compact) {
833
+ return this.name + ': ' + formatError(this, compact);
834
+ };
835
+
836
+
837
+ var exception = YAMLException$1;
838
+
839
+ // get snippet for a single line, respecting maxLength
840
+ function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
841
+ var head = '';
842
+ var tail = '';
843
+ var maxHalfLength = Math.floor(maxLineLength / 2) - 1;
844
+
845
+ if (position - lineStart > maxHalfLength) {
846
+ head = ' ... ';
847
+ lineStart = position - maxHalfLength + head.length;
848
+ }
849
+
850
+ if (lineEnd - position > maxHalfLength) {
851
+ tail = ' ...';
852
+ lineEnd = position + maxHalfLength - tail.length;
853
+ }
854
+
855
+ return {
856
+ str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, '→') + tail,
857
+ pos: position - lineStart + head.length // relative position
858
+ };
859
+ }
860
+
861
+
862
+ function padStart(string, max) {
863
+ return common.repeat(' ', max - string.length) + string;
864
+ }
865
+
866
+
867
+ function makeSnippet(mark, options) {
868
+ options = Object.create(options || null);
869
+
870
+ if (!mark.buffer) return null;
871
+
872
+ if (!options.maxLength) options.maxLength = 79;
873
+ if (typeof options.indent !== 'number') options.indent = 1;
874
+ if (typeof options.linesBefore !== 'number') options.linesBefore = 3;
875
+ if (typeof options.linesAfter !== 'number') options.linesAfter = 2;
876
+
877
+ var re = /\r?\n|\r|\0/g;
878
+ var lineStarts = [ 0 ];
879
+ var lineEnds = [];
880
+ var match;
881
+ var foundLineNo = -1;
882
+
883
+ while ((match = re.exec(mark.buffer))) {
884
+ lineEnds.push(match.index);
885
+ lineStarts.push(match.index + match[0].length);
886
+
887
+ if (mark.position <= match.index && foundLineNo < 0) {
888
+ foundLineNo = lineStarts.length - 2;
889
+ }
890
+ }
891
+
892
+ if (foundLineNo < 0) foundLineNo = lineStarts.length - 1;
893
+
894
+ var result = '', i, line;
895
+ var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length;
896
+ var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3);
897
+
898
+ for (i = 1; i <= options.linesBefore; i++) {
899
+ if (foundLineNo - i < 0) break;
900
+ line = getLine(
901
+ mark.buffer,
902
+ lineStarts[foundLineNo - i],
903
+ lineEnds[foundLineNo - i],
904
+ mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]),
905
+ maxLineLength
906
+ );
907
+ result = common.repeat(' ', options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) +
908
+ ' | ' + line.str + '\n' + result;
909
+ }
910
+
911
+ line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
912
+ result += common.repeat(' ', options.indent) + padStart((mark.line + 1).toString(), lineNoLength) +
913
+ ' | ' + line.str + '\n';
914
+ result += common.repeat('-', options.indent + lineNoLength + 3 + line.pos) + '^' + '\n';
915
+
916
+ for (i = 1; i <= options.linesAfter; i++) {
917
+ if (foundLineNo + i >= lineEnds.length) break;
918
+ line = getLine(
919
+ mark.buffer,
920
+ lineStarts[foundLineNo + i],
921
+ lineEnds[foundLineNo + i],
922
+ mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]),
923
+ maxLineLength
924
+ );
925
+ result += common.repeat(' ', options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) +
926
+ ' | ' + line.str + '\n';
927
+ }
928
+
929
+ return result.replace(/\n$/, '');
930
+ }
931
+
932
+
933
+ var snippet = makeSnippet;
934
+
935
+ var TYPE_CONSTRUCTOR_OPTIONS = [
936
+ 'kind',
937
+ 'multi',
938
+ 'resolve',
939
+ 'construct',
940
+ 'instanceOf',
941
+ 'predicate',
942
+ 'represent',
943
+ 'representName',
944
+ 'defaultStyle',
945
+ 'styleAliases'
946
+ ];
947
+
948
+ var YAML_NODE_KINDS = [
949
+ 'scalar',
950
+ 'sequence',
951
+ 'mapping'
952
+ ];
953
+
954
+ function compileStyleAliases(map) {
955
+ var result = {};
956
+
957
+ if (map !== null) {
958
+ Object.keys(map).forEach(function (style) {
959
+ map[style].forEach(function (alias) {
960
+ result[String(alias)] = style;
961
+ });
962
+ });
963
+ }
964
+
965
+ return result;
966
+ }
967
+
968
+ function Type$1(tag, options) {
969
+ options = options || {};
970
+
971
+ Object.keys(options).forEach(function (name) {
972
+ if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
973
+ throw new exception('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
974
+ }
975
+ });
976
+
977
+ // TODO: Add tag format check.
978
+ this.options = options; // keep original options in case user wants to extend this type later
979
+ this.tag = tag;
980
+ this.kind = options['kind'] || null;
981
+ this.resolve = options['resolve'] || function () { return true; };
982
+ this.construct = options['construct'] || function (data) { return data; };
983
+ this.instanceOf = options['instanceOf'] || null;
984
+ this.predicate = options['predicate'] || null;
985
+ this.represent = options['represent'] || null;
986
+ this.representName = options['representName'] || null;
987
+ this.defaultStyle = options['defaultStyle'] || null;
988
+ this.multi = options['multi'] || false;
989
+ this.styleAliases = compileStyleAliases(options['styleAliases'] || null);
990
+
991
+ if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
992
+ throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
993
+ }
994
+ }
995
+
996
+ var type = Type$1;
997
+
998
+ /*eslint-disable max-len*/
999
+
1000
+
1001
+
1002
+
1003
+
1004
+ function compileList(schema, name) {
1005
+ var result = [];
1006
+
1007
+ schema[name].forEach(function (currentType) {
1008
+ var newIndex = result.length;
1009
+
1010
+ result.forEach(function (previousType, previousIndex) {
1011
+ if (previousType.tag === currentType.tag &&
1012
+ previousType.kind === currentType.kind &&
1013
+ previousType.multi === currentType.multi) {
1014
+
1015
+ newIndex = previousIndex;
1016
+ }
1017
+ });
1018
+
1019
+ result[newIndex] = currentType;
1020
+ });
1021
+
1022
+ return result;
1023
+ }
1024
+
1025
+
1026
+ function compileMap(/* lists... */) {
1027
+ var result = {
1028
+ scalar: {},
1029
+ sequence: {},
1030
+ mapping: {},
1031
+ fallback: {},
1032
+ multi: {
1033
+ scalar: [],
1034
+ sequence: [],
1035
+ mapping: [],
1036
+ fallback: []
1037
+ }
1038
+ }, index, length;
1039
+
1040
+ function collectType(type) {
1041
+ if (type.multi) {
1042
+ result.multi[type.kind].push(type);
1043
+ result.multi['fallback'].push(type);
1044
+ } else {
1045
+ result[type.kind][type.tag] = result['fallback'][type.tag] = type;
1046
+ }
1047
+ }
1048
+
1049
+ for (index = 0, length = arguments.length; index < length; index += 1) {
1050
+ arguments[index].forEach(collectType);
1051
+ }
1052
+ return result;
1053
+ }
1054
+
1055
+
1056
+ function Schema$1(definition) {
1057
+ return this.extend(definition);
1058
+ }
1059
+
1060
+
1061
+ Schema$1.prototype.extend = function extend(definition) {
1062
+ var implicit = [];
1063
+ var explicit = [];
1064
+
1065
+ if (definition instanceof type) {
1066
+ // Schema.extend(type)
1067
+ explicit.push(definition);
1068
+
1069
+ } else if (Array.isArray(definition)) {
1070
+ // Schema.extend([ type1, type2, ... ])
1071
+ explicit = explicit.concat(definition);
1072
+
1073
+ } else if (definition && (Array.isArray(definition.implicit) || Array.isArray(definition.explicit))) {
1074
+ // Schema.extend({ explicit: [ type1, type2, ... ], implicit: [ type1, type2, ... ] })
1075
+ if (definition.implicit) implicit = implicit.concat(definition.implicit);
1076
+ if (definition.explicit) explicit = explicit.concat(definition.explicit);
1077
+
1078
+ } else {
1079
+ throw new exception('Schema.extend argument should be a Type, [ Type ], ' +
1080
+ 'or a schema definition ({ implicit: [...], explicit: [...] })');
1081
+ }
1082
+
1083
+ implicit.forEach(function (type$1) {
1084
+ if (!(type$1 instanceof type)) {
1085
+ throw new exception('Specified list of YAML types (or a single Type object) contains a non-Type object.');
1086
+ }
1087
+
1088
+ if (type$1.loadKind && type$1.loadKind !== 'scalar') {
1089
+ throw new exception('There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.');
1090
+ }
1091
+
1092
+ if (type$1.multi) {
1093
+ throw new exception('There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.');
1094
+ }
1095
+ });
1096
+
1097
+ explicit.forEach(function (type$1) {
1098
+ if (!(type$1 instanceof type)) {
1099
+ throw new exception('Specified list of YAML types (or a single Type object) contains a non-Type object.');
1100
+ }
1101
+ });
1102
+
1103
+ var result = Object.create(Schema$1.prototype);
1104
+
1105
+ result.implicit = (this.implicit || []).concat(implicit);
1106
+ result.explicit = (this.explicit || []).concat(explicit);
1107
+
1108
+ result.compiledImplicit = compileList(result, 'implicit');
1109
+ result.compiledExplicit = compileList(result, 'explicit');
1110
+ result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit);
1111
+
1112
+ return result;
1113
+ };
1114
+
1115
+
1116
+ var schema = Schema$1;
1117
+
1118
+ var str = new type('tag:yaml.org,2002:str', {
1119
+ kind: 'scalar',
1120
+ construct: function (data) { return data !== null ? data : ''; }
1121
+ });
1122
+
1123
+ var seq = new type('tag:yaml.org,2002:seq', {
1124
+ kind: 'sequence',
1125
+ construct: function (data) { return data !== null ? data : []; }
1126
+ });
1127
+
1128
+ var map = new type('tag:yaml.org,2002:map', {
1129
+ kind: 'mapping',
1130
+ construct: function (data) { return data !== null ? data : {}; }
1131
+ });
1132
+
1133
+ var failsafe = new schema({
1134
+ explicit: [
1135
+ str,
1136
+ seq,
1137
+ map
1138
+ ]
1139
+ });
1140
+
1141
+ function resolveYamlNull(data) {
1142
+ if (data === null) return true;
1143
+
1144
+ var max = data.length;
1145
+
1146
+ return (max === 1 && data === '~') ||
1147
+ (max === 4 && (data === 'null' || data === 'Null' || data === 'NULL'));
1148
+ }
1149
+
1150
+ function constructYamlNull() {
1151
+ return null;
1152
+ }
1153
+
1154
+ function isNull(object) {
1155
+ return object === null;
1156
+ }
1157
+
1158
+ var _null = new type('tag:yaml.org,2002:null', {
1159
+ kind: 'scalar',
1160
+ resolve: resolveYamlNull,
1161
+ construct: constructYamlNull,
1162
+ predicate: isNull,
1163
+ represent: {
1164
+ canonical: function () { return '~'; },
1165
+ lowercase: function () { return 'null'; },
1166
+ uppercase: function () { return 'NULL'; },
1167
+ camelcase: function () { return 'Null'; },
1168
+ empty: function () { return ''; }
1169
+ },
1170
+ defaultStyle: 'lowercase'
1171
+ });
1172
+
1173
+ function resolveYamlBoolean(data) {
1174
+ if (data === null) return false;
1175
+
1176
+ var max = data.length;
1177
+
1178
+ return (max === 4 && (data === 'true' || data === 'True' || data === 'TRUE')) ||
1179
+ (max === 5 && (data === 'false' || data === 'False' || data === 'FALSE'));
1180
+ }
1181
+
1182
+ function constructYamlBoolean(data) {
1183
+ return data === 'true' ||
1184
+ data === 'True' ||
1185
+ data === 'TRUE';
1186
+ }
1187
+
1188
+ function isBoolean(object) {
1189
+ return Object.prototype.toString.call(object) === '[object Boolean]';
1190
+ }
1191
+
1192
+ var bool = new type('tag:yaml.org,2002:bool', {
1193
+ kind: 'scalar',
1194
+ resolve: resolveYamlBoolean,
1195
+ construct: constructYamlBoolean,
1196
+ predicate: isBoolean,
1197
+ represent: {
1198
+ lowercase: function (object) { return object ? 'true' : 'false'; },
1199
+ uppercase: function (object) { return object ? 'TRUE' : 'FALSE'; },
1200
+ camelcase: function (object) { return object ? 'True' : 'False'; }
1201
+ },
1202
+ defaultStyle: 'lowercase'
1203
+ });
1204
+
1205
+ function isHexCode(c) {
1206
+ return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) ||
1207
+ ((0x41/* A */ <= c) && (c <= 0x46/* F */)) ||
1208
+ ((0x61/* a */ <= c) && (c <= 0x66/* f */));
1209
+ }
1210
+
1211
+ function isOctCode(c) {
1212
+ return ((0x30/* 0 */ <= c) && (c <= 0x37/* 7 */));
1213
+ }
1214
+
1215
+ function isDecCode(c) {
1216
+ return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */));
1217
+ }
1218
+
1219
+ function resolveYamlInteger(data) {
1220
+ if (data === null) return false;
1221
+
1222
+ var max = data.length,
1223
+ index = 0,
1224
+ hasDigits = false,
1225
+ ch;
1226
+
1227
+ if (!max) return false;
1228
+
1229
+ ch = data[index];
1230
+
1231
+ // sign
1232
+ if (ch === '-' || ch === '+') {
1233
+ ch = data[++index];
1234
+ }
1235
+
1236
+ if (ch === '0') {
1237
+ // 0
1238
+ if (index + 1 === max) return true;
1239
+ ch = data[++index];
1240
+
1241
+ // base 2, base 8, base 16
1242
+
1243
+ if (ch === 'b') {
1244
+ // base 2
1245
+ index++;
1246
+
1247
+ for (; index < max; index++) {
1248
+ ch = data[index];
1249
+ if (ch === '_') continue;
1250
+ if (ch !== '0' && ch !== '1') return false;
1251
+ hasDigits = true;
1252
+ }
1253
+ return hasDigits && ch !== '_';
1254
+ }
1255
+
1256
+
1257
+ if (ch === 'x') {
1258
+ // base 16
1259
+ index++;
1260
+
1261
+ for (; index < max; index++) {
1262
+ ch = data[index];
1263
+ if (ch === '_') continue;
1264
+ if (!isHexCode(data.charCodeAt(index))) return false;
1265
+ hasDigits = true;
1266
+ }
1267
+ return hasDigits && ch !== '_';
1268
+ }
1269
+
1270
+
1271
+ if (ch === 'o') {
1272
+ // base 8
1273
+ index++;
1274
+
1275
+ for (; index < max; index++) {
1276
+ ch = data[index];
1277
+ if (ch === '_') continue;
1278
+ if (!isOctCode(data.charCodeAt(index))) return false;
1279
+ hasDigits = true;
1280
+ }
1281
+ return hasDigits && ch !== '_';
1282
+ }
1283
+ }
1284
+
1285
+ // base 10 (except 0)
1286
+
1287
+ // value should not start with `_`;
1288
+ if (ch === '_') return false;
1289
+
1290
+ for (; index < max; index++) {
1291
+ ch = data[index];
1292
+ if (ch === '_') continue;
1293
+ if (!isDecCode(data.charCodeAt(index))) {
1294
+ return false;
1295
+ }
1296
+ hasDigits = true;
1297
+ }
1298
+
1299
+ // Should have digits and should not end with `_`
1300
+ if (!hasDigits || ch === '_') return false;
1301
+
1302
+ return true;
1303
+ }
1304
+
1305
+ function constructYamlInteger(data) {
1306
+ var value = data, sign = 1, ch;
1307
+
1308
+ if (value.indexOf('_') !== -1) {
1309
+ value = value.replace(/_/g, '');
1310
+ }
1311
+
1312
+ ch = value[0];
1313
+
1314
+ if (ch === '-' || ch === '+') {
1315
+ if (ch === '-') sign = -1;
1316
+ value = value.slice(1);
1317
+ ch = value[0];
1318
+ }
1319
+
1320
+ if (value === '0') return 0;
1321
+
1322
+ if (ch === '0') {
1323
+ if (value[1] === 'b') return sign * parseInt(value.slice(2), 2);
1324
+ if (value[1] === 'x') return sign * parseInt(value.slice(2), 16);
1325
+ if (value[1] === 'o') return sign * parseInt(value.slice(2), 8);
1326
+ }
1327
+
1328
+ return sign * parseInt(value, 10);
1329
+ }
1330
+
1331
+ function isInteger(object) {
1332
+ return (Object.prototype.toString.call(object)) === '[object Number]' &&
1333
+ (object % 1 === 0 && !common.isNegativeZero(object));
1334
+ }
1335
+
1336
+ var int = new type('tag:yaml.org,2002:int', {
1337
+ kind: 'scalar',
1338
+ resolve: resolveYamlInteger,
1339
+ construct: constructYamlInteger,
1340
+ predicate: isInteger,
1341
+ represent: {
1342
+ binary: function (obj) { return obj >= 0 ? '0b' + obj.toString(2) : '-0b' + obj.toString(2).slice(1); },
1343
+ octal: function (obj) { return obj >= 0 ? '0o' + obj.toString(8) : '-0o' + obj.toString(8).slice(1); },
1344
+ decimal: function (obj) { return obj.toString(10); },
1345
+ /* eslint-disable max-len */
1346
+ hexadecimal: function (obj) { return obj >= 0 ? '0x' + obj.toString(16).toUpperCase() : '-0x' + obj.toString(16).toUpperCase().slice(1); }
1347
+ },
1348
+ defaultStyle: 'decimal',
1349
+ styleAliases: {
1350
+ binary: [ 2, 'bin' ],
1351
+ octal: [ 8, 'oct' ],
1352
+ decimal: [ 10, 'dec' ],
1353
+ hexadecimal: [ 16, 'hex' ]
1354
+ }
1355
+ });
1356
+
1357
+ var YAML_FLOAT_PATTERN = new RegExp(
1358
+ // 2.5e4, 2.5 and integers
1359
+ '^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?' +
1360
+ // .2e4, .2
1361
+ // special case, seems not from spec
1362
+ '|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?' +
1363
+ // .inf
1364
+ '|[-+]?\\.(?:inf|Inf|INF)' +
1365
+ // .nan
1366
+ '|\\.(?:nan|NaN|NAN))$');
1367
+
1368
+ function resolveYamlFloat(data) {
1369
+ if (data === null) return false;
1370
+
1371
+ if (!YAML_FLOAT_PATTERN.test(data) ||
1372
+ // Quick hack to not allow integers end with `_`
1373
+ // Probably should update regexp & check speed
1374
+ data[data.length - 1] === '_') {
1375
+ return false;
1376
+ }
1377
+
1378
+ return true;
1379
+ }
1380
+
1381
+ function constructYamlFloat(data) {
1382
+ var value, sign;
1383
+
1384
+ value = data.replace(/_/g, '').toLowerCase();
1385
+ sign = value[0] === '-' ? -1 : 1;
1386
+
1387
+ if ('+-'.indexOf(value[0]) >= 0) {
1388
+ value = value.slice(1);
1389
+ }
1390
+
1391
+ if (value === '.inf') {
1392
+ return (sign === 1) ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
1393
+
1394
+ } else if (value === '.nan') {
1395
+ return NaN;
1396
+ }
1397
+ return sign * parseFloat(value, 10);
1398
+ }
1399
+
1400
+
1401
+ var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
1402
+
1403
+ function representYamlFloat(object, style) {
1404
+ var res;
1405
+
1406
+ if (isNaN(object)) {
1407
+ switch (style) {
1408
+ case 'lowercase': return '.nan';
1409
+ case 'uppercase': return '.NAN';
1410
+ case 'camelcase': return '.NaN';
1411
+ }
1412
+ } else if (Number.POSITIVE_INFINITY === object) {
1413
+ switch (style) {
1414
+ case 'lowercase': return '.inf';
1415
+ case 'uppercase': return '.INF';
1416
+ case 'camelcase': return '.Inf';
1417
+ }
1418
+ } else if (Number.NEGATIVE_INFINITY === object) {
1419
+ switch (style) {
1420
+ case 'lowercase': return '-.inf';
1421
+ case 'uppercase': return '-.INF';
1422
+ case 'camelcase': return '-.Inf';
1423
+ }
1424
+ } else if (common.isNegativeZero(object)) {
1425
+ return '-0.0';
1426
+ }
1427
+
1428
+ res = object.toString(10);
1429
+
1430
+ // JS stringifier can build scientific format without dots: 5e-100,
1431
+ // while YAML requres dot: 5.e-100. Fix it with simple hack
1432
+
1433
+ return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace('e', '.e') : res;
1434
+ }
1435
+
1436
+ function isFloat(object) {
1437
+ return (Object.prototype.toString.call(object) === '[object Number]') &&
1438
+ (object % 1 !== 0 || common.isNegativeZero(object));
1439
+ }
1440
+
1441
+ var float = new type('tag:yaml.org,2002:float', {
1442
+ kind: 'scalar',
1443
+ resolve: resolveYamlFloat,
1444
+ construct: constructYamlFloat,
1445
+ predicate: isFloat,
1446
+ represent: representYamlFloat,
1447
+ defaultStyle: 'lowercase'
1448
+ });
1449
+
1450
+ var json = failsafe.extend({
1451
+ implicit: [
1452
+ _null,
1453
+ bool,
1454
+ int,
1455
+ float
1456
+ ]
1457
+ });
1458
+
1459
+ var core = json;
1460
+
1461
+ var YAML_DATE_REGEXP = new RegExp(
1462
+ '^([0-9][0-9][0-9][0-9])' + // [1] year
1463
+ '-([0-9][0-9])' + // [2] month
1464
+ '-([0-9][0-9])$'); // [3] day
1465
+
1466
+ var YAML_TIMESTAMP_REGEXP = new RegExp(
1467
+ '^([0-9][0-9][0-9][0-9])' + // [1] year
1468
+ '-([0-9][0-9]?)' + // [2] month
1469
+ '-([0-9][0-9]?)' + // [3] day
1470
+ '(?:[Tt]|[ \\t]+)' + // ...
1471
+ '([0-9][0-9]?)' + // [4] hour
1472
+ ':([0-9][0-9])' + // [5] minute
1473
+ ':([0-9][0-9])' + // [6] second
1474
+ '(?:\\.([0-9]*))?' + // [7] fraction
1475
+ '(?:[ \\t]*(Z|([-+])([0-9][0-9]?)' + // [8] tz [9] tz_sign [10] tz_hour
1476
+ '(?::([0-9][0-9]))?))?$'); // [11] tz_minute
1477
+
1478
+ function resolveYamlTimestamp(data) {
1479
+ if (data === null) return false;
1480
+ if (YAML_DATE_REGEXP.exec(data) !== null) return true;
1481
+ if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true;
1482
+ return false;
1483
+ }
1484
+
1485
+ function constructYamlTimestamp(data) {
1486
+ var match, year, month, day, hour, minute, second, fraction = 0,
1487
+ delta = null, tz_hour, tz_minute, date;
1488
+
1489
+ match = YAML_DATE_REGEXP.exec(data);
1490
+ if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
1491
+
1492
+ if (match === null) throw new Error('Date resolve error');
1493
+
1494
+ // match: [1] year [2] month [3] day
1495
+
1496
+ year = +(match[1]);
1497
+ month = +(match[2]) - 1; // JS month starts with 0
1498
+ day = +(match[3]);
1499
+
1500
+ if (!match[4]) { // no hour
1501
+ return new Date(Date.UTC(year, month, day));
1502
+ }
1503
+
1504
+ // match: [4] hour [5] minute [6] second [7] fraction
1505
+
1506
+ hour = +(match[4]);
1507
+ minute = +(match[5]);
1508
+ second = +(match[6]);
1509
+
1510
+ if (match[7]) {
1511
+ fraction = match[7].slice(0, 3);
1512
+ while (fraction.length < 3) { // milli-seconds
1513
+ fraction += '0';
1514
+ }
1515
+ fraction = +fraction;
1516
+ }
1517
+
1518
+ // match: [8] tz [9] tz_sign [10] tz_hour [11] tz_minute
1519
+
1520
+ if (match[9]) {
1521
+ tz_hour = +(match[10]);
1522
+ tz_minute = +(match[11] || 0);
1523
+ delta = (tz_hour * 60 + tz_minute) * 60000; // delta in mili-seconds
1524
+ if (match[9] === '-') delta = -delta;
1525
+ }
1526
+
1527
+ date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
1528
+
1529
+ if (delta) date.setTime(date.getTime() - delta);
1530
+
1531
+ return date;
1532
+ }
1533
+
1534
+ function representYamlTimestamp(object /*, style*/) {
1535
+ return object.toISOString();
1536
+ }
1537
+
1538
+ var timestamp = new type('tag:yaml.org,2002:timestamp', {
1539
+ kind: 'scalar',
1540
+ resolve: resolveYamlTimestamp,
1541
+ construct: constructYamlTimestamp,
1542
+ instanceOf: Date,
1543
+ represent: representYamlTimestamp
1544
+ });
1545
+
1546
+ function resolveYamlMerge(data) {
1547
+ return data === '<<' || data === null;
1548
+ }
1549
+
1550
+ var merge = new type('tag:yaml.org,2002:merge', {
1551
+ kind: 'scalar',
1552
+ resolve: resolveYamlMerge
1553
+ });
1554
+
1555
+ /*eslint-disable no-bitwise*/
1556
+
1557
+
1558
+
1559
+
1560
+
1561
+ // [ 64, 65, 66 ] -> [ padding, CR, LF ]
1562
+ var BASE64_MAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r';
1563
+
1564
+
1565
+ function resolveYamlBinary(data) {
1566
+ if (data === null) return false;
1567
+
1568
+ var code, idx, bitlen = 0, max = data.length, map = BASE64_MAP;
1569
+
1570
+ // Convert one by one.
1571
+ for (idx = 0; idx < max; idx++) {
1572
+ code = map.indexOf(data.charAt(idx));
1573
+
1574
+ // Skip CR/LF
1575
+ if (code > 64) continue;
1576
+
1577
+ // Fail on illegal characters
1578
+ if (code < 0) return false;
1579
+
1580
+ bitlen += 6;
1581
+ }
1582
+
1583
+ // If there are any bits left, source was corrupted
1584
+ return (bitlen % 8) === 0;
1585
+ }
1586
+
1587
+ function constructYamlBinary(data) {
1588
+ var idx, tailbits,
1589
+ input = data.replace(/[\r\n=]/g, ''), // remove CR/LF & padding to simplify scan
1590
+ max = input.length,
1591
+ map = BASE64_MAP,
1592
+ bits = 0,
1593
+ result = [];
1594
+
1595
+ // Collect by 6*4 bits (3 bytes)
1596
+
1597
+ for (idx = 0; idx < max; idx++) {
1598
+ if ((idx % 4 === 0) && idx) {
1599
+ result.push((bits >> 16) & 0xFF);
1600
+ result.push((bits >> 8) & 0xFF);
1601
+ result.push(bits & 0xFF);
1602
+ }
1603
+
1604
+ bits = (bits << 6) | map.indexOf(input.charAt(idx));
1605
+ }
1606
+
1607
+ // Dump tail
1608
+
1609
+ tailbits = (max % 4) * 6;
1610
+
1611
+ if (tailbits === 0) {
1612
+ result.push((bits >> 16) & 0xFF);
1613
+ result.push((bits >> 8) & 0xFF);
1614
+ result.push(bits & 0xFF);
1615
+ } else if (tailbits === 18) {
1616
+ result.push((bits >> 10) & 0xFF);
1617
+ result.push((bits >> 2) & 0xFF);
1618
+ } else if (tailbits === 12) {
1619
+ result.push((bits >> 4) & 0xFF);
1620
+ }
1621
+
1622
+ return new Uint8Array(result);
1623
+ }
1624
+
1625
+ function representYamlBinary(object /*, style*/) {
1626
+ var result = '', bits = 0, idx, tail,
1627
+ max = object.length,
1628
+ map = BASE64_MAP;
1629
+
1630
+ // Convert every three bytes to 4 ASCII characters.
1631
+
1632
+ for (idx = 0; idx < max; idx++) {
1633
+ if ((idx % 3 === 0) && idx) {
1634
+ result += map[(bits >> 18) & 0x3F];
1635
+ result += map[(bits >> 12) & 0x3F];
1636
+ result += map[(bits >> 6) & 0x3F];
1637
+ result += map[bits & 0x3F];
1638
+ }
1639
+
1640
+ bits = (bits << 8) + object[idx];
1641
+ }
1642
+
1643
+ // Dump tail
1644
+
1645
+ tail = max % 3;
1646
+
1647
+ if (tail === 0) {
1648
+ result += map[(bits >> 18) & 0x3F];
1649
+ result += map[(bits >> 12) & 0x3F];
1650
+ result += map[(bits >> 6) & 0x3F];
1651
+ result += map[bits & 0x3F];
1652
+ } else if (tail === 2) {
1653
+ result += map[(bits >> 10) & 0x3F];
1654
+ result += map[(bits >> 4) & 0x3F];
1655
+ result += map[(bits << 2) & 0x3F];
1656
+ result += map[64];
1657
+ } else if (tail === 1) {
1658
+ result += map[(bits >> 2) & 0x3F];
1659
+ result += map[(bits << 4) & 0x3F];
1660
+ result += map[64];
1661
+ result += map[64];
1662
+ }
1663
+
1664
+ return result;
1665
+ }
1666
+
1667
+ function isBinary(obj) {
1668
+ return Object.prototype.toString.call(obj) === '[object Uint8Array]';
1669
+ }
1670
+
1671
+ var binary = new type('tag:yaml.org,2002:binary', {
1672
+ kind: 'scalar',
1673
+ resolve: resolveYamlBinary,
1674
+ construct: constructYamlBinary,
1675
+ predicate: isBinary,
1676
+ represent: representYamlBinary
1677
+ });
1678
+
1679
+ var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
1680
+ var _toString$2 = Object.prototype.toString;
1681
+
1682
+ function resolveYamlOmap(data) {
1683
+ if (data === null) return true;
1684
+
1685
+ var objectKeys = [], index, length, pair, pairKey, pairHasKey,
1686
+ object = data;
1687
+
1688
+ for (index = 0, length = object.length; index < length; index += 1) {
1689
+ pair = object[index];
1690
+ pairHasKey = false;
1691
+
1692
+ if (_toString$2.call(pair) !== '[object Object]') return false;
1693
+
1694
+ for (pairKey in pair) {
1695
+ if (_hasOwnProperty$3.call(pair, pairKey)) {
1696
+ if (!pairHasKey) pairHasKey = true;
1697
+ else return false;
1698
+ }
1699
+ }
1700
+
1701
+ if (!pairHasKey) return false;
1702
+
1703
+ if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);
1704
+ else return false;
1705
+ }
1706
+
1707
+ return true;
1708
+ }
1709
+
1710
+ function constructYamlOmap(data) {
1711
+ return data !== null ? data : [];
1712
+ }
1713
+
1714
+ var omap = new type('tag:yaml.org,2002:omap', {
1715
+ kind: 'sequence',
1716
+ resolve: resolveYamlOmap,
1717
+ construct: constructYamlOmap
1718
+ });
1719
+
1720
+ var _toString$1 = Object.prototype.toString;
1721
+
1722
+ function resolveYamlPairs(data) {
1723
+ if (data === null) return true;
1724
+
1725
+ var index, length, pair, keys, result,
1726
+ object = data;
1727
+
1728
+ result = new Array(object.length);
1729
+
1730
+ for (index = 0, length = object.length; index < length; index += 1) {
1731
+ pair = object[index];
1732
+
1733
+ if (_toString$1.call(pair) !== '[object Object]') return false;
1734
+
1735
+ keys = Object.keys(pair);
1736
+
1737
+ if (keys.length !== 1) return false;
1738
+
1739
+ result[index] = [ keys[0], pair[keys[0]] ];
1740
+ }
1741
+
1742
+ return true;
1743
+ }
1744
+
1745
+ function constructYamlPairs(data) {
1746
+ if (data === null) return [];
1747
+
1748
+ var index, length, pair, keys, result,
1749
+ object = data;
1750
+
1751
+ result = new Array(object.length);
1752
+
1753
+ for (index = 0, length = object.length; index < length; index += 1) {
1754
+ pair = object[index];
1755
+
1756
+ keys = Object.keys(pair);
1757
+
1758
+ result[index] = [ keys[0], pair[keys[0]] ];
1759
+ }
1760
+
1761
+ return result;
1762
+ }
1763
+
1764
+ var pairs = new type('tag:yaml.org,2002:pairs', {
1765
+ kind: 'sequence',
1766
+ resolve: resolveYamlPairs,
1767
+ construct: constructYamlPairs
1768
+ });
1769
+
1770
+ var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
1771
+
1772
+ function resolveYamlSet(data) {
1773
+ if (data === null) return true;
1774
+
1775
+ var key, object = data;
1776
+
1777
+ for (key in object) {
1778
+ if (_hasOwnProperty$2.call(object, key)) {
1779
+ if (object[key] !== null) return false;
1780
+ }
1781
+ }
1782
+
1783
+ return true;
1784
+ }
1785
+
1786
+ function constructYamlSet(data) {
1787
+ return data !== null ? data : {};
1788
+ }
1789
+
1790
+ var set = new type('tag:yaml.org,2002:set', {
1791
+ kind: 'mapping',
1792
+ resolve: resolveYamlSet,
1793
+ construct: constructYamlSet
1794
+ });
1795
+
1796
+ var _default = core.extend({
1797
+ implicit: [
1798
+ timestamp,
1799
+ merge
1800
+ ],
1801
+ explicit: [
1802
+ binary,
1803
+ omap,
1804
+ pairs,
1805
+ set
1806
+ ]
1807
+ });
1808
+
1809
+ /*eslint-disable max-len,no-use-before-define*/
1810
+
1811
+
1812
+
1813
+
1814
+
1815
+
1816
+
1817
+ var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
1818
+
1819
+
1820
+ var CONTEXT_FLOW_IN = 1;
1821
+ var CONTEXT_FLOW_OUT = 2;
1822
+ var CONTEXT_BLOCK_IN = 3;
1823
+ var CONTEXT_BLOCK_OUT = 4;
1824
+
1825
+
1826
+ var CHOMPING_CLIP = 1;
1827
+ var CHOMPING_STRIP = 2;
1828
+ var CHOMPING_KEEP = 3;
1829
+
1830
+
1831
+ var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
1832
+ var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
1833
+ var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
1834
+ var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
1835
+ var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
1836
+
1837
+
1838
+ function _class(obj) { return Object.prototype.toString.call(obj); }
1839
+
1840
+ function is_EOL(c) {
1841
+ return (c === 0x0A/* LF */) || (c === 0x0D/* CR */);
1842
+ }
1843
+
1844
+ function is_WHITE_SPACE(c) {
1845
+ return (c === 0x09/* Tab */) || (c === 0x20/* Space */);
1846
+ }
1847
+
1848
+ function is_WS_OR_EOL(c) {
1849
+ return (c === 0x09/* Tab */) ||
1850
+ (c === 0x20/* Space */) ||
1851
+ (c === 0x0A/* LF */) ||
1852
+ (c === 0x0D/* CR */);
1853
+ }
1854
+
1855
+ function is_FLOW_INDICATOR(c) {
1856
+ return c === 0x2C/* , */ ||
1857
+ c === 0x5B/* [ */ ||
1858
+ c === 0x5D/* ] */ ||
1859
+ c === 0x7B/* { */ ||
1860
+ c === 0x7D/* } */;
1861
+ }
1862
+
1863
+ function fromHexCode(c) {
1864
+ var lc;
1865
+
1866
+ if ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) {
1867
+ return c - 0x30;
1868
+ }
1869
+
1870
+ /*eslint-disable no-bitwise*/
1871
+ lc = c | 0x20;
1872
+
1873
+ if ((0x61/* a */ <= lc) && (lc <= 0x66/* f */)) {
1874
+ return lc - 0x61 + 10;
1875
+ }
1876
+
1877
+ return -1;
1878
+ }
1879
+
1880
+ function escapedHexLen(c) {
1881
+ if (c === 0x78/* x */) { return 2; }
1882
+ if (c === 0x75/* u */) { return 4; }
1883
+ if (c === 0x55/* U */) { return 8; }
1884
+ return 0;
1885
+ }
1886
+
1887
+ function fromDecimalCode(c) {
1888
+ if ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) {
1889
+ return c - 0x30;
1890
+ }
1891
+
1892
+ return -1;
1893
+ }
1894
+
1895
+ function simpleEscapeSequence(c) {
1896
+ /* eslint-disable indent */
1897
+ return (c === 0x30/* 0 */) ? '\x00' :
1898
+ (c === 0x61/* a */) ? '\x07' :
1899
+ (c === 0x62/* b */) ? '\x08' :
1900
+ (c === 0x74/* t */) ? '\x09' :
1901
+ (c === 0x09/* Tab */) ? '\x09' :
1902
+ (c === 0x6E/* n */) ? '\x0A' :
1903
+ (c === 0x76/* v */) ? '\x0B' :
1904
+ (c === 0x66/* f */) ? '\x0C' :
1905
+ (c === 0x72/* r */) ? '\x0D' :
1906
+ (c === 0x65/* e */) ? '\x1B' :
1907
+ (c === 0x20/* Space */) ? ' ' :
1908
+ (c === 0x22/* " */) ? '\x22' :
1909
+ (c === 0x2F/* / */) ? '/' :
1910
+ (c === 0x5C/* \ */) ? '\x5C' :
1911
+ (c === 0x4E/* N */) ? '\x85' :
1912
+ (c === 0x5F/* _ */) ? '\xA0' :
1913
+ (c === 0x4C/* L */) ? '\u2028' :
1914
+ (c === 0x50/* P */) ? '\u2029' : '';
1915
+ }
1916
+
1917
+ function charFromCodepoint(c) {
1918
+ if (c <= 0xFFFF) {
1919
+ return String.fromCharCode(c);
1920
+ }
1921
+ // Encode UTF-16 surrogate pair
1922
+ // https://en.wikipedia.org/wiki/UTF-16#Code_points_U.2B010000_to_U.2B10FFFF
1923
+ return String.fromCharCode(
1924
+ ((c - 0x010000) >> 10) + 0xD800,
1925
+ ((c - 0x010000) & 0x03FF) + 0xDC00
1926
+ );
1927
+ }
1928
+
1929
+ var simpleEscapeCheck = new Array(256); // integer, for fast access
1930
+ var simpleEscapeMap = new Array(256);
1931
+ for (var i = 0; i < 256; i++) {
1932
+ simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
1933
+ simpleEscapeMap[i] = simpleEscapeSequence(i);
1934
+ }
1935
+
1936
+
1937
+ function State$1(input, options) {
1938
+ this.input = input;
1939
+
1940
+ this.filename = options['filename'] || null;
1941
+ this.schema = options['schema'] || _default;
1942
+ this.onWarning = options['onWarning'] || null;
1943
+ // (Hidden) Remove? makes the loader to expect YAML 1.1 documents
1944
+ // if such documents have no explicit %YAML directive
1945
+ this.legacy = options['legacy'] || false;
1946
+
1947
+ this.json = options['json'] || false;
1948
+ this.listener = options['listener'] || null;
1949
+
1950
+ this.implicitTypes = this.schema.compiledImplicit;
1951
+ this.typeMap = this.schema.compiledTypeMap;
1952
+
1953
+ this.length = input.length;
1954
+ this.position = 0;
1955
+ this.line = 0;
1956
+ this.lineStart = 0;
1957
+ this.lineIndent = 0;
1958
+
1959
+ // position of first leading tab in the current line,
1960
+ // used to make sure there are no tabs in the indentation
1961
+ this.firstTabInLine = -1;
1962
+
1963
+ this.documents = [];
1964
+
1965
+ /*
1966
+ this.version;
1967
+ this.checkLineBreaks;
1968
+ this.tagMap;
1969
+ this.anchorMap;
1970
+ this.tag;
1971
+ this.anchor;
1972
+ this.kind;
1973
+ this.result;*/
1974
+
1975
+ }
1976
+
1977
+
1978
+ function generateError(state, message) {
1979
+ var mark = {
1980
+ name: state.filename,
1981
+ buffer: state.input.slice(0, -1), // omit trailing \0
1982
+ position: state.position,
1983
+ line: state.line,
1984
+ column: state.position - state.lineStart
1985
+ };
1986
+
1987
+ mark.snippet = snippet(mark);
1988
+
1989
+ return new exception(message, mark);
1990
+ }
1991
+
1992
+ function throwError(state, message) {
1993
+ throw generateError(state, message);
1994
+ }
1995
+
1996
+ function throwWarning(state, message) {
1997
+ if (state.onWarning) {
1998
+ state.onWarning.call(null, generateError(state, message));
1999
+ }
2000
+ }
2001
+
2002
+
2003
+ var directiveHandlers = {
2004
+
2005
+ YAML: function handleYamlDirective(state, name, args) {
2006
+
2007
+ var match, major, minor;
2008
+
2009
+ if (state.version !== null) {
2010
+ throwError(state, 'duplication of %YAML directive');
2011
+ }
2012
+
2013
+ if (args.length !== 1) {
2014
+ throwError(state, 'YAML directive accepts exactly one argument');
2015
+ }
2016
+
2017
+ match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
2018
+
2019
+ if (match === null) {
2020
+ throwError(state, 'ill-formed argument of the YAML directive');
2021
+ }
2022
+
2023
+ major = parseInt(match[1], 10);
2024
+ minor = parseInt(match[2], 10);
2025
+
2026
+ if (major !== 1) {
2027
+ throwError(state, 'unacceptable YAML version of the document');
2028
+ }
2029
+
2030
+ state.version = args[0];
2031
+ state.checkLineBreaks = (minor < 2);
2032
+
2033
+ if (minor !== 1 && minor !== 2) {
2034
+ throwWarning(state, 'unsupported YAML version of the document');
2035
+ }
2036
+ },
2037
+
2038
+ TAG: function handleTagDirective(state, name, args) {
2039
+
2040
+ var handle, prefix;
2041
+
2042
+ if (args.length !== 2) {
2043
+ throwError(state, 'TAG directive accepts exactly two arguments');
2044
+ }
2045
+
2046
+ handle = args[0];
2047
+ prefix = args[1];
2048
+
2049
+ if (!PATTERN_TAG_HANDLE.test(handle)) {
2050
+ throwError(state, 'ill-formed tag handle (first argument) of the TAG directive');
2051
+ }
2052
+
2053
+ if (_hasOwnProperty$1.call(state.tagMap, handle)) {
2054
+ throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
2055
+ }
2056
+
2057
+ if (!PATTERN_TAG_URI.test(prefix)) {
2058
+ throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive');
2059
+ }
2060
+
2061
+ try {
2062
+ prefix = decodeURIComponent(prefix);
2063
+ } catch (err) {
2064
+ throwError(state, 'tag prefix is malformed: ' + prefix);
2065
+ }
2066
+
2067
+ state.tagMap[handle] = prefix;
2068
+ }
2069
+ };
2070
+
2071
+
2072
+ function captureSegment(state, start, end, checkJson) {
2073
+ var _position, _length, _character, _result;
2074
+
2075
+ if (start < end) {
2076
+ _result = state.input.slice(start, end);
2077
+
2078
+ if (checkJson) {
2079
+ for (_position = 0, _length = _result.length; _position < _length; _position += 1) {
2080
+ _character = _result.charCodeAt(_position);
2081
+ if (!(_character === 0x09 ||
2082
+ (0x20 <= _character && _character <= 0x10FFFF))) {
2083
+ throwError(state, 'expected valid JSON character');
2084
+ }
2085
+ }
2086
+ } else if (PATTERN_NON_PRINTABLE.test(_result)) {
2087
+ throwError(state, 'the stream contains non-printable characters');
2088
+ }
2089
+
2090
+ state.result += _result;
2091
+ }
2092
+ }
2093
+
2094
+ function mergeMappings(state, destination, source, overridableKeys) {
2095
+ var sourceKeys, key, index, quantity;
2096
+
2097
+ if (!common.isObject(source)) {
2098
+ throwError(state, 'cannot merge mappings; the provided source object is unacceptable');
2099
+ }
2100
+
2101
+ sourceKeys = Object.keys(source);
2102
+
2103
+ for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
2104
+ key = sourceKeys[index];
2105
+
2106
+ if (!_hasOwnProperty$1.call(destination, key)) {
2107
+ destination[key] = source[key];
2108
+ overridableKeys[key] = true;
2109
+ }
2110
+ }
2111
+ }
2112
+
2113
+ function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode,
2114
+ startLine, startLineStart, startPos) {
2115
+
2116
+ var index, quantity;
2117
+
2118
+ // The output is a plain object here, so keys can only be strings.
2119
+ // We need to convert keyNode to a string, but doing so can hang the process
2120
+ // (deeply nested arrays that explode exponentially using aliases).
2121
+ if (Array.isArray(keyNode)) {
2122
+ keyNode = Array.prototype.slice.call(keyNode);
2123
+
2124
+ for (index = 0, quantity = keyNode.length; index < quantity; index += 1) {
2125
+ if (Array.isArray(keyNode[index])) {
2126
+ throwError(state, 'nested arrays are not supported inside keys');
2127
+ }
2128
+
2129
+ if (typeof keyNode === 'object' && _class(keyNode[index]) === '[object Object]') {
2130
+ keyNode[index] = '[object Object]';
2131
+ }
2132
+ }
2133
+ }
2134
+
2135
+ // Avoid code execution in load() via toString property
2136
+ // (still use its own toString for arrays, timestamps,
2137
+ // and whatever user schema extensions happen to have @@toStringTag)
2138
+ if (typeof keyNode === 'object' && _class(keyNode) === '[object Object]') {
2139
+ keyNode = '[object Object]';
2140
+ }
2141
+
2142
+
2143
+ keyNode = String(keyNode);
2144
+
2145
+ if (_result === null) {
2146
+ _result = {};
2147
+ }
2148
+
2149
+ if (keyTag === 'tag:yaml.org,2002:merge') {
2150
+ if (Array.isArray(valueNode)) {
2151
+ for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
2152
+ mergeMappings(state, _result, valueNode[index], overridableKeys);
2153
+ }
2154
+ } else {
2155
+ mergeMappings(state, _result, valueNode, overridableKeys);
2156
+ }
2157
+ } else {
2158
+ if (!state.json &&
2159
+ !_hasOwnProperty$1.call(overridableKeys, keyNode) &&
2160
+ _hasOwnProperty$1.call(_result, keyNode)) {
2161
+ state.line = startLine || state.line;
2162
+ state.lineStart = startLineStart || state.lineStart;
2163
+ state.position = startPos || state.position;
2164
+ throwError(state, 'duplicated mapping key');
2165
+ }
2166
+
2167
+ // used for this specific key only because Object.defineProperty is slow
2168
+ if (keyNode === '__proto__') {
2169
+ Object.defineProperty(_result, keyNode, {
2170
+ configurable: true,
2171
+ enumerable: true,
2172
+ writable: true,
2173
+ value: valueNode
2174
+ });
2175
+ } else {
2176
+ _result[keyNode] = valueNode;
2177
+ }
2178
+ delete overridableKeys[keyNode];
2179
+ }
2180
+
2181
+ return _result;
2182
+ }
2183
+
2184
+ function readLineBreak(state) {
2185
+ var ch;
2186
+
2187
+ ch = state.input.charCodeAt(state.position);
2188
+
2189
+ if (ch === 0x0A/* LF */) {
2190
+ state.position++;
2191
+ } else if (ch === 0x0D/* CR */) {
2192
+ state.position++;
2193
+ if (state.input.charCodeAt(state.position) === 0x0A/* LF */) {
2194
+ state.position++;
2195
+ }
2196
+ } else {
2197
+ throwError(state, 'a line break is expected');
2198
+ }
2199
+
2200
+ state.line += 1;
2201
+ state.lineStart = state.position;
2202
+ state.firstTabInLine = -1;
2203
+ }
2204
+
2205
+ function skipSeparationSpace(state, allowComments, checkIndent) {
2206
+ var lineBreaks = 0,
2207
+ ch = state.input.charCodeAt(state.position);
2208
+
2209
+ while (ch !== 0) {
2210
+ while (is_WHITE_SPACE(ch)) {
2211
+ if (ch === 0x09/* Tab */ && state.firstTabInLine === -1) {
2212
+ state.firstTabInLine = state.position;
2213
+ }
2214
+ ch = state.input.charCodeAt(++state.position);
2215
+ }
2216
+
2217
+ if (allowComments && ch === 0x23/* # */) {
2218
+ do {
2219
+ ch = state.input.charCodeAt(++state.position);
2220
+ } while (ch !== 0x0A/* LF */ && ch !== 0x0D/* CR */ && ch !== 0);
2221
+ }
2222
+
2223
+ if (is_EOL(ch)) {
2224
+ readLineBreak(state);
2225
+
2226
+ ch = state.input.charCodeAt(state.position);
2227
+ lineBreaks++;
2228
+ state.lineIndent = 0;
2229
+
2230
+ while (ch === 0x20/* Space */) {
2231
+ state.lineIndent++;
2232
+ ch = state.input.charCodeAt(++state.position);
2233
+ }
2234
+ } else {
2235
+ break;
2236
+ }
2237
+ }
2238
+
2239
+ if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
2240
+ throwWarning(state, 'deficient indentation');
2241
+ }
2242
+
2243
+ return lineBreaks;
2244
+ }
2245
+
2246
+ function testDocumentSeparator(state) {
2247
+ var _position = state.position,
2248
+ ch;
2249
+
2250
+ ch = state.input.charCodeAt(_position);
2251
+
2252
+ // Condition state.position === state.lineStart is tested
2253
+ // in parent on each call, for efficiency. No needs to test here again.
2254
+ if ((ch === 0x2D/* - */ || ch === 0x2E/* . */) &&
2255
+ ch === state.input.charCodeAt(_position + 1) &&
2256
+ ch === state.input.charCodeAt(_position + 2)) {
2257
+
2258
+ _position += 3;
2259
+
2260
+ ch = state.input.charCodeAt(_position);
2261
+
2262
+ if (ch === 0 || is_WS_OR_EOL(ch)) {
2263
+ return true;
2264
+ }
2265
+ }
2266
+
2267
+ return false;
2268
+ }
2269
+
2270
+ function writeFoldedLines(state, count) {
2271
+ if (count === 1) {
2272
+ state.result += ' ';
2273
+ } else if (count > 1) {
2274
+ state.result += common.repeat('\n', count - 1);
2275
+ }
2276
+ }
2277
+
2278
+
2279
+ function readPlainScalar(state, nodeIndent, withinFlowCollection) {
2280
+ var preceding,
2281
+ following,
2282
+ captureStart,
2283
+ captureEnd,
2284
+ hasPendingContent,
2285
+ _line,
2286
+ _lineStart,
2287
+ _lineIndent,
2288
+ _kind = state.kind,
2289
+ _result = state.result,
2290
+ ch;
2291
+
2292
+ ch = state.input.charCodeAt(state.position);
2293
+
2294
+ if (is_WS_OR_EOL(ch) ||
2295
+ is_FLOW_INDICATOR(ch) ||
2296
+ ch === 0x23/* # */ ||
2297
+ ch === 0x26/* & */ ||
2298
+ ch === 0x2A/* * */ ||
2299
+ ch === 0x21/* ! */ ||
2300
+ ch === 0x7C/* | */ ||
2301
+ ch === 0x3E/* > */ ||
2302
+ ch === 0x27/* ' */ ||
2303
+ ch === 0x22/* " */ ||
2304
+ ch === 0x25/* % */ ||
2305
+ ch === 0x40/* @ */ ||
2306
+ ch === 0x60/* ` */) {
2307
+ return false;
2308
+ }
2309
+
2310
+ if (ch === 0x3F/* ? */ || ch === 0x2D/* - */) {
2311
+ following = state.input.charCodeAt(state.position + 1);
2312
+
2313
+ if (is_WS_OR_EOL(following) ||
2314
+ withinFlowCollection && is_FLOW_INDICATOR(following)) {
2315
+ return false;
2316
+ }
2317
+ }
2318
+
2319
+ state.kind = 'scalar';
2320
+ state.result = '';
2321
+ captureStart = captureEnd = state.position;
2322
+ hasPendingContent = false;
2323
+
2324
+ while (ch !== 0) {
2325
+ if (ch === 0x3A/* : */) {
2326
+ following = state.input.charCodeAt(state.position + 1);
2327
+
2328
+ if (is_WS_OR_EOL(following) ||
2329
+ withinFlowCollection && is_FLOW_INDICATOR(following)) {
2330
+ break;
2331
+ }
2332
+
2333
+ } else if (ch === 0x23/* # */) {
2334
+ preceding = state.input.charCodeAt(state.position - 1);
2335
+
2336
+ if (is_WS_OR_EOL(preceding)) {
2337
+ break;
2338
+ }
2339
+
2340
+ } else if ((state.position === state.lineStart && testDocumentSeparator(state)) ||
2341
+ withinFlowCollection && is_FLOW_INDICATOR(ch)) {
2342
+ break;
2343
+
2344
+ } else if (is_EOL(ch)) {
2345
+ _line = state.line;
2346
+ _lineStart = state.lineStart;
2347
+ _lineIndent = state.lineIndent;
2348
+ skipSeparationSpace(state, false, -1);
2349
+
2350
+ if (state.lineIndent >= nodeIndent) {
2351
+ hasPendingContent = true;
2352
+ ch = state.input.charCodeAt(state.position);
2353
+ continue;
2354
+ } else {
2355
+ state.position = captureEnd;
2356
+ state.line = _line;
2357
+ state.lineStart = _lineStart;
2358
+ state.lineIndent = _lineIndent;
2359
+ break;
2360
+ }
2361
+ }
2362
+
2363
+ if (hasPendingContent) {
2364
+ captureSegment(state, captureStart, captureEnd, false);
2365
+ writeFoldedLines(state, state.line - _line);
2366
+ captureStart = captureEnd = state.position;
2367
+ hasPendingContent = false;
2368
+ }
2369
+
2370
+ if (!is_WHITE_SPACE(ch)) {
2371
+ captureEnd = state.position + 1;
2372
+ }
2373
+
2374
+ ch = state.input.charCodeAt(++state.position);
2375
+ }
2376
+
2377
+ captureSegment(state, captureStart, captureEnd, false);
2378
+
2379
+ if (state.result) {
2380
+ return true;
2381
+ }
2382
+
2383
+ state.kind = _kind;
2384
+ state.result = _result;
2385
+ return false;
2386
+ }
2387
+
2388
+ function readSingleQuotedScalar(state, nodeIndent) {
2389
+ var ch,
2390
+ captureStart, captureEnd;
2391
+
2392
+ ch = state.input.charCodeAt(state.position);
2393
+
2394
+ if (ch !== 0x27/* ' */) {
2395
+ return false;
2396
+ }
2397
+
2398
+ state.kind = 'scalar';
2399
+ state.result = '';
2400
+ state.position++;
2401
+ captureStart = captureEnd = state.position;
2402
+
2403
+ while ((ch = state.input.charCodeAt(state.position)) !== 0) {
2404
+ if (ch === 0x27/* ' */) {
2405
+ captureSegment(state, captureStart, state.position, true);
2406
+ ch = state.input.charCodeAt(++state.position);
2407
+
2408
+ if (ch === 0x27/* ' */) {
2409
+ captureStart = state.position;
2410
+ state.position++;
2411
+ captureEnd = state.position;
2412
+ } else {
2413
+ return true;
2414
+ }
2415
+
2416
+ } else if (is_EOL(ch)) {
2417
+ captureSegment(state, captureStart, captureEnd, true);
2418
+ writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
2419
+ captureStart = captureEnd = state.position;
2420
+
2421
+ } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
2422
+ throwError(state, 'unexpected end of the document within a single quoted scalar');
2423
+
2424
+ } else {
2425
+ state.position++;
2426
+ captureEnd = state.position;
2427
+ }
2428
+ }
2429
+
2430
+ throwError(state, 'unexpected end of the stream within a single quoted scalar');
2431
+ }
2432
+
2433
+ function readDoubleQuotedScalar(state, nodeIndent) {
2434
+ var captureStart,
2435
+ captureEnd,
2436
+ hexLength,
2437
+ hexResult,
2438
+ tmp,
2439
+ ch;
2440
+
2441
+ ch = state.input.charCodeAt(state.position);
2442
+
2443
+ if (ch !== 0x22/* " */) {
2444
+ return false;
2445
+ }
2446
+
2447
+ state.kind = 'scalar';
2448
+ state.result = '';
2449
+ state.position++;
2450
+ captureStart = captureEnd = state.position;
2451
+
2452
+ while ((ch = state.input.charCodeAt(state.position)) !== 0) {
2453
+ if (ch === 0x22/* " */) {
2454
+ captureSegment(state, captureStart, state.position, true);
2455
+ state.position++;
2456
+ return true;
2457
+
2458
+ } else if (ch === 0x5C/* \ */) {
2459
+ captureSegment(state, captureStart, state.position, true);
2460
+ ch = state.input.charCodeAt(++state.position);
2461
+
2462
+ if (is_EOL(ch)) {
2463
+ skipSeparationSpace(state, false, nodeIndent);
2464
+
2465
+ // TODO: rework to inline fn with no type cast?
2466
+ } else if (ch < 256 && simpleEscapeCheck[ch]) {
2467
+ state.result += simpleEscapeMap[ch];
2468
+ state.position++;
2469
+
2470
+ } else if ((tmp = escapedHexLen(ch)) > 0) {
2471
+ hexLength = tmp;
2472
+ hexResult = 0;
2473
+
2474
+ for (; hexLength > 0; hexLength--) {
2475
+ ch = state.input.charCodeAt(++state.position);
2476
+
2477
+ if ((tmp = fromHexCode(ch)) >= 0) {
2478
+ hexResult = (hexResult << 4) + tmp;
2479
+
2480
+ } else {
2481
+ throwError(state, 'expected hexadecimal character');
2482
+ }
2483
+ }
2484
+
2485
+ state.result += charFromCodepoint(hexResult);
2486
+
2487
+ state.position++;
2488
+
2489
+ } else {
2490
+ throwError(state, 'unknown escape sequence');
2491
+ }
2492
+
2493
+ captureStart = captureEnd = state.position;
2494
+
2495
+ } else if (is_EOL(ch)) {
2496
+ captureSegment(state, captureStart, captureEnd, true);
2497
+ writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
2498
+ captureStart = captureEnd = state.position;
2499
+
2500
+ } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
2501
+ throwError(state, 'unexpected end of the document within a double quoted scalar');
2502
+
2503
+ } else {
2504
+ state.position++;
2505
+ captureEnd = state.position;
2506
+ }
2507
+ }
2508
+
2509
+ throwError(state, 'unexpected end of the stream within a double quoted scalar');
2510
+ }
2511
+
2512
+ function readFlowCollection(state, nodeIndent) {
2513
+ var readNext = true,
2514
+ _line,
2515
+ _lineStart,
2516
+ _pos,
2517
+ _tag = state.tag,
2518
+ _result,
2519
+ _anchor = state.anchor,
2520
+ following,
2521
+ terminator,
2522
+ isPair,
2523
+ isExplicitPair,
2524
+ isMapping,
2525
+ overridableKeys = Object.create(null),
2526
+ keyNode,
2527
+ keyTag,
2528
+ valueNode,
2529
+ ch;
2530
+
2531
+ ch = state.input.charCodeAt(state.position);
2532
+
2533
+ if (ch === 0x5B/* [ */) {
2534
+ terminator = 0x5D;/* ] */
2535
+ isMapping = false;
2536
+ _result = [];
2537
+ } else if (ch === 0x7B/* { */) {
2538
+ terminator = 0x7D;/* } */
2539
+ isMapping = true;
2540
+ _result = {};
2541
+ } else {
2542
+ return false;
2543
+ }
2544
+
2545
+ if (state.anchor !== null) {
2546
+ state.anchorMap[state.anchor] = _result;
2547
+ }
2548
+
2549
+ ch = state.input.charCodeAt(++state.position);
2550
+
2551
+ while (ch !== 0) {
2552
+ skipSeparationSpace(state, true, nodeIndent);
2553
+
2554
+ ch = state.input.charCodeAt(state.position);
2555
+
2556
+ if (ch === terminator) {
2557
+ state.position++;
2558
+ state.tag = _tag;
2559
+ state.anchor = _anchor;
2560
+ state.kind = isMapping ? 'mapping' : 'sequence';
2561
+ state.result = _result;
2562
+ return true;
2563
+ } else if (!readNext) {
2564
+ throwError(state, 'missed comma between flow collection entries');
2565
+ } else if (ch === 0x2C/* , */) {
2566
+ // "flow collection entries can never be completely empty", as per YAML 1.2, section 7.4
2567
+ throwError(state, "expected the node content, but found ','");
2568
+ }
2569
+
2570
+ keyTag = keyNode = valueNode = null;
2571
+ isPair = isExplicitPair = false;
2572
+
2573
+ if (ch === 0x3F/* ? */) {
2574
+ following = state.input.charCodeAt(state.position + 1);
2575
+
2576
+ if (is_WS_OR_EOL(following)) {
2577
+ isPair = isExplicitPair = true;
2578
+ state.position++;
2579
+ skipSeparationSpace(state, true, nodeIndent);
2580
+ }
2581
+ }
2582
+
2583
+ _line = state.line; // Save the current line.
2584
+ _lineStart = state.lineStart;
2585
+ _pos = state.position;
2586
+ composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
2587
+ keyTag = state.tag;
2588
+ keyNode = state.result;
2589
+ skipSeparationSpace(state, true, nodeIndent);
2590
+
2591
+ ch = state.input.charCodeAt(state.position);
2592
+
2593
+ if ((isExplicitPair || state.line === _line) && ch === 0x3A/* : */) {
2594
+ isPair = true;
2595
+ ch = state.input.charCodeAt(++state.position);
2596
+ skipSeparationSpace(state, true, nodeIndent);
2597
+ composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
2598
+ valueNode = state.result;
2599
+ }
2600
+
2601
+ if (isMapping) {
2602
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos);
2603
+ } else if (isPair) {
2604
+ _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos));
2605
+ } else {
2606
+ _result.push(keyNode);
2607
+ }
2608
+
2609
+ skipSeparationSpace(state, true, nodeIndent);
2610
+
2611
+ ch = state.input.charCodeAt(state.position);
2612
+
2613
+ if (ch === 0x2C/* , */) {
2614
+ readNext = true;
2615
+ ch = state.input.charCodeAt(++state.position);
2616
+ } else {
2617
+ readNext = false;
2618
+ }
2619
+ }
2620
+
2621
+ throwError(state, 'unexpected end of the stream within a flow collection');
2622
+ }
2623
+
2624
+ function readBlockScalar(state, nodeIndent) {
2625
+ var captureStart,
2626
+ folding,
2627
+ chomping = CHOMPING_CLIP,
2628
+ didReadContent = false,
2629
+ detectedIndent = false,
2630
+ textIndent = nodeIndent,
2631
+ emptyLines = 0,
2632
+ atMoreIndented = false,
2633
+ tmp,
2634
+ ch;
2635
+
2636
+ ch = state.input.charCodeAt(state.position);
2637
+
2638
+ if (ch === 0x7C/* | */) {
2639
+ folding = false;
2640
+ } else if (ch === 0x3E/* > */) {
2641
+ folding = true;
2642
+ } else {
2643
+ return false;
2644
+ }
2645
+
2646
+ state.kind = 'scalar';
2647
+ state.result = '';
2648
+
2649
+ while (ch !== 0) {
2650
+ ch = state.input.charCodeAt(++state.position);
2651
+
2652
+ if (ch === 0x2B/* + */ || ch === 0x2D/* - */) {
2653
+ if (CHOMPING_CLIP === chomping) {
2654
+ chomping = (ch === 0x2B/* + */) ? CHOMPING_KEEP : CHOMPING_STRIP;
2655
+ } else {
2656
+ throwError(state, 'repeat of a chomping mode identifier');
2657
+ }
2658
+
2659
+ } else if ((tmp = fromDecimalCode(ch)) >= 0) {
2660
+ if (tmp === 0) {
2661
+ throwError(state, 'bad explicit indentation width of a block scalar; it cannot be less than one');
2662
+ } else if (!detectedIndent) {
2663
+ textIndent = nodeIndent + tmp - 1;
2664
+ detectedIndent = true;
2665
+ } else {
2666
+ throwError(state, 'repeat of an indentation width identifier');
2667
+ }
2668
+
2669
+ } else {
2670
+ break;
2671
+ }
2672
+ }
2673
+
2674
+ if (is_WHITE_SPACE(ch)) {
2675
+ do { ch = state.input.charCodeAt(++state.position); }
2676
+ while (is_WHITE_SPACE(ch));
2677
+
2678
+ if (ch === 0x23/* # */) {
2679
+ do { ch = state.input.charCodeAt(++state.position); }
2680
+ while (!is_EOL(ch) && (ch !== 0));
2681
+ }
2682
+ }
2683
+
2684
+ while (ch !== 0) {
2685
+ readLineBreak(state);
2686
+ state.lineIndent = 0;
2687
+
2688
+ ch = state.input.charCodeAt(state.position);
2689
+
2690
+ while ((!detectedIndent || state.lineIndent < textIndent) &&
2691
+ (ch === 0x20/* Space */)) {
2692
+ state.lineIndent++;
2693
+ ch = state.input.charCodeAt(++state.position);
2694
+ }
2695
+
2696
+ if (!detectedIndent && state.lineIndent > textIndent) {
2697
+ textIndent = state.lineIndent;
2698
+ }
2699
+
2700
+ if (is_EOL(ch)) {
2701
+ emptyLines++;
2702
+ continue;
2703
+ }
2704
+
2705
+ // End of the scalar.
2706
+ if (state.lineIndent < textIndent) {
2707
+
2708
+ // Perform the chomping.
2709
+ if (chomping === CHOMPING_KEEP) {
2710
+ state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
2711
+ } else if (chomping === CHOMPING_CLIP) {
2712
+ if (didReadContent) { // i.e. only if the scalar is not empty.
2713
+ state.result += '\n';
2714
+ }
2715
+ }
2716
+
2717
+ // Break this `while` cycle and go to the funciton's epilogue.
2718
+ break;
2719
+ }
2720
+
2721
+ // Folded style: use fancy rules to handle line breaks.
2722
+ if (folding) {
2723
+
2724
+ // Lines starting with white space characters (more-indented lines) are not folded.
2725
+ if (is_WHITE_SPACE(ch)) {
2726
+ atMoreIndented = true;
2727
+ // except for the first content line (cf. Example 8.1)
2728
+ state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
2729
+
2730
+ // End of more-indented block.
2731
+ } else if (atMoreIndented) {
2732
+ atMoreIndented = false;
2733
+ state.result += common.repeat('\n', emptyLines + 1);
2734
+
2735
+ // Just one line break - perceive as the same line.
2736
+ } else if (emptyLines === 0) {
2737
+ if (didReadContent) { // i.e. only if we have already read some scalar content.
2738
+ state.result += ' ';
2739
+ }
2740
+
2741
+ // Several line breaks - perceive as different lines.
2742
+ } else {
2743
+ state.result += common.repeat('\n', emptyLines);
2744
+ }
2745
+
2746
+ // Literal style: just add exact number of line breaks between content lines.
2747
+ } else {
2748
+ // Keep all line breaks except the header line break.
2749
+ state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
2750
+ }
2751
+
2752
+ didReadContent = true;
2753
+ detectedIndent = true;
2754
+ emptyLines = 0;
2755
+ captureStart = state.position;
2756
+
2757
+ while (!is_EOL(ch) && (ch !== 0)) {
2758
+ ch = state.input.charCodeAt(++state.position);
2759
+ }
2760
+
2761
+ captureSegment(state, captureStart, state.position, false);
2762
+ }
2763
+
2764
+ return true;
2765
+ }
2766
+
2767
+ function readBlockSequence(state, nodeIndent) {
2768
+ var _line,
2769
+ _tag = state.tag,
2770
+ _anchor = state.anchor,
2771
+ _result = [],
2772
+ following,
2773
+ detected = false,
2774
+ ch;
2775
+
2776
+ // there is a leading tab before this token, so it can't be a block sequence/mapping;
2777
+ // it can still be flow sequence/mapping or a scalar
2778
+ if (state.firstTabInLine !== -1) return false;
2779
+
2780
+ if (state.anchor !== null) {
2781
+ state.anchorMap[state.anchor] = _result;
2782
+ }
2783
+
2784
+ ch = state.input.charCodeAt(state.position);
2785
+
2786
+ while (ch !== 0) {
2787
+ if (state.firstTabInLine !== -1) {
2788
+ state.position = state.firstTabInLine;
2789
+ throwError(state, 'tab characters must not be used in indentation');
2790
+ }
2791
+
2792
+ if (ch !== 0x2D/* - */) {
2793
+ break;
2794
+ }
2795
+
2796
+ following = state.input.charCodeAt(state.position + 1);
2797
+
2798
+ if (!is_WS_OR_EOL(following)) {
2799
+ break;
2800
+ }
2801
+
2802
+ detected = true;
2803
+ state.position++;
2804
+
2805
+ if (skipSeparationSpace(state, true, -1)) {
2806
+ if (state.lineIndent <= nodeIndent) {
2807
+ _result.push(null);
2808
+ ch = state.input.charCodeAt(state.position);
2809
+ continue;
2810
+ }
2811
+ }
2812
+
2813
+ _line = state.line;
2814
+ composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
2815
+ _result.push(state.result);
2816
+ skipSeparationSpace(state, true, -1);
2817
+
2818
+ ch = state.input.charCodeAt(state.position);
2819
+
2820
+ if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) {
2821
+ throwError(state, 'bad indentation of a sequence entry');
2822
+ } else if (state.lineIndent < nodeIndent) {
2823
+ break;
2824
+ }
2825
+ }
2826
+
2827
+ if (detected) {
2828
+ state.tag = _tag;
2829
+ state.anchor = _anchor;
2830
+ state.kind = 'sequence';
2831
+ state.result = _result;
2832
+ return true;
2833
+ }
2834
+ return false;
2835
+ }
2836
+
2837
+ function readBlockMapping(state, nodeIndent, flowIndent) {
2838
+ var following,
2839
+ allowCompact,
2840
+ _line,
2841
+ _keyLine,
2842
+ _keyLineStart,
2843
+ _keyPos,
2844
+ _tag = state.tag,
2845
+ _anchor = state.anchor,
2846
+ _result = {},
2847
+ overridableKeys = Object.create(null),
2848
+ keyTag = null,
2849
+ keyNode = null,
2850
+ valueNode = null,
2851
+ atExplicitKey = false,
2852
+ detected = false,
2853
+ ch;
2854
+
2855
+ // there is a leading tab before this token, so it can't be a block sequence/mapping;
2856
+ // it can still be flow sequence/mapping or a scalar
2857
+ if (state.firstTabInLine !== -1) return false;
2858
+
2859
+ if (state.anchor !== null) {
2860
+ state.anchorMap[state.anchor] = _result;
2861
+ }
2862
+
2863
+ ch = state.input.charCodeAt(state.position);
2864
+
2865
+ while (ch !== 0) {
2866
+ if (!atExplicitKey && state.firstTabInLine !== -1) {
2867
+ state.position = state.firstTabInLine;
2868
+ throwError(state, 'tab characters must not be used in indentation');
2869
+ }
2870
+
2871
+ following = state.input.charCodeAt(state.position + 1);
2872
+ _line = state.line; // Save the current line.
2873
+
2874
+ //
2875
+ // Explicit notation case. There are two separate blocks:
2876
+ // first for the key (denoted by "?") and second for the value (denoted by ":")
2877
+ //
2878
+ if ((ch === 0x3F/* ? */ || ch === 0x3A/* : */) && is_WS_OR_EOL(following)) {
2879
+
2880
+ if (ch === 0x3F/* ? */) {
2881
+ if (atExplicitKey) {
2882
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
2883
+ keyTag = keyNode = valueNode = null;
2884
+ }
2885
+
2886
+ detected = true;
2887
+ atExplicitKey = true;
2888
+ allowCompact = true;
2889
+
2890
+ } else if (atExplicitKey) {
2891
+ // i.e. 0x3A/* : */ === character after the explicit key.
2892
+ atExplicitKey = false;
2893
+ allowCompact = true;
2894
+
2895
+ } else {
2896
+ throwError(state, 'incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line');
2897
+ }
2898
+
2899
+ state.position += 1;
2900
+ ch = following;
2901
+
2902
+ //
2903
+ // Implicit notation case. Flow-style node as the key first, then ":", and the value.
2904
+ //
2905
+ } else {
2906
+ _keyLine = state.line;
2907
+ _keyLineStart = state.lineStart;
2908
+ _keyPos = state.position;
2909
+
2910
+ if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
2911
+ // Neither implicit nor explicit notation.
2912
+ // Reading is done. Go to the epilogue.
2913
+ break;
2914
+ }
2915
+
2916
+ if (state.line === _line) {
2917
+ ch = state.input.charCodeAt(state.position);
2918
+
2919
+ while (is_WHITE_SPACE(ch)) {
2920
+ ch = state.input.charCodeAt(++state.position);
2921
+ }
2922
+
2923
+ if (ch === 0x3A/* : */) {
2924
+ ch = state.input.charCodeAt(++state.position);
2925
+
2926
+ if (!is_WS_OR_EOL(ch)) {
2927
+ throwError(state, 'a whitespace character is expected after the key-value separator within a block mapping');
2928
+ }
2929
+
2930
+ if (atExplicitKey) {
2931
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
2932
+ keyTag = keyNode = valueNode = null;
2933
+ }
2934
+
2935
+ detected = true;
2936
+ atExplicitKey = false;
2937
+ allowCompact = false;
2938
+ keyTag = state.tag;
2939
+ keyNode = state.result;
2940
+
2941
+ } else if (detected) {
2942
+ throwError(state, 'can not read an implicit mapping pair; a colon is missed');
2943
+
2944
+ } else {
2945
+ state.tag = _tag;
2946
+ state.anchor = _anchor;
2947
+ return true; // Keep the result of `composeNode`.
2948
+ }
2949
+
2950
+ } else if (detected) {
2951
+ throwError(state, 'can not read a block mapping entry; a multiline key may not be an implicit key');
2952
+
2953
+ } else {
2954
+ state.tag = _tag;
2955
+ state.anchor = _anchor;
2956
+ return true; // Keep the result of `composeNode`.
2957
+ }
2958
+ }
2959
+
2960
+ //
2961
+ // Common reading code for both explicit and implicit notations.
2962
+ //
2963
+ if (state.line === _line || state.lineIndent > nodeIndent) {
2964
+ if (atExplicitKey) {
2965
+ _keyLine = state.line;
2966
+ _keyLineStart = state.lineStart;
2967
+ _keyPos = state.position;
2968
+ }
2969
+
2970
+ if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
2971
+ if (atExplicitKey) {
2972
+ keyNode = state.result;
2973
+ } else {
2974
+ valueNode = state.result;
2975
+ }
2976
+ }
2977
+
2978
+ if (!atExplicitKey) {
2979
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _keyLine, _keyLineStart, _keyPos);
2980
+ keyTag = keyNode = valueNode = null;
2981
+ }
2982
+
2983
+ skipSeparationSpace(state, true, -1);
2984
+ ch = state.input.charCodeAt(state.position);
2985
+ }
2986
+
2987
+ if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) {
2988
+ throwError(state, 'bad indentation of a mapping entry');
2989
+ } else if (state.lineIndent < nodeIndent) {
2990
+ break;
2991
+ }
2992
+ }
2993
+
2994
+ //
2995
+ // Epilogue.
2996
+ //
2997
+
2998
+ // Special case: last mapping's node contains only the key in explicit notation.
2999
+ if (atExplicitKey) {
3000
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
3001
+ }
3002
+
3003
+ // Expose the resulting mapping.
3004
+ if (detected) {
3005
+ state.tag = _tag;
3006
+ state.anchor = _anchor;
3007
+ state.kind = 'mapping';
3008
+ state.result = _result;
3009
+ }
3010
+
3011
+ return detected;
3012
+ }
3013
+
3014
+ function readTagProperty(state) {
3015
+ var _position,
3016
+ isVerbatim = false,
3017
+ isNamed = false,
3018
+ tagHandle,
3019
+ tagName,
3020
+ ch;
3021
+
3022
+ ch = state.input.charCodeAt(state.position);
3023
+
3024
+ if (ch !== 0x21/* ! */) return false;
3025
+
3026
+ if (state.tag !== null) {
3027
+ throwError(state, 'duplication of a tag property');
3028
+ }
3029
+
3030
+ ch = state.input.charCodeAt(++state.position);
3031
+
3032
+ if (ch === 0x3C/* < */) {
3033
+ isVerbatim = true;
3034
+ ch = state.input.charCodeAt(++state.position);
3035
+
3036
+ } else if (ch === 0x21/* ! */) {
3037
+ isNamed = true;
3038
+ tagHandle = '!!';
3039
+ ch = state.input.charCodeAt(++state.position);
3040
+
3041
+ } else {
3042
+ tagHandle = '!';
3043
+ }
3044
+
3045
+ _position = state.position;
3046
+
3047
+ if (isVerbatim) {
3048
+ do { ch = state.input.charCodeAt(++state.position); }
3049
+ while (ch !== 0 && ch !== 0x3E/* > */);
3050
+
3051
+ if (state.position < state.length) {
3052
+ tagName = state.input.slice(_position, state.position);
3053
+ ch = state.input.charCodeAt(++state.position);
3054
+ } else {
3055
+ throwError(state, 'unexpected end of the stream within a verbatim tag');
3056
+ }
3057
+ } else {
3058
+ while (ch !== 0 && !is_WS_OR_EOL(ch)) {
3059
+
3060
+ if (ch === 0x21/* ! */) {
3061
+ if (!isNamed) {
3062
+ tagHandle = state.input.slice(_position - 1, state.position + 1);
3063
+
3064
+ if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
3065
+ throwError(state, 'named tag handle cannot contain such characters');
3066
+ }
3067
+
3068
+ isNamed = true;
3069
+ _position = state.position + 1;
3070
+ } else {
3071
+ throwError(state, 'tag suffix cannot contain exclamation marks');
3072
+ }
3073
+ }
3074
+
3075
+ ch = state.input.charCodeAt(++state.position);
3076
+ }
3077
+
3078
+ tagName = state.input.slice(_position, state.position);
3079
+
3080
+ if (PATTERN_FLOW_INDICATORS.test(tagName)) {
3081
+ throwError(state, 'tag suffix cannot contain flow indicator characters');
3082
+ }
3083
+ }
3084
+
3085
+ if (tagName && !PATTERN_TAG_URI.test(tagName)) {
3086
+ throwError(state, 'tag name cannot contain such characters: ' + tagName);
3087
+ }
3088
+
3089
+ try {
3090
+ tagName = decodeURIComponent(tagName);
3091
+ } catch (err) {
3092
+ throwError(state, 'tag name is malformed: ' + tagName);
3093
+ }
3094
+
3095
+ if (isVerbatim) {
3096
+ state.tag = tagName;
3097
+
3098
+ } else if (_hasOwnProperty$1.call(state.tagMap, tagHandle)) {
3099
+ state.tag = state.tagMap[tagHandle] + tagName;
3100
+
3101
+ } else if (tagHandle === '!') {
3102
+ state.tag = '!' + tagName;
3103
+
3104
+ } else if (tagHandle === '!!') {
3105
+ state.tag = 'tag:yaml.org,2002:' + tagName;
3106
+
3107
+ } else {
3108
+ throwError(state, 'undeclared tag handle "' + tagHandle + '"');
3109
+ }
3110
+
3111
+ return true;
3112
+ }
3113
+
3114
+ function readAnchorProperty(state) {
3115
+ var _position,
3116
+ ch;
3117
+
3118
+ ch = state.input.charCodeAt(state.position);
3119
+
3120
+ if (ch !== 0x26/* & */) return false;
3121
+
3122
+ if (state.anchor !== null) {
3123
+ throwError(state, 'duplication of an anchor property');
3124
+ }
3125
+
3126
+ ch = state.input.charCodeAt(++state.position);
3127
+ _position = state.position;
3128
+
3129
+ while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
3130
+ ch = state.input.charCodeAt(++state.position);
3131
+ }
3132
+
3133
+ if (state.position === _position) {
3134
+ throwError(state, 'name of an anchor node must contain at least one character');
3135
+ }
3136
+
3137
+ state.anchor = state.input.slice(_position, state.position);
3138
+ return true;
3139
+ }
3140
+
3141
+ function readAlias(state) {
3142
+ var _position, alias,
3143
+ ch;
3144
+
3145
+ ch = state.input.charCodeAt(state.position);
3146
+
3147
+ if (ch !== 0x2A/* * */) return false;
3148
+
3149
+ ch = state.input.charCodeAt(++state.position);
3150
+ _position = state.position;
3151
+
3152
+ while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
3153
+ ch = state.input.charCodeAt(++state.position);
3154
+ }
3155
+
3156
+ if (state.position === _position) {
3157
+ throwError(state, 'name of an alias node must contain at least one character');
3158
+ }
3159
+
3160
+ alias = state.input.slice(_position, state.position);
3161
+
3162
+ if (!_hasOwnProperty$1.call(state.anchorMap, alias)) {
3163
+ throwError(state, 'unidentified alias "' + alias + '"');
3164
+ }
3165
+
3166
+ state.result = state.anchorMap[alias];
3167
+ skipSeparationSpace(state, true, -1);
3168
+ return true;
3169
+ }
3170
+
3171
+ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
3172
+ var allowBlockStyles,
3173
+ allowBlockScalars,
3174
+ allowBlockCollections,
3175
+ indentStatus = 1, // 1: this>parent, 0: this=parent, -1: this<parent
3176
+ atNewLine = false,
3177
+ hasContent = false,
3178
+ typeIndex,
3179
+ typeQuantity,
3180
+ typeList,
3181
+ type,
3182
+ flowIndent,
3183
+ blockIndent;
3184
+
3185
+ if (state.listener !== null) {
3186
+ state.listener('open', state);
3187
+ }
3188
+
3189
+ state.tag = null;
3190
+ state.anchor = null;
3191
+ state.kind = null;
3192
+ state.result = null;
3193
+
3194
+ allowBlockStyles = allowBlockScalars = allowBlockCollections =
3195
+ CONTEXT_BLOCK_OUT === nodeContext ||
3196
+ CONTEXT_BLOCK_IN === nodeContext;
3197
+
3198
+ if (allowToSeek) {
3199
+ if (skipSeparationSpace(state, true, -1)) {
3200
+ atNewLine = true;
3201
+
3202
+ if (state.lineIndent > parentIndent) {
3203
+ indentStatus = 1;
3204
+ } else if (state.lineIndent === parentIndent) {
3205
+ indentStatus = 0;
3206
+ } else if (state.lineIndent < parentIndent) {
3207
+ indentStatus = -1;
3208
+ }
3209
+ }
3210
+ }
3211
+
3212
+ if (indentStatus === 1) {
3213
+ while (readTagProperty(state) || readAnchorProperty(state)) {
3214
+ if (skipSeparationSpace(state, true, -1)) {
3215
+ atNewLine = true;
3216
+ allowBlockCollections = allowBlockStyles;
3217
+
3218
+ if (state.lineIndent > parentIndent) {
3219
+ indentStatus = 1;
3220
+ } else if (state.lineIndent === parentIndent) {
3221
+ indentStatus = 0;
3222
+ } else if (state.lineIndent < parentIndent) {
3223
+ indentStatus = -1;
3224
+ }
3225
+ } else {
3226
+ allowBlockCollections = false;
3227
+ }
3228
+ }
3229
+ }
3230
+
3231
+ if (allowBlockCollections) {
3232
+ allowBlockCollections = atNewLine || allowCompact;
3233
+ }
3234
+
3235
+ if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
3236
+ if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
3237
+ flowIndent = parentIndent;
3238
+ } else {
3239
+ flowIndent = parentIndent + 1;
3240
+ }
3241
+
3242
+ blockIndent = state.position - state.lineStart;
3243
+
3244
+ if (indentStatus === 1) {
3245
+ if (allowBlockCollections &&
3246
+ (readBlockSequence(state, blockIndent) ||
3247
+ readBlockMapping(state, blockIndent, flowIndent)) ||
3248
+ readFlowCollection(state, flowIndent)) {
3249
+ hasContent = true;
3250
+ } else {
3251
+ if ((allowBlockScalars && readBlockScalar(state, flowIndent)) ||
3252
+ readSingleQuotedScalar(state, flowIndent) ||
3253
+ readDoubleQuotedScalar(state, flowIndent)) {
3254
+ hasContent = true;
3255
+
3256
+ } else if (readAlias(state)) {
3257
+ hasContent = true;
3258
+
3259
+ if (state.tag !== null || state.anchor !== null) {
3260
+ throwError(state, 'alias node should not have any properties');
3261
+ }
3262
+
3263
+ } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
3264
+ hasContent = true;
3265
+
3266
+ if (state.tag === null) {
3267
+ state.tag = '?';
3268
+ }
3269
+ }
3270
+
3271
+ if (state.anchor !== null) {
3272
+ state.anchorMap[state.anchor] = state.result;
3273
+ }
3274
+ }
3275
+ } else if (indentStatus === 0) {
3276
+ // Special case: block sequences are allowed to have same indentation level as the parent.
3277
+ // http://www.yaml.org/spec/1.2/spec.html#id2799784
3278
+ hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
3279
+ }
3280
+ }
3281
+
3282
+ if (state.tag === null) {
3283
+ if (state.anchor !== null) {
3284
+ state.anchorMap[state.anchor] = state.result;
3285
+ }
3286
+
3287
+ } else if (state.tag === '?') {
3288
+ // Implicit resolving is not allowed for non-scalar types, and '?'
3289
+ // non-specific tag is only automatically assigned to plain scalars.
3290
+ //
3291
+ // We only need to check kind conformity in case user explicitly assigns '?'
3292
+ // tag, for example like this: "!<?> [0]"
3293
+ //
3294
+ if (state.result !== null && state.kind !== 'scalar') {
3295
+ throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"');
3296
+ }
3297
+
3298
+ for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) {
3299
+ type = state.implicitTypes[typeIndex];
3300
+
3301
+ if (type.resolve(state.result)) { // `state.result` updated in resolver if matched
3302
+ state.result = type.construct(state.result);
3303
+ state.tag = type.tag;
3304
+ if (state.anchor !== null) {
3305
+ state.anchorMap[state.anchor] = state.result;
3306
+ }
3307
+ break;
3308
+ }
3309
+ }
3310
+ } else if (state.tag !== '!') {
3311
+ if (_hasOwnProperty$1.call(state.typeMap[state.kind || 'fallback'], state.tag)) {
3312
+ type = state.typeMap[state.kind || 'fallback'][state.tag];
3313
+ } else {
3314
+ // looking for multi type
3315
+ type = null;
3316
+ typeList = state.typeMap.multi[state.kind || 'fallback'];
3317
+
3318
+ for (typeIndex = 0, typeQuantity = typeList.length; typeIndex < typeQuantity; typeIndex += 1) {
3319
+ if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) {
3320
+ type = typeList[typeIndex];
3321
+ break;
3322
+ }
3323
+ }
3324
+ }
3325
+
3326
+ if (!type) {
3327
+ throwError(state, 'unknown tag !<' + state.tag + '>');
3328
+ }
3329
+
3330
+ if (state.result !== null && type.kind !== state.kind) {
3331
+ throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"');
3332
+ }
3333
+
3334
+ if (!type.resolve(state.result, state.tag)) { // `state.result` updated in resolver if matched
3335
+ throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag');
3336
+ } else {
3337
+ state.result = type.construct(state.result, state.tag);
3338
+ if (state.anchor !== null) {
3339
+ state.anchorMap[state.anchor] = state.result;
3340
+ }
3341
+ }
3342
+ }
3343
+
3344
+ if (state.listener !== null) {
3345
+ state.listener('close', state);
3346
+ }
3347
+ return state.tag !== null || state.anchor !== null || hasContent;
3348
+ }
3349
+
3350
+ function readDocument(state) {
3351
+ var documentStart = state.position,
3352
+ _position,
3353
+ directiveName,
3354
+ directiveArgs,
3355
+ hasDirectives = false,
3356
+ ch;
3357
+
3358
+ state.version = null;
3359
+ state.checkLineBreaks = state.legacy;
3360
+ state.tagMap = Object.create(null);
3361
+ state.anchorMap = Object.create(null);
3362
+
3363
+ while ((ch = state.input.charCodeAt(state.position)) !== 0) {
3364
+ skipSeparationSpace(state, true, -1);
3365
+
3366
+ ch = state.input.charCodeAt(state.position);
3367
+
3368
+ if (state.lineIndent > 0 || ch !== 0x25/* % */) {
3369
+ break;
3370
+ }
3371
+
3372
+ hasDirectives = true;
3373
+ ch = state.input.charCodeAt(++state.position);
3374
+ _position = state.position;
3375
+
3376
+ while (ch !== 0 && !is_WS_OR_EOL(ch)) {
3377
+ ch = state.input.charCodeAt(++state.position);
3378
+ }
3379
+
3380
+ directiveName = state.input.slice(_position, state.position);
3381
+ directiveArgs = [];
3382
+
3383
+ if (directiveName.length < 1) {
3384
+ throwError(state, 'directive name must not be less than one character in length');
3385
+ }
3386
+
3387
+ while (ch !== 0) {
3388
+ while (is_WHITE_SPACE(ch)) {
3389
+ ch = state.input.charCodeAt(++state.position);
3390
+ }
3391
+
3392
+ if (ch === 0x23/* # */) {
3393
+ do { ch = state.input.charCodeAt(++state.position); }
3394
+ while (ch !== 0 && !is_EOL(ch));
3395
+ break;
3396
+ }
3397
+
3398
+ if (is_EOL(ch)) break;
3399
+
3400
+ _position = state.position;
3401
+
3402
+ while (ch !== 0 && !is_WS_OR_EOL(ch)) {
3403
+ ch = state.input.charCodeAt(++state.position);
3404
+ }
3405
+
3406
+ directiveArgs.push(state.input.slice(_position, state.position));
3407
+ }
3408
+
3409
+ if (ch !== 0) readLineBreak(state);
3410
+
3411
+ if (_hasOwnProperty$1.call(directiveHandlers, directiveName)) {
3412
+ directiveHandlers[directiveName](state, directiveName, directiveArgs);
3413
+ } else {
3414
+ throwWarning(state, 'unknown document directive "' + directiveName + '"');
3415
+ }
3416
+ }
3417
+
3418
+ skipSeparationSpace(state, true, -1);
3419
+
3420
+ if (state.lineIndent === 0 &&
3421
+ state.input.charCodeAt(state.position) === 0x2D/* - */ &&
3422
+ state.input.charCodeAt(state.position + 1) === 0x2D/* - */ &&
3423
+ state.input.charCodeAt(state.position + 2) === 0x2D/* - */) {
3424
+ state.position += 3;
3425
+ skipSeparationSpace(state, true, -1);
3426
+
3427
+ } else if (hasDirectives) {
3428
+ throwError(state, 'directives end mark is expected');
3429
+ }
3430
+
3431
+ composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
3432
+ skipSeparationSpace(state, true, -1);
3433
+
3434
+ if (state.checkLineBreaks &&
3435
+ PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
3436
+ throwWarning(state, 'non-ASCII line breaks are interpreted as content');
3437
+ }
3438
+
3439
+ state.documents.push(state.result);
3440
+
3441
+ if (state.position === state.lineStart && testDocumentSeparator(state)) {
3442
+
3443
+ if (state.input.charCodeAt(state.position) === 0x2E/* . */) {
3444
+ state.position += 3;
3445
+ skipSeparationSpace(state, true, -1);
3446
+ }
3447
+ return;
3448
+ }
3449
+
3450
+ if (state.position < (state.length - 1)) {
3451
+ throwError(state, 'end of the stream or a document separator is expected');
3452
+ } else {
3453
+ return;
3454
+ }
3455
+ }
3456
+
3457
+
3458
+ function loadDocuments(input, options) {
3459
+ input = String(input);
3460
+ options = options || {};
3461
+
3462
+ if (input.length !== 0) {
3463
+
3464
+ // Add tailing `\n` if not exists
3465
+ if (input.charCodeAt(input.length - 1) !== 0x0A/* LF */ &&
3466
+ input.charCodeAt(input.length - 1) !== 0x0D/* CR */) {
3467
+ input += '\n';
3468
+ }
3469
+
3470
+ // Strip BOM
3471
+ if (input.charCodeAt(0) === 0xFEFF) {
3472
+ input = input.slice(1);
3473
+ }
3474
+ }
3475
+
3476
+ var state = new State$1(input, options);
3477
+
3478
+ var nullpos = input.indexOf('\0');
3479
+
3480
+ if (nullpos !== -1) {
3481
+ state.position = nullpos;
3482
+ throwError(state, 'null byte is not allowed in input');
3483
+ }
3484
+
3485
+ // Use 0 as string terminator. That significantly simplifies bounds check.
3486
+ state.input += '\0';
3487
+
3488
+ while (state.input.charCodeAt(state.position) === 0x20/* Space */) {
3489
+ state.lineIndent += 1;
3490
+ state.position += 1;
3491
+ }
3492
+
3493
+ while (state.position < (state.length - 1)) {
3494
+ readDocument(state);
3495
+ }
3496
+
3497
+ return state.documents;
3498
+ }
3499
+
3500
+
3501
+ function loadAll$1(input, iterator, options) {
3502
+ if (iterator !== null && typeof iterator === 'object' && typeof options === 'undefined') {
3503
+ options = iterator;
3504
+ iterator = null;
3505
+ }
3506
+
3507
+ var documents = loadDocuments(input, options);
3508
+
3509
+ if (typeof iterator !== 'function') {
3510
+ return documents;
3511
+ }
3512
+
3513
+ for (var index = 0, length = documents.length; index < length; index += 1) {
3514
+ iterator(documents[index]);
3515
+ }
3516
+ }
3517
+
3518
+
3519
+ function load$1(input, options) {
3520
+ var documents = loadDocuments(input, options);
3521
+
3522
+ if (documents.length === 0) {
3523
+ /*eslint-disable no-undefined*/
3524
+ return undefined;
3525
+ } else if (documents.length === 1) {
3526
+ return documents[0];
3527
+ }
3528
+ throw new exception('expected a single document in the stream, but found more');
3529
+ }
3530
+
3531
+
3532
+ var loadAll_1 = loadAll$1;
3533
+ var load_1 = load$1;
3534
+
3535
+ var loader = {
3536
+ loadAll: loadAll_1,
3537
+ load: load_1
3538
+ };
3539
+
3540
+ /*eslint-disable no-use-before-define*/
3541
+
3542
+
3543
+
3544
+
3545
+
3546
+ var _toString = Object.prototype.toString;
3547
+ var _hasOwnProperty = Object.prototype.hasOwnProperty;
3548
+
3549
+ var CHAR_BOM = 0xFEFF;
3550
+ var CHAR_TAB = 0x09; /* Tab */
3551
+ var CHAR_LINE_FEED = 0x0A; /* LF */
3552
+ var CHAR_CARRIAGE_RETURN = 0x0D; /* CR */
3553
+ var CHAR_SPACE = 0x20; /* Space */
3554
+ var CHAR_EXCLAMATION = 0x21; /* ! */
3555
+ var CHAR_DOUBLE_QUOTE = 0x22; /* " */
3556
+ var CHAR_SHARP = 0x23; /* # */
3557
+ var CHAR_PERCENT = 0x25; /* % */
3558
+ var CHAR_AMPERSAND = 0x26; /* & */
3559
+ var CHAR_SINGLE_QUOTE = 0x27; /* ' */
3560
+ var CHAR_ASTERISK = 0x2A; /* * */
3561
+ var CHAR_COMMA = 0x2C; /* , */
3562
+ var CHAR_MINUS = 0x2D; /* - */
3563
+ var CHAR_COLON = 0x3A; /* : */
3564
+ var CHAR_EQUALS = 0x3D; /* = */
3565
+ var CHAR_GREATER_THAN = 0x3E; /* > */
3566
+ var CHAR_QUESTION = 0x3F; /* ? */
3567
+ var CHAR_COMMERCIAL_AT = 0x40; /* @ */
3568
+ var CHAR_LEFT_SQUARE_BRACKET = 0x5B; /* [ */
3569
+ var CHAR_RIGHT_SQUARE_BRACKET = 0x5D; /* ] */
3570
+ var CHAR_GRAVE_ACCENT = 0x60; /* ` */
3571
+ var CHAR_LEFT_CURLY_BRACKET = 0x7B; /* { */
3572
+ var CHAR_VERTICAL_LINE = 0x7C; /* | */
3573
+ var CHAR_RIGHT_CURLY_BRACKET = 0x7D; /* } */
3574
+
3575
+ var ESCAPE_SEQUENCES = {};
3576
+
3577
+ ESCAPE_SEQUENCES[0x00] = '\\0';
3578
+ ESCAPE_SEQUENCES[0x07] = '\\a';
3579
+ ESCAPE_SEQUENCES[0x08] = '\\b';
3580
+ ESCAPE_SEQUENCES[0x09] = '\\t';
3581
+ ESCAPE_SEQUENCES[0x0A] = '\\n';
3582
+ ESCAPE_SEQUENCES[0x0B] = '\\v';
3583
+ ESCAPE_SEQUENCES[0x0C] = '\\f';
3584
+ ESCAPE_SEQUENCES[0x0D] = '\\r';
3585
+ ESCAPE_SEQUENCES[0x1B] = '\\e';
3586
+ ESCAPE_SEQUENCES[0x22] = '\\"';
3587
+ ESCAPE_SEQUENCES[0x5C] = '\\\\';
3588
+ ESCAPE_SEQUENCES[0x85] = '\\N';
3589
+ ESCAPE_SEQUENCES[0xA0] = '\\_';
3590
+ ESCAPE_SEQUENCES[0x2028] = '\\L';
3591
+ ESCAPE_SEQUENCES[0x2029] = '\\P';
3592
+
3593
+ var DEPRECATED_BOOLEANS_SYNTAX = [
3594
+ 'y', 'Y', 'yes', 'Yes', 'YES', 'on', 'On', 'ON',
3595
+ 'n', 'N', 'no', 'No', 'NO', 'off', 'Off', 'OFF'
3596
+ ];
3597
+
3598
+ var DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;
3599
+
3600
+ function compileStyleMap(schema, map) {
3601
+ var result, keys, index, length, tag, style, type;
3602
+
3603
+ if (map === null) return {};
3604
+
3605
+ result = {};
3606
+ keys = Object.keys(map);
3607
+
3608
+ for (index = 0, length = keys.length; index < length; index += 1) {
3609
+ tag = keys[index];
3610
+ style = String(map[tag]);
3611
+
3612
+ if (tag.slice(0, 2) === '!!') {
3613
+ tag = 'tag:yaml.org,2002:' + tag.slice(2);
3614
+ }
3615
+ type = schema.compiledTypeMap['fallback'][tag];
3616
+
3617
+ if (type && _hasOwnProperty.call(type.styleAliases, style)) {
3618
+ style = type.styleAliases[style];
3619
+ }
3620
+
3621
+ result[tag] = style;
3622
+ }
3623
+
3624
+ return result;
3625
+ }
3626
+
3627
+ function encodeHex(character) {
3628
+ var string, handle, length;
3629
+
3630
+ string = character.toString(16).toUpperCase();
3631
+
3632
+ if (character <= 0xFF) {
3633
+ handle = 'x';
3634
+ length = 2;
3635
+ } else if (character <= 0xFFFF) {
3636
+ handle = 'u';
3637
+ length = 4;
3638
+ } else if (character <= 0xFFFFFFFF) {
3639
+ handle = 'U';
3640
+ length = 8;
3641
+ } else {
3642
+ throw new exception('code point within a string may not be greater than 0xFFFFFFFF');
3643
+ }
3644
+
3645
+ return '\\' + handle + common.repeat('0', length - string.length) + string;
3646
+ }
3647
+
3648
+
3649
+ var QUOTING_TYPE_SINGLE = 1,
3650
+ QUOTING_TYPE_DOUBLE = 2;
3651
+
3652
+ function State(options) {
3653
+ this.schema = options['schema'] || _default;
3654
+ this.indent = Math.max(1, (options['indent'] || 2));
3655
+ this.noArrayIndent = options['noArrayIndent'] || false;
3656
+ this.skipInvalid = options['skipInvalid'] || false;
3657
+ this.flowLevel = (common.isNothing(options['flowLevel']) ? -1 : options['flowLevel']);
3658
+ this.styleMap = compileStyleMap(this.schema, options['styles'] || null);
3659
+ this.sortKeys = options['sortKeys'] || false;
3660
+ this.lineWidth = options['lineWidth'] || 80;
3661
+ this.noRefs = options['noRefs'] || false;
3662
+ this.noCompatMode = options['noCompatMode'] || false;
3663
+ this.condenseFlow = options['condenseFlow'] || false;
3664
+ this.quotingType = options['quotingType'] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE;
3665
+ this.forceQuotes = options['forceQuotes'] || false;
3666
+ this.replacer = typeof options['replacer'] === 'function' ? options['replacer'] : null;
3667
+
3668
+ this.implicitTypes = this.schema.compiledImplicit;
3669
+ this.explicitTypes = this.schema.compiledExplicit;
3670
+
3671
+ this.tag = null;
3672
+ this.result = '';
3673
+
3674
+ this.duplicates = [];
3675
+ this.usedDuplicates = null;
3676
+ }
3677
+
3678
+ // Indents every line in a string. Empty lines (\n only) are not indented.
3679
+ function indentString(string, spaces) {
3680
+ var ind = common.repeat(' ', spaces),
3681
+ position = 0,
3682
+ next = -1,
3683
+ result = '',
3684
+ line,
3685
+ length = string.length;
3686
+
3687
+ while (position < length) {
3688
+ next = string.indexOf('\n', position);
3689
+ if (next === -1) {
3690
+ line = string.slice(position);
3691
+ position = length;
3692
+ } else {
3693
+ line = string.slice(position, next + 1);
3694
+ position = next + 1;
3695
+ }
3696
+
3697
+ if (line.length && line !== '\n') result += ind;
3698
+
3699
+ result += line;
3700
+ }
3701
+
3702
+ return result;
3703
+ }
3704
+
3705
+ function generateNextLine(state, level) {
3706
+ return '\n' + common.repeat(' ', state.indent * level);
3707
+ }
3708
+
3709
+ function testImplicitResolving(state, str) {
3710
+ var index, length, type;
3711
+
3712
+ for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
3713
+ type = state.implicitTypes[index];
3714
+
3715
+ if (type.resolve(str)) {
3716
+ return true;
3717
+ }
3718
+ }
3719
+
3720
+ return false;
3721
+ }
3722
+
3723
+ // [33] s-white ::= s-space | s-tab
3724
+ function isWhitespace(c) {
3725
+ return c === CHAR_SPACE || c === CHAR_TAB;
3726
+ }
3727
+
3728
+ // Returns true if the character can be printed without escaping.
3729
+ // From YAML 1.2: "any allowed characters known to be non-printable
3730
+ // should also be escaped. [However,] This isn’t mandatory"
3731
+ // Derived from nb-char - \t - #x85 - #xA0 - #x2028 - #x2029.
3732
+ function isPrintable(c) {
3733
+ return (0x00020 <= c && c <= 0x00007E)
3734
+ || ((0x000A1 <= c && c <= 0x00D7FF) && c !== 0x2028 && c !== 0x2029)
3735
+ || ((0x0E000 <= c && c <= 0x00FFFD) && c !== CHAR_BOM)
3736
+ || (0x10000 <= c && c <= 0x10FFFF);
3737
+ }
3738
+
3739
+ // [34] ns-char ::= nb-char - s-white
3740
+ // [27] nb-char ::= c-printable - b-char - c-byte-order-mark
3741
+ // [26] b-char ::= b-line-feed | b-carriage-return
3742
+ // Including s-white (for some reason, examples doesn't match specs in this aspect)
3743
+ // ns-char ::= c-printable - b-line-feed - b-carriage-return - c-byte-order-mark
3744
+ function isNsCharOrWhitespace(c) {
3745
+ return isPrintable(c)
3746
+ && c !== CHAR_BOM
3747
+ // - b-char
3748
+ && c !== CHAR_CARRIAGE_RETURN
3749
+ && c !== CHAR_LINE_FEED;
3750
+ }
3751
+
3752
+ // [127] ns-plain-safe(c) ::= c = flow-out ⇒ ns-plain-safe-out
3753
+ // c = flow-in ⇒ ns-plain-safe-in
3754
+ // c = block-key ⇒ ns-plain-safe-out
3755
+ // c = flow-key ⇒ ns-plain-safe-in
3756
+ // [128] ns-plain-safe-out ::= ns-char
3757
+ // [129] ns-plain-safe-in ::= ns-char - c-flow-indicator
3758
+ // [130] ns-plain-char(c) ::= ( ns-plain-safe(c) - “:” - “#” )
3759
+ // | ( /* An ns-char preceding */ “#” )
3760
+ // | ( “:” /* Followed by an ns-plain-safe(c) */ )
3761
+ function isPlainSafe(c, prev, inblock) {
3762
+ var cIsNsCharOrWhitespace = isNsCharOrWhitespace(c);
3763
+ var cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c);
3764
+ return (
3765
+ // ns-plain-safe
3766
+ inblock ? // c = flow-in
3767
+ cIsNsCharOrWhitespace
3768
+ : cIsNsCharOrWhitespace
3769
+ // - c-flow-indicator
3770
+ && c !== CHAR_COMMA
3771
+ && c !== CHAR_LEFT_SQUARE_BRACKET
3772
+ && c !== CHAR_RIGHT_SQUARE_BRACKET
3773
+ && c !== CHAR_LEFT_CURLY_BRACKET
3774
+ && c !== CHAR_RIGHT_CURLY_BRACKET
3775
+ )
3776
+ // ns-plain-char
3777
+ && c !== CHAR_SHARP // false on '#'
3778
+ && !(prev === CHAR_COLON && !cIsNsChar) // false on ': '
3779
+ || (isNsCharOrWhitespace(prev) && !isWhitespace(prev) && c === CHAR_SHARP) // change to true on '[^ ]#'
3780
+ || (prev === CHAR_COLON && cIsNsChar); // change to true on ':[^ ]'
3781
+ }
3782
+
3783
+ // Simplified test for values allowed as the first character in plain style.
3784
+ function isPlainSafeFirst(c) {
3785
+ // Uses a subset of ns-char - c-indicator
3786
+ // where ns-char = nb-char - s-white.
3787
+ // No support of ( ( “?” | “:” | “-” ) /* Followed by an ns-plain-safe(c)) */ ) part
3788
+ return isPrintable(c) && c !== CHAR_BOM
3789
+ && !isWhitespace(c) // - s-white
3790
+ // - (c-indicator ::=
3791
+ // “-” | “?” | “:” | “,” | “[” | “]” | “{” | “}”
3792
+ && c !== CHAR_MINUS
3793
+ && c !== CHAR_QUESTION
3794
+ && c !== CHAR_COLON
3795
+ && c !== CHAR_COMMA
3796
+ && c !== CHAR_LEFT_SQUARE_BRACKET
3797
+ && c !== CHAR_RIGHT_SQUARE_BRACKET
3798
+ && c !== CHAR_LEFT_CURLY_BRACKET
3799
+ && c !== CHAR_RIGHT_CURLY_BRACKET
3800
+ // | “#” | “&” | “*” | “!” | “|” | “=” | “>” | “'” | “"”
3801
+ && c !== CHAR_SHARP
3802
+ && c !== CHAR_AMPERSAND
3803
+ && c !== CHAR_ASTERISK
3804
+ && c !== CHAR_EXCLAMATION
3805
+ && c !== CHAR_VERTICAL_LINE
3806
+ && c !== CHAR_EQUALS
3807
+ && c !== CHAR_GREATER_THAN
3808
+ && c !== CHAR_SINGLE_QUOTE
3809
+ && c !== CHAR_DOUBLE_QUOTE
3810
+ // | “%” | “@” | “`”)
3811
+ && c !== CHAR_PERCENT
3812
+ && c !== CHAR_COMMERCIAL_AT
3813
+ && c !== CHAR_GRAVE_ACCENT;
3814
+ }
3815
+
3816
+ // Simplified test for values allowed as the last character in plain style.
3817
+ function isPlainSafeLast(c) {
3818
+ // just not whitespace or colon, it will be checked to be plain character later
3819
+ return !isWhitespace(c) && c !== CHAR_COLON;
3820
+ }
3821
+
3822
+ // Same as 'string'.codePointAt(pos), but works in older browsers.
3823
+ function codePointAt(string, pos) {
3824
+ var first = string.charCodeAt(pos), second;
3825
+ if (first >= 0xD800 && first <= 0xDBFF && pos + 1 < string.length) {
3826
+ second = string.charCodeAt(pos + 1);
3827
+ if (second >= 0xDC00 && second <= 0xDFFF) {
3828
+ // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
3829
+ return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
3830
+ }
3831
+ }
3832
+ return first;
3833
+ }
3834
+
3835
+ // Determines whether block indentation indicator is required.
3836
+ function needIndentIndicator(string) {
3837
+ var leadingSpaceRe = /^\n* /;
3838
+ return leadingSpaceRe.test(string);
3839
+ }
3840
+
3841
+ var STYLE_PLAIN = 1,
3842
+ STYLE_SINGLE = 2,
3843
+ STYLE_LITERAL = 3,
3844
+ STYLE_FOLDED = 4,
3845
+ STYLE_DOUBLE = 5;
3846
+
3847
+ // Determines which scalar styles are possible and returns the preferred style.
3848
+ // lineWidth = -1 => no limit.
3849
+ // Pre-conditions: str.length > 0.
3850
+ // Post-conditions:
3851
+ // STYLE_PLAIN or STYLE_SINGLE => no \n are in the string.
3852
+ // STYLE_LITERAL => no lines are suitable for folding (or lineWidth is -1).
3853
+ // STYLE_FOLDED => a line > lineWidth and can be folded (and lineWidth != -1).
3854
+ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth,
3855
+ testAmbiguousType, quotingType, forceQuotes, inblock) {
3856
+
3857
+ var i;
3858
+ var char = 0;
3859
+ var prevChar = null;
3860
+ var hasLineBreak = false;
3861
+ var hasFoldableLine = false; // only checked if shouldTrackWidth
3862
+ var shouldTrackWidth = lineWidth !== -1;
3863
+ var previousLineBreak = -1; // count the first line correctly
3864
+ var plain = isPlainSafeFirst(codePointAt(string, 0))
3865
+ && isPlainSafeLast(codePointAt(string, string.length - 1));
3866
+
3867
+ if (singleLineOnly || forceQuotes) {
3868
+ // Case: no block styles.
3869
+ // Check for disallowed characters to rule out plain and single.
3870
+ for (i = 0; i < string.length; char >= 0x10000 ? i += 2 : i++) {
3871
+ char = codePointAt(string, i);
3872
+ if (!isPrintable(char)) {
3873
+ return STYLE_DOUBLE;
3874
+ }
3875
+ plain = plain && isPlainSafe(char, prevChar, inblock);
3876
+ prevChar = char;
3877
+ }
3878
+ } else {
3879
+ // Case: block styles permitted.
3880
+ for (i = 0; i < string.length; char >= 0x10000 ? i += 2 : i++) {
3881
+ char = codePointAt(string, i);
3882
+ if (char === CHAR_LINE_FEED) {
3883
+ hasLineBreak = true;
3884
+ // Check if any line can be folded.
3885
+ if (shouldTrackWidth) {
3886
+ hasFoldableLine = hasFoldableLine ||
3887
+ // Foldable line = too long, and not more-indented.
3888
+ (i - previousLineBreak - 1 > lineWidth &&
3889
+ string[previousLineBreak + 1] !== ' ');
3890
+ previousLineBreak = i;
3891
+ }
3892
+ } else if (!isPrintable(char)) {
3893
+ return STYLE_DOUBLE;
3894
+ }
3895
+ plain = plain && isPlainSafe(char, prevChar, inblock);
3896
+ prevChar = char;
3897
+ }
3898
+ // in case the end is missing a \n
3899
+ hasFoldableLine = hasFoldableLine || (shouldTrackWidth &&
3900
+ (i - previousLineBreak - 1 > lineWidth &&
3901
+ string[previousLineBreak + 1] !== ' '));
3902
+ }
3903
+ // Although every style can represent \n without escaping, prefer block styles
3904
+ // for multiline, since they're more readable and they don't add empty lines.
3905
+ // Also prefer folding a super-long line.
3906
+ if (!hasLineBreak && !hasFoldableLine) {
3907
+ // Strings interpretable as another type have to be quoted;
3908
+ // e.g. the string 'true' vs. the boolean true.
3909
+ if (plain && !forceQuotes && !testAmbiguousType(string)) {
3910
+ return STYLE_PLAIN;
3911
+ }
3912
+ return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
3913
+ }
3914
+ // Edge case: block indentation indicator can only have one digit.
3915
+ if (indentPerLevel > 9 && needIndentIndicator(string)) {
3916
+ return STYLE_DOUBLE;
3917
+ }
3918
+ // At this point we know block styles are valid.
3919
+ // Prefer literal style unless we want to fold.
3920
+ if (!forceQuotes) {
3921
+ return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
3922
+ }
3923
+ return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
3924
+ }
3925
+
3926
+ // Note: line breaking/folding is implemented for only the folded style.
3927
+ // NB. We drop the last trailing newline (if any) of a returned block scalar
3928
+ // since the dumper adds its own newline. This always works:
3929
+ // • No ending newline => unaffected; already using strip "-" chomping.
3930
+ // • Ending newline => removed then restored.
3931
+ // Importantly, this keeps the "+" chomp indicator from gaining an extra line.
3932
+ function writeScalar(state, string, level, iskey, inblock) {
3933
+ state.dump = (function () {
3934
+ if (string.length === 0) {
3935
+ return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''";
3936
+ }
3937
+ if (!state.noCompatMode) {
3938
+ if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string)) {
3939
+ return state.quotingType === QUOTING_TYPE_DOUBLE ? ('"' + string + '"') : ("'" + string + "'");
3940
+ }
3941
+ }
3942
+
3943
+ var indent = state.indent * Math.max(1, level); // no 0-indent scalars
3944
+ // As indentation gets deeper, let the width decrease monotonically
3945
+ // to the lower bound min(state.lineWidth, 40).
3946
+ // Note that this implies
3947
+ // state.lineWidth ≤ 40 + state.indent: width is fixed at the lower bound.
3948
+ // state.lineWidth > 40 + state.indent: width decreases until the lower bound.
3949
+ // This behaves better than a constant minimum width which disallows narrower options,
3950
+ // or an indent threshold which causes the width to suddenly increase.
3951
+ var lineWidth = state.lineWidth === -1
3952
+ ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
3953
+
3954
+ // Without knowing if keys are implicit/explicit, assume implicit for safety.
3955
+ var singleLineOnly = iskey
3956
+ // No block styles in flow mode.
3957
+ || (state.flowLevel > -1 && level >= state.flowLevel);
3958
+ function testAmbiguity(string) {
3959
+ return testImplicitResolving(state, string);
3960
+ }
3961
+
3962
+ switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth,
3963
+ testAmbiguity, state.quotingType, state.forceQuotes && !iskey, inblock)) {
3964
+
3965
+ case STYLE_PLAIN:
3966
+ return string;
3967
+ case STYLE_SINGLE:
3968
+ return "'" + string.replace(/'/g, "''") + "'";
3969
+ case STYLE_LITERAL:
3970
+ return '|' + blockHeader(string, state.indent)
3971
+ + dropEndingNewline(indentString(string, indent));
3972
+ case STYLE_FOLDED:
3973
+ return '>' + blockHeader(string, state.indent)
3974
+ + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
3975
+ case STYLE_DOUBLE:
3976
+ return '"' + escapeString(string) + '"';
3977
+ default:
3978
+ throw new exception('impossible error: invalid scalar style');
3979
+ }
3980
+ }());
3981
+ }
3982
+
3983
+ // Pre-conditions: string is valid for a block scalar, 1 <= indentPerLevel <= 9.
3984
+ function blockHeader(string, indentPerLevel) {
3985
+ var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : '';
3986
+
3987
+ // note the special case: the string '\n' counts as a "trailing" empty line.
3988
+ var clip = string[string.length - 1] === '\n';
3989
+ var keep = clip && (string[string.length - 2] === '\n' || string === '\n');
3990
+ var chomp = keep ? '+' : (clip ? '' : '-');
3991
+
3992
+ return indentIndicator + chomp + '\n';
3993
+ }
3994
+
3995
+ // (See the note for writeScalar.)
3996
+ function dropEndingNewline(string) {
3997
+ return string[string.length - 1] === '\n' ? string.slice(0, -1) : string;
3998
+ }
3999
+
4000
+ // Note: a long line without a suitable break point will exceed the width limit.
4001
+ // Pre-conditions: every char in str isPrintable, str.length > 0, width > 0.
4002
+ function foldString(string, width) {
4003
+ // In folded style, $k$ consecutive newlines output as $k+1$ newlines—
4004
+ // unless they're before or after a more-indented line, or at the very
4005
+ // beginning or end, in which case $k$ maps to $k$.
4006
+ // Therefore, parse each chunk as newline(s) followed by a content line.
4007
+ var lineRe = /(\n+)([^\n]*)/g;
4008
+
4009
+ // first line (possibly an empty line)
4010
+ var result = (function () {
4011
+ var nextLF = string.indexOf('\n');
4012
+ nextLF = nextLF !== -1 ? nextLF : string.length;
4013
+ lineRe.lastIndex = nextLF;
4014
+ return foldLine(string.slice(0, nextLF), width);
4015
+ }());
4016
+ // If we haven't reached the first content line yet, don't add an extra \n.
4017
+ var prevMoreIndented = string[0] === '\n' || string[0] === ' ';
4018
+ var moreIndented;
4019
+
4020
+ // rest of the lines
4021
+ var match;
4022
+ while ((match = lineRe.exec(string))) {
4023
+ var prefix = match[1], line = match[2];
4024
+ moreIndented = (line[0] === ' ');
4025
+ result += prefix
4026
+ + (!prevMoreIndented && !moreIndented && line !== ''
4027
+ ? '\n' : '')
4028
+ + foldLine(line, width);
4029
+ prevMoreIndented = moreIndented;
4030
+ }
4031
+
4032
+ return result;
4033
+ }
4034
+
4035
+ // Greedy line breaking.
4036
+ // Picks the longest line under the limit each time,
4037
+ // otherwise settles for the shortest line over the limit.
4038
+ // NB. More-indented lines *cannot* be folded, as that would add an extra \n.
4039
+ function foldLine(line, width) {
4040
+ if (line === '' || line[0] === ' ') return line;
4041
+
4042
+ // Since a more-indented line adds a \n, breaks can't be followed by a space.
4043
+ var breakRe = / [^ ]/g; // note: the match index will always be <= length-2.
4044
+ var match;
4045
+ // start is an inclusive index. end, curr, and next are exclusive.
4046
+ var start = 0, end, curr = 0, next = 0;
4047
+ var result = '';
4048
+
4049
+ // Invariants: 0 <= start <= length-1.
4050
+ // 0 <= curr <= next <= max(0, length-2). curr - start <= width.
4051
+ // Inside the loop:
4052
+ // A match implies length >= 2, so curr and next are <= length-2.
4053
+ while ((match = breakRe.exec(line))) {
4054
+ next = match.index;
4055
+ // maintain invariant: curr - start <= width
4056
+ if (next - start > width) {
4057
+ end = (curr > start) ? curr : next; // derive end <= length-2
4058
+ result += '\n' + line.slice(start, end);
4059
+ // skip the space that was output as \n
4060
+ start = end + 1; // derive start <= length-1
4061
+ }
4062
+ curr = next;
4063
+ }
4064
+
4065
+ // By the invariants, start <= length-1, so there is something left over.
4066
+ // It is either the whole string or a part starting from non-whitespace.
4067
+ result += '\n';
4068
+ // Insert a break if the remainder is too long and there is a break available.
4069
+ if (line.length - start > width && curr > start) {
4070
+ result += line.slice(start, curr) + '\n' + line.slice(curr + 1);
4071
+ } else {
4072
+ result += line.slice(start);
4073
+ }
4074
+
4075
+ return result.slice(1); // drop extra \n joiner
4076
+ }
4077
+
4078
+ // Escapes a double-quoted string.
4079
+ function escapeString(string) {
4080
+ var result = '';
4081
+ var char = 0;
4082
+ var escapeSeq;
4083
+
4084
+ for (var i = 0; i < string.length; char >= 0x10000 ? i += 2 : i++) {
4085
+ char = codePointAt(string, i);
4086
+ escapeSeq = ESCAPE_SEQUENCES[char];
4087
+
4088
+ if (!escapeSeq && isPrintable(char)) {
4089
+ result += string[i];
4090
+ if (char >= 0x10000) result += string[i + 1];
4091
+ } else {
4092
+ result += escapeSeq || encodeHex(char);
4093
+ }
4094
+ }
4095
+
4096
+ return result;
4097
+ }
4098
+
4099
+ function writeFlowSequence(state, level, object) {
4100
+ var _result = '',
4101
+ _tag = state.tag,
4102
+ index,
4103
+ length,
4104
+ value;
4105
+
4106
+ for (index = 0, length = object.length; index < length; index += 1) {
4107
+ value = object[index];
4108
+
4109
+ if (state.replacer) {
4110
+ value = state.replacer.call(object, String(index), value);
4111
+ }
4112
+
4113
+ // Write only valid elements, put null instead of invalid elements.
4114
+ if (writeNode(state, level, value, false, false) ||
4115
+ (typeof value === 'undefined' &&
4116
+ writeNode(state, level, null, false, false))) {
4117
+
4118
+ if (_result !== '') _result += ',' + (!state.condenseFlow ? ' ' : '');
4119
+ _result += state.dump;
4120
+ }
4121
+ }
4122
+
4123
+ state.tag = _tag;
4124
+ state.dump = '[' + _result + ']';
4125
+ }
4126
+
4127
+ function writeBlockSequence(state, level, object, compact) {
4128
+ var _result = '',
4129
+ _tag = state.tag,
4130
+ index,
4131
+ length,
4132
+ value;
4133
+
4134
+ for (index = 0, length = object.length; index < length; index += 1) {
4135
+ value = object[index];
4136
+
4137
+ if (state.replacer) {
4138
+ value = state.replacer.call(object, String(index), value);
4139
+ }
4140
+
4141
+ // Write only valid elements, put null instead of invalid elements.
4142
+ if (writeNode(state, level + 1, value, true, true, false, true) ||
4143
+ (typeof value === 'undefined' &&
4144
+ writeNode(state, level + 1, null, true, true, false, true))) {
4145
+
4146
+ if (!compact || _result !== '') {
4147
+ _result += generateNextLine(state, level);
4148
+ }
4149
+
4150
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
4151
+ _result += '-';
4152
+ } else {
4153
+ _result += '- ';
4154
+ }
4155
+
4156
+ _result += state.dump;
4157
+ }
4158
+ }
4159
+
4160
+ state.tag = _tag;
4161
+ state.dump = _result || '[]'; // Empty sequence if no valid values.
4162
+ }
4163
+
4164
+ function writeFlowMapping(state, level, object) {
4165
+ var _result = '',
4166
+ _tag = state.tag,
4167
+ objectKeyList = Object.keys(object),
4168
+ index,
4169
+ length,
4170
+ objectKey,
4171
+ objectValue,
4172
+ pairBuffer;
4173
+
4174
+ for (index = 0, length = objectKeyList.length; index < length; index += 1) {
4175
+
4176
+ pairBuffer = '';
4177
+ if (_result !== '') pairBuffer += ', ';
4178
+
4179
+ if (state.condenseFlow) pairBuffer += '"';
4180
+
4181
+ objectKey = objectKeyList[index];
4182
+ objectValue = object[objectKey];
4183
+
4184
+ if (state.replacer) {
4185
+ objectValue = state.replacer.call(object, objectKey, objectValue);
4186
+ }
4187
+
4188
+ if (!writeNode(state, level, objectKey, false, false)) {
4189
+ continue; // Skip this pair because of invalid key;
4190
+ }
4191
+
4192
+ if (state.dump.length > 1024) pairBuffer += '? ';
4193
+
4194
+ pairBuffer += state.dump + (state.condenseFlow ? '"' : '') + ':' + (state.condenseFlow ? '' : ' ');
4195
+
4196
+ if (!writeNode(state, level, objectValue, false, false)) {
4197
+ continue; // Skip this pair because of invalid value.
4198
+ }
4199
+
4200
+ pairBuffer += state.dump;
4201
+
4202
+ // Both key and value are valid.
4203
+ _result += pairBuffer;
4204
+ }
4205
+
4206
+ state.tag = _tag;
4207
+ state.dump = '{' + _result + '}';
4208
+ }
4209
+
4210
+ function writeBlockMapping(state, level, object, compact) {
4211
+ var _result = '',
4212
+ _tag = state.tag,
4213
+ objectKeyList = Object.keys(object),
4214
+ index,
4215
+ length,
4216
+ objectKey,
4217
+ objectValue,
4218
+ explicitPair,
4219
+ pairBuffer;
4220
+
4221
+ // Allow sorting keys so that the output file is deterministic
4222
+ if (state.sortKeys === true) {
4223
+ // Default sorting
4224
+ objectKeyList.sort();
4225
+ } else if (typeof state.sortKeys === 'function') {
4226
+ // Custom sort function
4227
+ objectKeyList.sort(state.sortKeys);
4228
+ } else if (state.sortKeys) {
4229
+ // Something is wrong
4230
+ throw new exception('sortKeys must be a boolean or a function');
4231
+ }
4232
+
4233
+ for (index = 0, length = objectKeyList.length; index < length; index += 1) {
4234
+ pairBuffer = '';
4235
+
4236
+ if (!compact || _result !== '') {
4237
+ pairBuffer += generateNextLine(state, level);
4238
+ }
4239
+
4240
+ objectKey = objectKeyList[index];
4241
+ objectValue = object[objectKey];
4242
+
4243
+ if (state.replacer) {
4244
+ objectValue = state.replacer.call(object, objectKey, objectValue);
4245
+ }
4246
+
4247
+ if (!writeNode(state, level + 1, objectKey, true, true, true)) {
4248
+ continue; // Skip this pair because of invalid key.
4249
+ }
4250
+
4251
+ explicitPair = (state.tag !== null && state.tag !== '?') ||
4252
+ (state.dump && state.dump.length > 1024);
4253
+
4254
+ if (explicitPair) {
4255
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
4256
+ pairBuffer += '?';
4257
+ } else {
4258
+ pairBuffer += '? ';
4259
+ }
4260
+ }
4261
+
4262
+ pairBuffer += state.dump;
4263
+
4264
+ if (explicitPair) {
4265
+ pairBuffer += generateNextLine(state, level);
4266
+ }
4267
+
4268
+ if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
4269
+ continue; // Skip this pair because of invalid value.
4270
+ }
4271
+
4272
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
4273
+ pairBuffer += ':';
4274
+ } else {
4275
+ pairBuffer += ': ';
4276
+ }
4277
+
4278
+ pairBuffer += state.dump;
4279
+
4280
+ // Both key and value are valid.
4281
+ _result += pairBuffer;
4282
+ }
4283
+
4284
+ state.tag = _tag;
4285
+ state.dump = _result || '{}'; // Empty mapping if no valid pairs.
4286
+ }
4287
+
4288
+ function detectType(state, object, explicit) {
4289
+ var _result, typeList, index, length, type, style;
4290
+
4291
+ typeList = explicit ? state.explicitTypes : state.implicitTypes;
4292
+
4293
+ for (index = 0, length = typeList.length; index < length; index += 1) {
4294
+ type = typeList[index];
4295
+
4296
+ if ((type.instanceOf || type.predicate) &&
4297
+ (!type.instanceOf || ((typeof object === 'object') && (object instanceof type.instanceOf))) &&
4298
+ (!type.predicate || type.predicate(object))) {
4299
+
4300
+ if (explicit) {
4301
+ if (type.multi && type.representName) {
4302
+ state.tag = type.representName(object);
4303
+ } else {
4304
+ state.tag = type.tag;
4305
+ }
4306
+ } else {
4307
+ state.tag = '?';
4308
+ }
4309
+
4310
+ if (type.represent) {
4311
+ style = state.styleMap[type.tag] || type.defaultStyle;
4312
+
4313
+ if (_toString.call(type.represent) === '[object Function]') {
4314
+ _result = type.represent(object, style);
4315
+ } else if (_hasOwnProperty.call(type.represent, style)) {
4316
+ _result = type.represent[style](object, style);
4317
+ } else {
4318
+ throw new exception('!<' + type.tag + '> tag resolver accepts not "' + style + '" style');
4319
+ }
4320
+
4321
+ state.dump = _result;
4322
+ }
4323
+
4324
+ return true;
4325
+ }
4326
+ }
4327
+
4328
+ return false;
4329
+ }
4330
+
4331
+ // Serializes `object` and writes it to global `result`.
4332
+ // Returns true on success, or false on invalid object.
4333
+ //
4334
+ function writeNode(state, level, object, block, compact, iskey, isblockseq) {
4335
+ state.tag = null;
4336
+ state.dump = object;
4337
+
4338
+ if (!detectType(state, object, false)) {
4339
+ detectType(state, object, true);
4340
+ }
4341
+
4342
+ var type = _toString.call(state.dump);
4343
+ var inblock = block;
4344
+ var tagStr;
4345
+
4346
+ if (block) {
4347
+ block = (state.flowLevel < 0 || state.flowLevel > level);
4348
+ }
4349
+
4350
+ var objectOrArray = type === '[object Object]' || type === '[object Array]',
4351
+ duplicateIndex,
4352
+ duplicate;
4353
+
4354
+ if (objectOrArray) {
4355
+ duplicateIndex = state.duplicates.indexOf(object);
4356
+ duplicate = duplicateIndex !== -1;
4357
+ }
4358
+
4359
+ if ((state.tag !== null && state.tag !== '?') || duplicate || (state.indent !== 2 && level > 0)) {
4360
+ compact = false;
4361
+ }
4362
+
4363
+ if (duplicate && state.usedDuplicates[duplicateIndex]) {
4364
+ state.dump = '*ref_' + duplicateIndex;
4365
+ } else {
4366
+ if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
4367
+ state.usedDuplicates[duplicateIndex] = true;
4368
+ }
4369
+ if (type === '[object Object]') {
4370
+ if (block && (Object.keys(state.dump).length !== 0)) {
4371
+ writeBlockMapping(state, level, state.dump, compact);
4372
+ if (duplicate) {
4373
+ state.dump = '&ref_' + duplicateIndex + state.dump;
4374
+ }
4375
+ } else {
4376
+ writeFlowMapping(state, level, state.dump);
4377
+ if (duplicate) {
4378
+ state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
4379
+ }
4380
+ }
4381
+ } else if (type === '[object Array]') {
4382
+ if (block && (state.dump.length !== 0)) {
4383
+ if (state.noArrayIndent && !isblockseq && level > 0) {
4384
+ writeBlockSequence(state, level - 1, state.dump, compact);
4385
+ } else {
4386
+ writeBlockSequence(state, level, state.dump, compact);
4387
+ }
4388
+ if (duplicate) {
4389
+ state.dump = '&ref_' + duplicateIndex + state.dump;
4390
+ }
4391
+ } else {
4392
+ writeFlowSequence(state, level, state.dump);
4393
+ if (duplicate) {
4394
+ state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
4395
+ }
4396
+ }
4397
+ } else if (type === '[object String]') {
4398
+ if (state.tag !== '?') {
4399
+ writeScalar(state, state.dump, level, iskey, inblock);
4400
+ }
4401
+ } else if (type === '[object Undefined]') {
4402
+ return false;
4403
+ } else {
4404
+ if (state.skipInvalid) return false;
4405
+ throw new exception('unacceptable kind of an object to dump ' + type);
4406
+ }
4407
+
4408
+ if (state.tag !== null && state.tag !== '?') {
4409
+ // Need to encode all characters except those allowed by the spec:
4410
+ //
4411
+ // [35] ns-dec-digit ::= [#x30-#x39] /* 0-9 */
4412
+ // [36] ns-hex-digit ::= ns-dec-digit
4413
+ // | [#x41-#x46] /* A-F */ | [#x61-#x66] /* a-f */
4414
+ // [37] ns-ascii-letter ::= [#x41-#x5A] /* A-Z */ | [#x61-#x7A] /* a-z */
4415
+ // [38] ns-word-char ::= ns-dec-digit | ns-ascii-letter | “-”
4416
+ // [39] ns-uri-char ::= “%” ns-hex-digit ns-hex-digit | ns-word-char | “#”
4417
+ // | “;” | “/” | “?” | “:” | “@” | “&” | “=” | “+” | “$” | “,”
4418
+ // | “_” | “.” | “!” | “~” | “*” | “'” | “(” | “)” | “[” | “]”
4419
+ //
4420
+ // Also need to encode '!' because it has special meaning (end of tag prefix).
4421
+ //
4422
+ tagStr = encodeURI(
4423
+ state.tag[0] === '!' ? state.tag.slice(1) : state.tag
4424
+ ).replace(/!/g, '%21');
4425
+
4426
+ if (state.tag[0] === '!') {
4427
+ tagStr = '!' + tagStr;
4428
+ } else if (tagStr.slice(0, 18) === 'tag:yaml.org,2002:') {
4429
+ tagStr = '!!' + tagStr.slice(18);
4430
+ } else {
4431
+ tagStr = '!<' + tagStr + '>';
4432
+ }
4433
+
4434
+ state.dump = tagStr + ' ' + state.dump;
4435
+ }
4436
+ }
4437
+
4438
+ return true;
4439
+ }
4440
+
4441
+ function getDuplicateReferences(object, state) {
4442
+ var objects = [],
4443
+ duplicatesIndexes = [],
4444
+ index,
4445
+ length;
4446
+
4447
+ inspectNode(object, objects, duplicatesIndexes);
4448
+
4449
+ for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
4450
+ state.duplicates.push(objects[duplicatesIndexes[index]]);
4451
+ }
4452
+ state.usedDuplicates = new Array(length);
4453
+ }
4454
+
4455
+ function inspectNode(object, objects, duplicatesIndexes) {
4456
+ var objectKeyList,
4457
+ index,
4458
+ length;
4459
+
4460
+ if (object !== null && typeof object === 'object') {
4461
+ index = objects.indexOf(object);
4462
+ if (index !== -1) {
4463
+ if (duplicatesIndexes.indexOf(index) === -1) {
4464
+ duplicatesIndexes.push(index);
4465
+ }
4466
+ } else {
4467
+ objects.push(object);
4468
+
4469
+ if (Array.isArray(object)) {
4470
+ for (index = 0, length = object.length; index < length; index += 1) {
4471
+ inspectNode(object[index], objects, duplicatesIndexes);
4472
+ }
4473
+ } else {
4474
+ objectKeyList = Object.keys(object);
4475
+
4476
+ for (index = 0, length = objectKeyList.length; index < length; index += 1) {
4477
+ inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
4478
+ }
4479
+ }
4480
+ }
4481
+ }
4482
+ }
4483
+
4484
+ function dump$1(input, options) {
4485
+ options = options || {};
4486
+
4487
+ var state = new State(options);
4488
+
4489
+ if (!state.noRefs) getDuplicateReferences(input, state);
4490
+
4491
+ var value = input;
4492
+
4493
+ if (state.replacer) {
4494
+ value = state.replacer.call({ '': value }, '', value);
4495
+ }
4496
+
4497
+ if (writeNode(state, 0, value, true, true)) return state.dump + '\n';
4498
+
4499
+ return '';
4500
+ }
4501
+
4502
+ var dump_1 = dump$1;
4503
+
4504
+ var dumper = {
4505
+ dump: dump_1
4506
+ };
4507
+
4508
+ function renamed(from, to) {
4509
+ return function () {
4510
+ throw new Error('Function yaml.' + from + ' is removed in js-yaml 4. ' +
4511
+ 'Use yaml.' + to + ' instead, which is now safe by default.');
4512
+ };
4513
+ }
4514
+
4515
+
4516
+ var Type = type;
4517
+ var Schema = schema;
4518
+ var FAILSAFE_SCHEMA = failsafe;
4519
+ var JSON_SCHEMA = json;
4520
+ var CORE_SCHEMA = core;
4521
+ var DEFAULT_SCHEMA = _default;
4522
+ var load = loader.load;
4523
+ var loadAll = loader.loadAll;
4524
+ var dump = dumper.dump;
4525
+ var YAMLException = exception;
4526
+
4527
+ // Re-export all types in case user wants to create custom schema
4528
+ var types = {
4529
+ binary: binary,
4530
+ float: float,
4531
+ map: map,
4532
+ null: _null,
4533
+ pairs: pairs,
4534
+ set: set,
4535
+ timestamp: timestamp,
4536
+ bool: bool,
4537
+ int: int,
4538
+ merge: merge,
4539
+ omap: omap,
4540
+ seq: seq,
4541
+ str: str
4542
+ };
4543
+
4544
+ // Removed functions from JS-YAML 3.0.x
4545
+ var safeLoad = renamed('safeLoad', 'load');
4546
+ var safeLoadAll = renamed('safeLoadAll', 'loadAll');
4547
+ var safeDump = renamed('safeDump', 'dump');
4548
+
4549
+ var jsYaml = {
4550
+ Type: Type,
4551
+ Schema: Schema,
4552
+ FAILSAFE_SCHEMA: FAILSAFE_SCHEMA,
4553
+ JSON_SCHEMA: JSON_SCHEMA,
4554
+ CORE_SCHEMA: CORE_SCHEMA,
4555
+ DEFAULT_SCHEMA: DEFAULT_SCHEMA,
4556
+ load: load,
4557
+ loadAll: loadAll,
4558
+ dump: dump,
4559
+ YAMLException: YAMLException,
4560
+ types: types,
4561
+ safeLoad: safeLoad,
4562
+ safeLoadAll: safeLoadAll,
4563
+ safeDump: safeDump
4564
+ };
4565
+
4566
+ console.log("🦖 remarkYamlTable plugin module loaded");
4567
+ var remarkYamlTable = function (options) {
4568
+ var _a = (options !== null && options !== void 0 ? options : {}).logLevel; _a === void 0 ? exports.LogLevel.Silent : _a;
4569
+ var logger = new Logger(resolveLogLevel(options === null || options === void 0 ? void 0 : options.logLevel), 'remarkYamlTable');
4570
+ logger.log('initialized');
4571
+ return function (tree) {
4572
+ visit(tree, 'code', function (node, index, parent) {
4573
+ if (!parent || index === undefined)
4574
+ return;
4575
+ if (node.lang === 'yaml-table') {
4576
+ try {
4577
+ var data = jsYaml.load(node.value);
4578
+ if (Array.isArray(data) && data.length > 0 && typeof data[0] === 'object') {
4579
+ var headers_1 = Object.keys(data[0]);
4580
+ var tableRows = data.map(function (row) { return ({
4581
+ type: 'tableRow',
4582
+ children: headers_1.map(function (header) {
4583
+ var _a;
4584
+ return ({
4585
+ type: 'tableCell',
4586
+ children: [{ type: 'text', value: String((_a = row[header]) !== null && _a !== void 0 ? _a : '') }],
4587
+ });
4588
+ }),
4589
+ }); });
4590
+ var tableNode = {
4591
+ type: 'table',
4592
+ align: headers_1.map(function () { return null; }),
4593
+ children: tslib.__spreadArray([
4594
+ {
4595
+ type: 'tableRow',
4596
+ children: headers_1.map(function (header) { return ({
4597
+ type: 'tableCell',
4598
+ children: [{ type: 'text', value: header }],
4599
+ }); }),
4600
+ }
4601
+ ], tableRows, true),
4602
+ };
4603
+ parent.children[index] = tableNode;
4604
+ logger.log("generated table with ".concat(headers_1.length, " columns and ").concat(data.length, " rows"), exports.LogLevel.Info);
4605
+ }
4606
+ }
4607
+ catch (error) {
4608
+ logger.log("YAML parsing error: ".concat(error.message), exports.LogLevel.Info);
4609
+ }
4610
+ }
4611
+ });
4612
+ };
4613
+ };
4614
+
4615
+ function timedPlugin(name, plugin, opts) {
4616
+ if (opts === void 0) { opts = {}; }
4617
+ var _a = opts.logLevel; _a === void 0 ? exports.LogLevel.Info : _a;
4618
+ var logger = new Logger(resolveLogLevel(opts === null || opts === void 0 ? void 0 : opts.logLevel), name);
4619
+ return (function () {
4620
+ var args = [];
4621
+ for (var _i = 0; _i < arguments.length; _i++) {
4622
+ args[_i] = arguments[_i];
4623
+ }
4624
+ var instance = plugin.apply(void 0, args);
4625
+ return function (tree, file) {
4626
+ var start = Date.now();
4627
+ var res = instance(tree, file);
4628
+ var dur = Date.now() - start;
4629
+ logger.log("\u23F1 finished in ".concat(dur, "ms"));
4630
+ return res;
4631
+ };
4632
+ });
4633
+ }
4634
+
4635
+ exports.Logger = Logger;
4636
+ exports.remarkCodeSections = remarkCodeSections;
4637
+ exports.remarkReplaceMetaUrl = remarkReplaceMetaUrl;
4638
+ exports.remarkScopedPath = remarkScopedPath;
4639
+ exports.remarkYamlTable = remarkYamlTable;
4640
+ exports.remarkYouTube = remarkYouTube;
4641
+ exports.resolveLogLevel = resolveLogLevel;
4642
+ exports.timedPlugin = timedPlugin;
4643
+ //# sourceMappingURL=plugins.cjs.map