yaml 2.0.0-0 → 2.0.0-11

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 (250) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +51 -35
  3. package/browser/dist/compose/compose-collection.js +59 -0
  4. package/browser/dist/compose/compose-doc.js +40 -0
  5. package/browser/dist/compose/compose-node.js +90 -0
  6. package/browser/dist/compose/compose-scalar.js +81 -0
  7. package/browser/dist/compose/composer.js +217 -0
  8. package/browser/dist/compose/resolve-block-map.js +107 -0
  9. package/browser/dist/compose/resolve-block-scalar.js +192 -0
  10. package/browser/dist/compose/resolve-block-seq.js +45 -0
  11. package/browser/dist/compose/resolve-end.js +37 -0
  12. package/browser/dist/compose/resolve-flow-collection.js +200 -0
  13. package/browser/dist/compose/resolve-flow-scalar.js +223 -0
  14. package/browser/dist/compose/resolve-props.js +130 -0
  15. package/browser/dist/compose/util-contains-newline.js +34 -0
  16. package/browser/dist/compose/util-empty-scalar-position.js +27 -0
  17. package/browser/dist/compose/util-flow-indent-check.js +15 -0
  18. package/browser/dist/compose/util-map-includes.js +17 -0
  19. package/browser/dist/doc/Document.js +328 -0
  20. package/browser/dist/doc/anchors.js +72 -0
  21. package/browser/dist/doc/applyReviver.js +54 -0
  22. package/browser/dist/doc/createNode.js +84 -0
  23. package/browser/dist/doc/directives.js +169 -0
  24. package/browser/dist/errors.js +57 -0
  25. package/browser/dist/index.js +17 -1045
  26. package/browser/dist/log.js +14 -0
  27. package/browser/dist/node_modules/tslib/tslib.es6.js +164 -0
  28. package/browser/dist/nodes/Alias.js +94 -0
  29. package/browser/dist/nodes/Collection.js +146 -0
  30. package/browser/dist/nodes/Node.js +48 -0
  31. package/browser/dist/nodes/Pair.js +36 -0
  32. package/browser/dist/nodes/Scalar.js +23 -0
  33. package/browser/dist/nodes/YAMLMap.js +116 -0
  34. package/browser/dist/nodes/YAMLSeq.js +105 -0
  35. package/browser/dist/nodes/addPairToJSMap.js +104 -0
  36. package/browser/dist/nodes/toJS.js +35 -0
  37. package/browser/dist/parse/cst-scalar.js +215 -0
  38. package/browser/dist/parse/cst-stringify.js +61 -0
  39. package/browser/dist/parse/cst-visit.js +97 -0
  40. package/browser/dist/parse/cst.js +98 -0
  41. package/browser/dist/parse/lexer.js +701 -0
  42. package/browser/dist/parse/line-counter.js +39 -0
  43. package/browser/dist/parse/parser.js +916 -0
  44. package/browser/dist/public-api.js +99 -0
  45. package/browser/dist/schema/Schema.js +34 -0
  46. package/browser/dist/schema/common/map.js +42 -0
  47. package/browser/dist/schema/common/null.js +15 -0
  48. package/browser/dist/schema/common/seq.js +33 -0
  49. package/browser/dist/schema/common/string.js +14 -0
  50. package/browser/dist/schema/core/bool.js +19 -0
  51. package/browser/dist/schema/core/float.js +43 -0
  52. package/browser/dist/schema/core/int.js +38 -0
  53. package/browser/dist/schema/core/schema.js +23 -0
  54. package/browser/dist/schema/json/schema.js +62 -0
  55. package/browser/dist/schema/tags.js +83 -0
  56. package/browser/dist/schema/yaml-1.1/binary.js +66 -0
  57. package/browser/dist/schema/yaml-1.1/bool.js +26 -0
  58. package/browser/dist/schema/yaml-1.1/float.js +46 -0
  59. package/browser/dist/schema/yaml-1.1/int.js +71 -0
  60. package/browser/dist/schema/yaml-1.1/omap.js +73 -0
  61. package/browser/dist/schema/yaml-1.1/pairs.js +77 -0
  62. package/browser/dist/schema/yaml-1.1/schema.js +37 -0
  63. package/browser/dist/schema/yaml-1.1/set.js +87 -0
  64. package/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
  65. package/browser/dist/stringify/foldFlowLines.js +135 -0
  66. package/browser/dist/stringify/stringify.js +124 -0
  67. package/browser/dist/stringify/stringifyCollection.js +152 -0
  68. package/browser/dist/stringify/stringifyComment.js +18 -0
  69. package/browser/dist/stringify/stringifyDocument.js +86 -0
  70. package/browser/dist/stringify/stringifyNumber.js +24 -0
  71. package/browser/dist/stringify/stringifyPair.js +122 -0
  72. package/browser/dist/stringify/stringifyString.js +314 -0
  73. package/browser/dist/util.js +9 -2
  74. package/browser/dist/visit.js +234 -0
  75. package/browser/index.js +5 -1
  76. package/browser/package.json +3 -0
  77. package/dist/compose/compose-collection.d.ts +5 -0
  78. package/dist/compose/compose-collection.js +61 -0
  79. package/dist/compose/compose-doc.d.ts +6 -0
  80. package/dist/compose/compose-doc.js +42 -0
  81. package/dist/compose/compose-node.d.ts +26 -0
  82. package/dist/compose/compose-node.js +93 -0
  83. package/dist/compose/compose-scalar.d.ts +5 -0
  84. package/dist/compose/compose-scalar.js +83 -0
  85. package/dist/compose/composer.d.ts +62 -0
  86. package/dist/compose/composer.js +221 -0
  87. package/dist/compose/resolve-block-map.d.ts +6 -0
  88. package/dist/compose/resolve-block-map.js +109 -0
  89. package/dist/compose/resolve-block-scalar.d.ts +10 -0
  90. package/dist/compose/resolve-block-scalar.js +194 -0
  91. package/dist/compose/resolve-block-seq.d.ts +5 -0
  92. package/dist/compose/resolve-block-seq.js +47 -0
  93. package/dist/compose/resolve-end.d.ts +6 -0
  94. package/dist/compose/resolve-end.js +39 -0
  95. package/dist/compose/resolve-flow-collection.d.ts +6 -0
  96. package/dist/compose/resolve-flow-collection.js +202 -0
  97. package/dist/compose/resolve-flow-scalar.d.ts +10 -0
  98. package/dist/compose/resolve-flow-scalar.js +225 -0
  99. package/dist/compose/resolve-props.d.ts +21 -0
  100. package/dist/compose/resolve-props.js +132 -0
  101. package/dist/compose/util-contains-newline.d.ts +2 -0
  102. package/dist/compose/util-contains-newline.js +36 -0
  103. package/dist/compose/util-empty-scalar-position.d.ts +2 -0
  104. package/dist/compose/util-empty-scalar-position.js +29 -0
  105. package/dist/compose/util-flow-indent-check.d.ts +3 -0
  106. package/dist/compose/util-flow-indent-check.js +17 -0
  107. package/dist/compose/util-map-includes.d.ts +4 -0
  108. package/dist/compose/util-map-includes.js +19 -0
  109. package/dist/doc/Document.d.ts +139 -0
  110. package/dist/doc/Document.js +330 -0
  111. package/dist/doc/anchors.d.ts +24 -0
  112. package/dist/doc/anchors.js +77 -0
  113. package/dist/doc/applyReviver.d.ts +9 -0
  114. package/dist/doc/applyReviver.js +56 -0
  115. package/dist/doc/createNode.d.ts +17 -0
  116. package/dist/doc/createNode.js +86 -0
  117. package/dist/doc/directives.d.ts +49 -0
  118. package/dist/doc/directives.js +171 -0
  119. package/dist/errors.d.ts +21 -0
  120. package/dist/errors.js +62 -0
  121. package/dist/index.d.ts +19 -0
  122. package/dist/index.js +48 -81
  123. package/dist/log.d.ts +3 -0
  124. package/dist/log.js +17 -0
  125. package/dist/node_modules/tslib/tslib.es6.js +76 -0
  126. package/dist/nodes/Alias.d.ts +28 -0
  127. package/dist/nodes/Alias.js +96 -0
  128. package/dist/nodes/Collection.d.ts +73 -0
  129. package/dist/nodes/Collection.js +150 -0
  130. package/dist/nodes/Node.d.ts +53 -0
  131. package/dist/nodes/Node.js +66 -0
  132. package/dist/nodes/Pair.d.ts +21 -0
  133. package/dist/nodes/Pair.js +39 -0
  134. package/dist/nodes/Scalar.d.ts +42 -0
  135. package/dist/nodes/Scalar.js +26 -0
  136. package/dist/nodes/YAMLMap.d.ts +41 -0
  137. package/dist/nodes/YAMLMap.js +119 -0
  138. package/dist/nodes/YAMLSeq.d.ts +55 -0
  139. package/dist/nodes/YAMLSeq.js +107 -0
  140. package/dist/nodes/addPairToJSMap.d.ts +3 -0
  141. package/dist/nodes/addPairToJSMap.js +106 -0
  142. package/dist/nodes/toJS.d.ts +30 -0
  143. package/dist/nodes/toJS.js +37 -0
  144. package/dist/options.d.ts +330 -0
  145. package/dist/parse/cst-scalar.d.ts +64 -0
  146. package/dist/parse/cst-scalar.js +219 -0
  147. package/dist/parse/cst-stringify.d.ts +8 -0
  148. package/dist/parse/cst-stringify.js +63 -0
  149. package/dist/parse/cst-visit.d.ts +39 -0
  150. package/dist/parse/cst-visit.js +99 -0
  151. package/dist/parse/cst.d.ts +106 -0
  152. package/dist/parse/cst.js +112 -0
  153. package/dist/parse/lexer.d.ts +87 -0
  154. package/dist/parse/lexer.js +703 -0
  155. package/dist/parse/line-counter.d.ts +22 -0
  156. package/dist/parse/line-counter.js +41 -0
  157. package/dist/parse/parser.d.ts +84 -0
  158. package/dist/parse/parser.js +920 -0
  159. package/dist/public-api.d.ts +43 -0
  160. package/dist/public-api.js +104 -0
  161. package/dist/schema/Schema.d.ts +18 -0
  162. package/dist/schema/Schema.js +36 -0
  163. package/dist/schema/common/map.d.ts +2 -0
  164. package/dist/schema/common/map.js +44 -0
  165. package/dist/schema/common/null.d.ts +4 -0
  166. package/dist/schema/common/null.js +17 -0
  167. package/dist/schema/common/seq.d.ts +2 -0
  168. package/dist/schema/common/seq.js +35 -0
  169. package/dist/schema/common/string.d.ts +2 -0
  170. package/dist/schema/common/string.js +16 -0
  171. package/dist/schema/core/bool.d.ts +4 -0
  172. package/dist/schema/core/bool.js +21 -0
  173. package/dist/schema/core/float.d.ts +4 -0
  174. package/dist/schema/core/float.js +47 -0
  175. package/dist/schema/core/int.d.ts +4 -0
  176. package/dist/schema/core/int.js +42 -0
  177. package/dist/schema/core/schema.d.ts +1 -0
  178. package/dist/schema/core/schema.js +25 -0
  179. package/dist/schema/json/schema.d.ts +2 -0
  180. package/dist/schema/json/schema.js +64 -0
  181. package/dist/schema/tags.d.ts +40 -0
  182. package/dist/schema/tags.js +86 -0
  183. package/dist/schema/types.d.ts +82 -0
  184. package/dist/schema/yaml-1.1/binary.d.ts +2 -0
  185. package/dist/schema/yaml-1.1/binary.js +68 -0
  186. package/dist/schema/yaml-1.1/bool.d.ts +7 -0
  187. package/dist/schema/yaml-1.1/bool.js +29 -0
  188. package/dist/schema/yaml-1.1/float.d.ts +4 -0
  189. package/dist/schema/yaml-1.1/float.js +50 -0
  190. package/dist/schema/yaml-1.1/int.d.ts +5 -0
  191. package/dist/schema/yaml-1.1/int.js +76 -0
  192. package/dist/schema/yaml-1.1/omap.d.ts +21 -0
  193. package/dist/schema/yaml-1.1/omap.js +76 -0
  194. package/dist/schema/yaml-1.1/pairs.d.ts +10 -0
  195. package/dist/schema/yaml-1.1/pairs.js +81 -0
  196. package/dist/schema/yaml-1.1/schema.d.ts +1 -0
  197. package/dist/schema/yaml-1.1/schema.js +39 -0
  198. package/dist/schema/yaml-1.1/set.d.ts +22 -0
  199. package/dist/schema/yaml-1.1/set.js +90 -0
  200. package/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
  201. package/dist/schema/yaml-1.1/timestamp.js +105 -0
  202. package/dist/stringify/foldFlowLines.d.ts +34 -0
  203. package/dist/stringify/foldFlowLines.js +140 -0
  204. package/dist/stringify/stringify.d.ts +20 -0
  205. package/dist/stringify/stringify.js +127 -0
  206. package/dist/stringify/stringifyCollection.d.ts +17 -0
  207. package/dist/stringify/stringifyCollection.js +154 -0
  208. package/dist/stringify/stringifyComment.d.ts +10 -0
  209. package/dist/stringify/stringifyComment.js +22 -0
  210. package/dist/stringify/stringifyDocument.d.ts +3 -0
  211. package/dist/stringify/stringifyDocument.js +88 -0
  212. package/dist/stringify/stringifyNumber.d.ts +2 -0
  213. package/dist/stringify/stringifyNumber.js +26 -0
  214. package/dist/stringify/stringifyPair.d.ts +3 -0
  215. package/dist/stringify/stringifyPair.js +124 -0
  216. package/dist/stringify/stringifyString.d.ts +3 -0
  217. package/dist/stringify/stringifyString.js +316 -0
  218. package/dist/test-events.d.ts +4 -0
  219. package/dist/test-events.js +125 -151
  220. package/dist/util.d.ts +9 -0
  221. package/dist/util.js +19 -14
  222. package/dist/visit.d.ts +102 -0
  223. package/dist/visit.js +237 -0
  224. package/package.json +49 -51
  225. package/util.d.ts +3 -86
  226. package/util.js +2 -16
  227. package/browser/dist/PlainValue-6b68dc0e.js +0 -1279
  228. package/browser/dist/Schema-d14032c2.js +0 -1047
  229. package/browser/dist/parse-6e806192.js +0 -1904
  230. package/browser/dist/parse-cst.js +0 -2
  231. package/browser/dist/resolveSeq-3477c430.js +0 -2478
  232. package/browser/dist/types.js +0 -3
  233. package/browser/parse-cst.js +0 -1
  234. package/browser/types.js +0 -1
  235. package/browser/util.js +0 -1
  236. package/dist/Document-59bd9290.js +0 -803
  237. package/dist/PlainValue-ec8e588e.js +0 -876
  238. package/dist/Schema-fe1471c4.js +0 -808
  239. package/dist/parse-ab8de154.js +0 -1748
  240. package/dist/parse-cst.js +0 -8
  241. package/dist/resolveSeq-6b2dc4ac.js +0 -2217
  242. package/dist/types.js +0 -22
  243. package/index.d.ts +0 -411
  244. package/index.js +0 -1
  245. package/parse-cst.d.ts +0 -187
  246. package/parse-cst.js +0 -1
  247. package/types.d.ts +0 -379
  248. package/types.js +0 -17
  249. package/types.mjs +0 -17
  250. package/util.mjs +0 -18
@@ -0,0 +1,169 @@
1
+ import { isNode } from '../nodes/Node.js';
2
+ import { visit } from '../visit.js';
3
+
4
+ const escapeChars = {
5
+ '!': '%21',
6
+ ',': '%2C',
7
+ '[': '%5B',
8
+ ']': '%5D',
9
+ '{': '%7B',
10
+ '}': '%7D'
11
+ };
12
+ const escapeTagName = (tn) => tn.replace(/[!,[\]{}]/g, ch => escapeChars[ch]);
13
+ class Directives {
14
+ constructor(yaml, tags) {
15
+ /**
16
+ * The directives-end/doc-start marker `---`. If `null`, a marker may still be
17
+ * included in the document's stringified representation.
18
+ */
19
+ this.docStart = null;
20
+ /** The doc-end marker `...`. */
21
+ this.docEnd = false;
22
+ this.yaml = Object.assign({}, Directives.defaultYaml, yaml);
23
+ this.tags = Object.assign({}, Directives.defaultTags, tags);
24
+ }
25
+ clone() {
26
+ const copy = new Directives(this.yaml, this.tags);
27
+ copy.docStart = this.docStart;
28
+ return copy;
29
+ }
30
+ /**
31
+ * During parsing, get a Directives instance for the current document and
32
+ * update the stream state according to the current version's spec.
33
+ */
34
+ atDocument() {
35
+ const res = new Directives(this.yaml, this.tags);
36
+ switch (this.yaml.version) {
37
+ case '1.1':
38
+ this.atNextDocument = true;
39
+ break;
40
+ case '1.2':
41
+ this.atNextDocument = false;
42
+ this.yaml = {
43
+ explicit: Directives.defaultYaml.explicit,
44
+ version: '1.2'
45
+ };
46
+ this.tags = Object.assign({}, Directives.defaultTags);
47
+ break;
48
+ }
49
+ return res;
50
+ }
51
+ /**
52
+ * @param onError - May be called even if the action was successful
53
+ * @returns `true` on success
54
+ */
55
+ add(line, onError) {
56
+ if (this.atNextDocument) {
57
+ this.yaml = { explicit: Directives.defaultYaml.explicit, version: '1.1' };
58
+ this.tags = Object.assign({}, Directives.defaultTags);
59
+ this.atNextDocument = false;
60
+ }
61
+ const parts = line.trim().split(/[ \t]+/);
62
+ const name = parts.shift();
63
+ switch (name) {
64
+ case '%TAG': {
65
+ if (parts.length !== 2) {
66
+ onError(0, '%TAG directive should contain exactly two parts');
67
+ if (parts.length < 2)
68
+ return false;
69
+ }
70
+ const [handle, prefix] = parts;
71
+ this.tags[handle] = prefix;
72
+ return true;
73
+ }
74
+ case '%YAML': {
75
+ this.yaml.explicit = true;
76
+ if (parts.length !== 1) {
77
+ onError(0, '%YAML directive should contain exactly one part');
78
+ return false;
79
+ }
80
+ const [version] = parts;
81
+ if (version === '1.1' || version === '1.2') {
82
+ this.yaml.version = version;
83
+ return true;
84
+ }
85
+ else {
86
+ const isValid = /^\d+\.\d+$/.test(version);
87
+ onError(6, `Unsupported YAML version ${version}`, isValid);
88
+ return false;
89
+ }
90
+ }
91
+ default:
92
+ onError(0, `Unknown directive ${name}`, true);
93
+ return false;
94
+ }
95
+ }
96
+ /**
97
+ * Resolves a tag, matching handles to those defined in %TAG directives.
98
+ *
99
+ * @returns Resolved tag, which may also be the non-specific tag `'!'` or a
100
+ * `'!local'` tag, or `null` if unresolvable.
101
+ */
102
+ tagName(source, onError) {
103
+ if (source === '!')
104
+ return '!'; // non-specific tag
105
+ if (source[0] !== '!') {
106
+ onError(`Not a valid tag: ${source}`);
107
+ return null;
108
+ }
109
+ if (source[1] === '<') {
110
+ const verbatim = source.slice(2, -1);
111
+ if (verbatim === '!' || verbatim === '!!') {
112
+ onError(`Verbatim tags aren't resolved, so ${source} is invalid.`);
113
+ return null;
114
+ }
115
+ if (source[source.length - 1] !== '>')
116
+ onError('Verbatim tags must end with a >');
117
+ return verbatim;
118
+ }
119
+ const [, handle, suffix] = source.match(/^(.*!)([^!]*)$/);
120
+ if (!suffix)
121
+ onError(`The ${source} tag has no suffix`);
122
+ const prefix = this.tags[handle];
123
+ if (prefix)
124
+ return prefix + decodeURIComponent(suffix);
125
+ if (handle === '!')
126
+ return source; // local tag
127
+ onError(`Could not resolve tag: ${source}`);
128
+ return null;
129
+ }
130
+ /**
131
+ * Given a fully resolved tag, returns its printable string form,
132
+ * taking into account current tag prefixes and defaults.
133
+ */
134
+ tagString(tag) {
135
+ for (const [handle, prefix] of Object.entries(this.tags)) {
136
+ if (tag.startsWith(prefix))
137
+ return handle + escapeTagName(tag.substring(prefix.length));
138
+ }
139
+ return tag[0] === '!' ? tag : `!<${tag}>`;
140
+ }
141
+ toString(doc) {
142
+ const lines = this.yaml.explicit
143
+ ? [`%YAML ${this.yaml.version || '1.2'}`]
144
+ : [];
145
+ const tagEntries = Object.entries(this.tags);
146
+ let tagNames;
147
+ if (doc && tagEntries.length > 0 && isNode(doc.contents)) {
148
+ const tags = {};
149
+ visit(doc.contents, (_key, node) => {
150
+ if (isNode(node) && node.tag)
151
+ tags[node.tag] = true;
152
+ });
153
+ tagNames = Object.keys(tags);
154
+ }
155
+ else
156
+ tagNames = [];
157
+ for (const [handle, prefix] of tagEntries) {
158
+ if (handle === '!!' && prefix === 'tag:yaml.org,2002:')
159
+ continue;
160
+ if (!doc || tagNames.some(tn => tn.startsWith(prefix)))
161
+ lines.push(`%TAG ${handle} ${prefix}`);
162
+ }
163
+ return lines.join('\n');
164
+ }
165
+ }
166
+ Directives.defaultYaml = { explicit: false, version: '1.2' };
167
+ Directives.defaultTags = { '!!': 'tag:yaml.org,2002:' };
168
+
169
+ export { Directives };
@@ -0,0 +1,57 @@
1
+ class YAMLError extends Error {
2
+ constructor(name, pos, code, message) {
3
+ super();
4
+ this.name = name;
5
+ this.code = code;
6
+ this.message = message;
7
+ this.pos = pos;
8
+ }
9
+ }
10
+ class YAMLParseError extends YAMLError {
11
+ constructor(pos, code, message) {
12
+ super('YAMLParseError', pos, code, message);
13
+ }
14
+ }
15
+ class YAMLWarning extends YAMLError {
16
+ constructor(pos, code, message) {
17
+ super('YAMLWarning', pos, code, message);
18
+ }
19
+ }
20
+ const prettifyError = (src, lc) => (error) => {
21
+ if (error.pos[0] === -1)
22
+ return;
23
+ error.linePos = error.pos.map(pos => lc.linePos(pos));
24
+ const { line, col } = error.linePos[0];
25
+ error.message += ` at line ${line}, column ${col}`;
26
+ let ci = col - 1;
27
+ let lineStr = src
28
+ .substring(lc.lineStarts[line - 1], lc.lineStarts[line])
29
+ .replace(/[\n\r]+$/, '');
30
+ // Trim to max 80 chars, keeping col position near the middle
31
+ if (ci >= 60 && lineStr.length > 80) {
32
+ const trimStart = Math.min(ci - 39, lineStr.length - 79);
33
+ lineStr = '…' + lineStr.substring(trimStart);
34
+ ci -= trimStart - 1;
35
+ }
36
+ if (lineStr.length > 80)
37
+ lineStr = lineStr.substring(0, 79) + '…';
38
+ // Include previous line in context if pointing at line start
39
+ if (line > 1 && /^ *$/.test(lineStr.substring(0, ci))) {
40
+ // Regexp won't match if start is trimmed
41
+ let prev = src.substring(lc.lineStarts[line - 2], lc.lineStarts[line - 1]);
42
+ if (prev.length > 80)
43
+ prev = prev.substring(0, 79) + '…\n';
44
+ lineStr = prev + lineStr;
45
+ }
46
+ if (/[^ ]/.test(lineStr)) {
47
+ let count = 1;
48
+ const end = error.linePos[1];
49
+ if (end && end.line === line && end.col > col) {
50
+ count = Math.min(end.col - col, 80 - ci);
51
+ }
52
+ const pointer = ' '.repeat(ci) + '^'.repeat(count);
53
+ error.message += `:\n\n${lineStr}\n${pointer}\n`;
54
+ }
55
+ };
56
+
57
+ export { YAMLError, YAMLParseError, YAMLWarning, prettifyError };