yaml 1.8.2 → 1.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/dist/Anchors.js +10 -13
- package/browser/dist/Document.js +72 -67
- package/browser/dist/addComment.js +1 -1
- package/browser/dist/cst/Alias.js +12 -8
- package/browser/dist/cst/BlankLine.js +16 -20
- package/browser/dist/cst/BlockValue.js +14 -10
- package/browser/dist/cst/Collection.js +17 -13
- package/browser/dist/cst/CollectionItem.js +15 -11
- package/browser/dist/cst/Comment.js +13 -9
- package/browser/dist/cst/Directive.js +13 -9
- package/browser/dist/cst/Document.js +17 -13
- package/browser/dist/cst/FlowCollection.js +17 -13
- package/browser/dist/cst/Node.js +3 -5
- package/browser/dist/cst/ParseContext.js +12 -14
- package/browser/dist/cst/PlainValue.js +12 -8
- package/browser/dist/cst/QuoteDouble.js +13 -9
- package/browser/dist/cst/QuoteSingle.js +13 -9
- package/browser/dist/cst/Range.js +2 -5
- package/browser/dist/cst/parse.js +3 -3
- package/browser/dist/errors.js +23 -8
- package/browser/dist/foldFlowLines.js +1 -1
- package/browser/dist/index.js +71 -21
- package/browser/dist/listTagNames.js +5 -5
- package/browser/dist/schema/Alias.js +30 -34
- package/browser/dist/schema/Collection.js +40 -47
- package/browser/dist/schema/Map.js +39 -56
- package/browser/dist/schema/Merge.js +37 -46
- package/browser/dist/schema/Node.js +2 -5
- package/browser/dist/schema/Pair.js +36 -13
- package/browser/dist/schema/Scalar.js +13 -9
- package/browser/dist/schema/Seq.js +27 -25
- package/browser/dist/schema/index.js +25 -39
- package/browser/dist/schema/parseMap.js +8 -8
- package/browser/dist/schema/parseSeq.js +5 -5
- package/browser/dist/schema/parseUtils.js +11 -15
- package/browser/dist/stringify.js +2 -1
- package/browser/dist/tags/core.js +39 -23
- package/browser/dist/tags/failsafe/index.js +4 -4
- package/browser/dist/tags/failsafe/map.js +15 -18
- package/browser/dist/tags/failsafe/seq.js +14 -18
- package/browser/dist/tags/failsafe/string.js +1 -1
- package/browser/dist/tags/index.js +10 -10
- package/browser/dist/tags/json.js +27 -26
- package/browser/dist/tags/options.js +3 -0
- package/browser/dist/tags/yaml-1.1/binary.js +10 -8
- package/browser/dist/tags/yaml-1.1/index.js +75 -43
- package/browser/dist/tags/yaml-1.1/omap.js +34 -39
- package/browser/dist/tags/yaml-1.1/pairs.js +17 -20
- package/browser/dist/tags/yaml-1.1/set.js +27 -23
- package/browser/dist/test-events.js +4 -4
- package/browser/dist/toJSON.js +3 -4
- package/browser/dist/warnings.js +29 -18
- package/browser/index.js +1 -1
- package/browser/map.js +4 -2
- package/browser/pair.js +4 -2
- package/browser/parse-cst.js +1 -1
- package/browser/scalar.js +4 -2
- package/browser/schema.js +11 -6
- package/browser/seq.js +4 -2
- package/browser/types/binary.js +5 -6
- package/browser/types/omap.js +4 -2
- package/browser/types/pairs.js +4 -2
- package/browser/types/set.js +4 -2
- package/browser/types/timestamp.js +5 -9
- package/browser/types.js +12 -10
- package/browser/util.js +16 -13
- package/dist/Anchors.js +13 -18
- package/dist/Document.js +52 -48
- package/dist/addComment.js +1 -4
- package/dist/constants.js +0 -3
- package/dist/cst/Alias.js +8 -13
- package/dist/cst/BlankLine.js +8 -24
- package/dist/cst/BlockValue.js +12 -17
- package/dist/cst/Collection.js +22 -27
- package/dist/cst/CollectionItem.js +16 -21
- package/dist/cst/Comment.js +6 -11
- package/dist/cst/Directive.js +7 -12
- package/dist/cst/Document.js +23 -28
- package/dist/cst/FlowCollection.js +21 -26
- package/dist/cst/Node.js +4 -9
- package/dist/cst/ParseContext.js +38 -43
- package/dist/cst/PlainValue.js +10 -15
- package/dist/cst/QuoteDouble.js +9 -14
- package/dist/cst/QuoteSingle.js +9 -14
- package/dist/cst/Range.js +2 -5
- package/dist/cst/parse.js +5 -10
- package/dist/cst/source-utils.js +0 -3
- package/dist/errors.js +4 -9
- package/dist/foldFlowLines.js +1 -4
- package/dist/index.js +59 -17
- package/dist/listTagNames.js +9 -14
- package/dist/schema/Alias.js +12 -17
- package/dist/schema/Collection.js +16 -20
- package/dist/schema/Map.js +12 -17
- package/dist/schema/Merge.js +13 -18
- package/dist/schema/Node.js +2 -5
- package/dist/schema/Pair.js +44 -31
- package/dist/schema/Scalar.js +6 -11
- package/dist/schema/Seq.js +9 -14
- package/dist/schema/index.js +22 -27
- package/dist/schema/parseMap.js +19 -28
- package/dist/schema/parseSeq.js +10 -15
- package/dist/schema/parseUtils.js +0 -3
- package/dist/stringify.js +6 -12
- package/dist/tags/core.js +34 -26
- package/dist/tags/failsafe/index.js +6 -11
- package/dist/tags/failsafe/map.js +8 -13
- package/dist/tags/failsafe/seq.js +8 -13
- package/dist/tags/failsafe/string.js +3 -6
- package/dist/tags/index.js +20 -29
- package/dist/tags/json.js +26 -22
- package/dist/tags/options.js +5 -4
- package/dist/tags/yaml-1.1/binary.js +11 -11
- package/dist/tags/yaml-1.1/index.js +69 -38
- package/dist/tags/yaml-1.1/omap.js +19 -24
- package/dist/tags/yaml-1.1/pairs.js +12 -17
- package/dist/tags/yaml-1.1/set.js +12 -21
- package/dist/tags/yaml-1.1/timestamp.js +0 -3
- package/dist/test-events.js +4 -9
- package/dist/toJSON.js +3 -5
- package/dist/warnings.js +31 -22
- package/index.d.ts +358 -0
- package/index.js +1 -1
- package/map.js +1 -1
- package/package.json +29 -23
- package/pair.js +1 -1
- package/parse-cst.d.ts +187 -0
- package/parse-cst.js +1 -1
- package/scalar.js +1 -1
- package/schema.js +2 -2
- package/seq.js +1 -1
- package/types/binary.js +1 -1
- package/types/omap.js +1 -1
- package/types/pairs.js +1 -1
- package/types/set.js +1 -1
- package/types/timestamp.js +1 -1
- package/types.d.ts +393 -0
- package/types.js +7 -6
- package/types.mjs +6 -5
- package/util.d.ts +86 -0
- package/util.js +6 -5
- package/util.mjs +4 -3
package/types.d.ts
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import { Document, scalarOptions } from './index'
|
|
2
|
+
import { CST } from './parse-cst'
|
|
3
|
+
import { Type } from './util'
|
|
4
|
+
|
|
5
|
+
export const binaryOptions: scalarOptions.Binary
|
|
6
|
+
export const boolOptions: scalarOptions.Bool
|
|
7
|
+
export const intOptions: scalarOptions.Int
|
|
8
|
+
export const nullOptions: scalarOptions.Null
|
|
9
|
+
export const strOptions: scalarOptions.Str
|
|
10
|
+
|
|
11
|
+
export class Schema {
|
|
12
|
+
/** Default: `'tag:yaml.org,2002:'` */
|
|
13
|
+
static defaultPrefix: string
|
|
14
|
+
static defaultTags: {
|
|
15
|
+
/** Default: `'tag:yaml.org,2002:map'` */
|
|
16
|
+
MAP: string
|
|
17
|
+
/** Default: `'tag:yaml.org,2002:seq'` */
|
|
18
|
+
SEQ: string
|
|
19
|
+
/** Default: `'tag:yaml.org,2002:str'` */
|
|
20
|
+
STR: string
|
|
21
|
+
}
|
|
22
|
+
constructor(options: Schema.Options)
|
|
23
|
+
/**
|
|
24
|
+
* Convert any value into a `Node` using this schema, recursively turning
|
|
25
|
+
* objects into collectsions.
|
|
26
|
+
*
|
|
27
|
+
* @param wrapScalars If `true`, also wraps plain values in `Scalar` objects;
|
|
28
|
+
* if undefined or `false` and `value` is not an object, it will be returned
|
|
29
|
+
* directly.
|
|
30
|
+
* @param tag Use to specify the collection type, e.g. `"!!omap"`. Note that
|
|
31
|
+
* this requires the corresponding tag to be available in this schema.
|
|
32
|
+
*/
|
|
33
|
+
createNode(
|
|
34
|
+
value: any,
|
|
35
|
+
wrapScalars?: boolean,
|
|
36
|
+
tag?: string,
|
|
37
|
+
ctx?: Schema.CreateNodeContext
|
|
38
|
+
): AST.Node
|
|
39
|
+
merge: boolean
|
|
40
|
+
name: Schema.Name
|
|
41
|
+
sortMapEntries: ((a: Pair, b: Pair) => number) | null
|
|
42
|
+
tags: Schema.Tag[]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export namespace Schema {
|
|
46
|
+
type Name = 'core' | 'failsafe' | 'json' | 'yaml-1.1'
|
|
47
|
+
|
|
48
|
+
interface Options {
|
|
49
|
+
/**
|
|
50
|
+
* Array of additional tags to include in the schema, or a function that may
|
|
51
|
+
* modify the schema's base tag array.
|
|
52
|
+
*/
|
|
53
|
+
customTags?: (TagId | Tag)[] | ((tags: Tag[]) => Tag[])
|
|
54
|
+
/**
|
|
55
|
+
* Enable support for `<<` merge keys.
|
|
56
|
+
*
|
|
57
|
+
* Default: `false` for YAML 1.2, `true` for earlier versions
|
|
58
|
+
*/
|
|
59
|
+
merge?: boolean
|
|
60
|
+
/**
|
|
61
|
+
* The base schema to use.
|
|
62
|
+
*
|
|
63
|
+
* Default: `"core"` for YAML 1.2, `"yaml-1.1"` for earlier versions
|
|
64
|
+
*/
|
|
65
|
+
schema?: Name
|
|
66
|
+
/**
|
|
67
|
+
* When stringifying, sort map entries. If `true`, sort by comparing key values with `<`.
|
|
68
|
+
*
|
|
69
|
+
* Default: `false`
|
|
70
|
+
*/
|
|
71
|
+
sortMapEntries?: boolean | ((a: Pair, b: Pair) => number)
|
|
72
|
+
/**
|
|
73
|
+
* @deprecated Use `customTags` instead.
|
|
74
|
+
*/
|
|
75
|
+
tags?: Options['customTags']
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface CreateNodeContext {
|
|
79
|
+
wrapScalars?: boolean
|
|
80
|
+
[key: string]: any
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface StringifyContext {
|
|
84
|
+
forceBlockIndent?: boolean
|
|
85
|
+
implicitKey?: boolean
|
|
86
|
+
indent?: string
|
|
87
|
+
indentAtStart?: number
|
|
88
|
+
inFlow?: boolean
|
|
89
|
+
[key: string]: any
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
type TagId =
|
|
93
|
+
| 'binary'
|
|
94
|
+
| 'bool'
|
|
95
|
+
| 'float'
|
|
96
|
+
| 'floatExp'
|
|
97
|
+
| 'floatNaN'
|
|
98
|
+
| 'floatTime'
|
|
99
|
+
| 'int'
|
|
100
|
+
| 'intHex'
|
|
101
|
+
| 'intOct'
|
|
102
|
+
| 'intTime'
|
|
103
|
+
| 'null'
|
|
104
|
+
| 'omap'
|
|
105
|
+
| 'pairs'
|
|
106
|
+
| 'set'
|
|
107
|
+
| 'timestamp'
|
|
108
|
+
|
|
109
|
+
type Tag = CustomTag | DefaultTag
|
|
110
|
+
|
|
111
|
+
interface BaseTag {
|
|
112
|
+
/**
|
|
113
|
+
* An optional factory function, used e.g. by collections when wrapping JS objects as AST nodes.
|
|
114
|
+
*/
|
|
115
|
+
createNode?: (
|
|
116
|
+
schema: Schema,
|
|
117
|
+
value: any,
|
|
118
|
+
ctx: Schema.CreateNodeContext
|
|
119
|
+
) => YAMLMap | YAMLSeq | Scalar
|
|
120
|
+
/**
|
|
121
|
+
* If a tag has multiple forms that should be parsed and/or stringified differently, use `format` to identify them.
|
|
122
|
+
*/
|
|
123
|
+
format?: string
|
|
124
|
+
/**
|
|
125
|
+
* Used by `YAML.createNode` to detect your data type, e.g. using `typeof` or
|
|
126
|
+
* `instanceof`.
|
|
127
|
+
*/
|
|
128
|
+
identify(value: any): boolean
|
|
129
|
+
/**
|
|
130
|
+
* The `Node` child class that implements this tag. Required for collections and tags that have overlapping JS representations.
|
|
131
|
+
*/
|
|
132
|
+
nodeClass?: new () => any
|
|
133
|
+
/**
|
|
134
|
+
* Used by some tags to configure their stringification, where applicable.
|
|
135
|
+
*/
|
|
136
|
+
options?: object
|
|
137
|
+
/**
|
|
138
|
+
* Optional function stringifying the AST node in the current context. If your
|
|
139
|
+
* data includes a suitable `.toString()` method, you can probably leave this
|
|
140
|
+
* undefined and use the default stringifier.
|
|
141
|
+
*
|
|
142
|
+
* @param item The node being stringified.
|
|
143
|
+
* @param ctx Contains the stringifying context variables.
|
|
144
|
+
* @param onComment Callback to signal that the stringifier includes the
|
|
145
|
+
* item's comment in its output.
|
|
146
|
+
* @param onChompKeep Callback to signal that the output uses a block scalar
|
|
147
|
+
* type with the `+` chomping indicator.
|
|
148
|
+
*/
|
|
149
|
+
stringify?: (
|
|
150
|
+
item: AST.Node,
|
|
151
|
+
ctx: Schema.StringifyContext,
|
|
152
|
+
onComment?: () => void,
|
|
153
|
+
onChompKeep?: () => void
|
|
154
|
+
) => string
|
|
155
|
+
/**
|
|
156
|
+
* The identifier for your data type, with which its stringified form will be
|
|
157
|
+
* prefixed. Should either be a !-prefixed local `!tag`, or a fully qualified
|
|
158
|
+
* `tag:domain,date:foo`.
|
|
159
|
+
*/
|
|
160
|
+
tag: string
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
interface CustomTag extends BaseTag {
|
|
164
|
+
/**
|
|
165
|
+
* A JavaScript class that should be matched to this tag, e.g. `Date` for `!!timestamp`.
|
|
166
|
+
* @deprecated Use `Tag.identify` instead
|
|
167
|
+
*/
|
|
168
|
+
class?: new () => any
|
|
169
|
+
/**
|
|
170
|
+
* Turns a CST node into an AST node. If returning a non-`Node` value, the
|
|
171
|
+
* output will be wrapped as a `Scalar`.
|
|
172
|
+
*/
|
|
173
|
+
resolve(doc: Document, cstNode: CST.Node): AST.Node | any
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
interface DefaultTag extends BaseTag {
|
|
177
|
+
/**
|
|
178
|
+
* If `true`, together with `test` allows for values to be stringified without
|
|
179
|
+
* an explicit tag. For most cases, it's unlikely that you'll actually want to
|
|
180
|
+
* use this, even if you first think you do.
|
|
181
|
+
*/
|
|
182
|
+
default: true
|
|
183
|
+
/**
|
|
184
|
+
* Alternative form used by default tags; called with `test` match results.
|
|
185
|
+
*/
|
|
186
|
+
resolve(...match: string[]): AST.Node | any
|
|
187
|
+
/**
|
|
188
|
+
* Together with `default` allows for values to be stringified without an
|
|
189
|
+
* explicit tag and detected using a regular expression. For most cases, it's
|
|
190
|
+
* unlikely that you'll actually want to use these, even if you first think
|
|
191
|
+
* you do.
|
|
192
|
+
*/
|
|
193
|
+
test: RegExp
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export class Scalar extends AST.Node {
|
|
198
|
+
constructor(value: any)
|
|
199
|
+
toJSON(arg?: any, ctx?: AST.NodeToJsonContext): any
|
|
200
|
+
type?: Scalar.Type
|
|
201
|
+
/**
|
|
202
|
+
* By default (undefined), numbers use decimal notation.
|
|
203
|
+
* The YAML 1.2 core schema only supports 'HEX' and 'OCT'.
|
|
204
|
+
*/
|
|
205
|
+
format?: 'BIN' | 'HEX' | 'OCT' | 'TIME'
|
|
206
|
+
value: any
|
|
207
|
+
}
|
|
208
|
+
export namespace Scalar {
|
|
209
|
+
type Type =
|
|
210
|
+
| Type.BLOCK_FOLDED
|
|
211
|
+
| Type.BLOCK_LITERAL
|
|
212
|
+
| Type.PLAIN
|
|
213
|
+
| Type.QUOTE_DOUBLE
|
|
214
|
+
| Type.QUOTE_SINGLE
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export class Pair extends AST.Node {
|
|
218
|
+
constructor(key: any, value?: any)
|
|
219
|
+
toJSON(arg?: any, ctx?: AST.NodeToJsonContext): object | Map<any, any>
|
|
220
|
+
type: Pair.Type.PAIR | Pair.Type.MERGE_PAIR
|
|
221
|
+
/** Always Node or null when parsed, but can be set to anything. */
|
|
222
|
+
key: any
|
|
223
|
+
/** Always Node or null when parsed, but can be set to anything. */
|
|
224
|
+
value: any
|
|
225
|
+
cstNode?: never // no corresponding cstNode
|
|
226
|
+
}
|
|
227
|
+
export namespace Pair {
|
|
228
|
+
enum Type {
|
|
229
|
+
PAIR = 'PAIR',
|
|
230
|
+
MERGE_PAIR = 'MERGE_PAIR'
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export class YAMLMap extends AST.Collection {
|
|
235
|
+
type?: Type.FLOW_MAP | Type.MAP
|
|
236
|
+
items: Array<Pair | AST.Merge>
|
|
237
|
+
hasAllNullValues(): boolean
|
|
238
|
+
toJSON(arg?: any, ctx?: AST.NodeToJsonContext): object | Map<any, any>
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export class YAMLSeq extends AST.Collection {
|
|
242
|
+
type?: Type.FLOW_SEQ | Type.SEQ
|
|
243
|
+
delete(key: number | string | Scalar): boolean
|
|
244
|
+
get(key: number | string | Scalar, keepScalar?: boolean): any
|
|
245
|
+
has(key: number | string | Scalar): boolean
|
|
246
|
+
set(key: number | string | Scalar, value: any): void
|
|
247
|
+
hasAllNullValues(): boolean
|
|
248
|
+
toJSON(arg?: any, ctx?: AST.NodeToJsonContext): any[]
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export namespace AST {
|
|
252
|
+
type AstNode = ScalarNode | CollectionNode | Alias
|
|
253
|
+
|
|
254
|
+
type ScalarNode =
|
|
255
|
+
| BlockFolded
|
|
256
|
+
| BlockLiteral
|
|
257
|
+
| PlainValue
|
|
258
|
+
| QuoteDouble
|
|
259
|
+
| QuoteSingle
|
|
260
|
+
|
|
261
|
+
type CollectionNode = FlowMap | BlockMap | FlowSeq | BlockSeq
|
|
262
|
+
|
|
263
|
+
class Node {
|
|
264
|
+
/** A comment on or immediately after this */
|
|
265
|
+
comment?: string | null
|
|
266
|
+
/** A comment before this */
|
|
267
|
+
commentBefore?: string | null
|
|
268
|
+
/** Only available when `keepCstNodes` is set to `true` */
|
|
269
|
+
cstNode?: CST.Node
|
|
270
|
+
/**
|
|
271
|
+
* The [start, end] range of characters of the source parsed
|
|
272
|
+
* into this node (undefined for pairs or if not parsed)
|
|
273
|
+
*/
|
|
274
|
+
range?: [number, number] | null
|
|
275
|
+
/** A blank line before this node and its commentBefore */
|
|
276
|
+
spaceBefore?: boolean
|
|
277
|
+
/** A fully qualified tag, if required */
|
|
278
|
+
tag?: string
|
|
279
|
+
/** A plain JS representation of this node */
|
|
280
|
+
toJSON(arg?: any): any
|
|
281
|
+
/** The type of this node */
|
|
282
|
+
type?: Type | Pair.Type
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
class Collection extends Node {
|
|
286
|
+
type?: Type.MAP | Type.FLOW_MAP | Type.SEQ | Type.FLOW_SEQ | Type.DOCUMENT
|
|
287
|
+
items: any[]
|
|
288
|
+
schema?: Schema
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Adds a value to the collection. For `!!map` and `!!omap` the value must
|
|
292
|
+
* be a Pair instance or a `{ key, value }` object, which may not have a key
|
|
293
|
+
* that already exists in the map.
|
|
294
|
+
*/
|
|
295
|
+
add(value: any): void
|
|
296
|
+
addIn(path: Iterable<any>, value: any): void
|
|
297
|
+
/**
|
|
298
|
+
* Removes a value from the collection.
|
|
299
|
+
* @returns `true` if the item was found and removed.
|
|
300
|
+
*/
|
|
301
|
+
delete(key: any): boolean
|
|
302
|
+
deleteIn(path: Iterable<any>): boolean
|
|
303
|
+
/**
|
|
304
|
+
* Returns item at `key`, or `undefined` if not found. By default unwraps
|
|
305
|
+
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
306
|
+
* `true` (collections are always returned intact).
|
|
307
|
+
*/
|
|
308
|
+
get(key: any, keepScalar?: boolean): any
|
|
309
|
+
getIn(path: Iterable<any>, keepScalar?: boolean): any
|
|
310
|
+
/**
|
|
311
|
+
* Checks if the collection includes a value with the key `key`.
|
|
312
|
+
*/
|
|
313
|
+
has(key: any): boolean
|
|
314
|
+
hasIn(path: Iterable<any>): boolean
|
|
315
|
+
/**
|
|
316
|
+
* Sets a value in this collection. For `!!set`, `value` needs to be a
|
|
317
|
+
* boolean to add/remove the item from the set.
|
|
318
|
+
*/
|
|
319
|
+
set(key: any, value: any): void
|
|
320
|
+
setIn(path: Iterable<any>, value: any): void
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
interface NodeToJsonContext {
|
|
324
|
+
anchors?: any[]
|
|
325
|
+
doc: Document
|
|
326
|
+
keep?: boolean
|
|
327
|
+
mapAsMap?: boolean
|
|
328
|
+
maxAliasCount?: number
|
|
329
|
+
onCreate?: (node: Node) => void
|
|
330
|
+
[key: string]: any
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
interface BlockFolded extends Scalar {
|
|
334
|
+
type: Type.BLOCK_FOLDED
|
|
335
|
+
cstNode?: CST.BlockFolded
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
interface BlockLiteral extends Scalar {
|
|
339
|
+
type: Type.BLOCK_LITERAL
|
|
340
|
+
cstNode?: CST.BlockLiteral
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
interface PlainValue extends Scalar {
|
|
344
|
+
type: Type.PLAIN
|
|
345
|
+
cstNode?: CST.PlainValue
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
interface QuoteDouble extends Scalar {
|
|
349
|
+
type: Type.QUOTE_DOUBLE
|
|
350
|
+
cstNode?: CST.QuoteDouble
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
interface QuoteSingle extends Scalar {
|
|
354
|
+
type: Type.QUOTE_SINGLE
|
|
355
|
+
cstNode?: CST.QuoteSingle
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
interface Alias extends Node {
|
|
359
|
+
type: Type.ALIAS
|
|
360
|
+
source: AstNode
|
|
361
|
+
cstNode?: CST.Alias
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
interface Merge extends Pair {
|
|
365
|
+
type: Pair.Type.MERGE_PAIR
|
|
366
|
+
/** Always Scalar('<<'), defined by the type specification */
|
|
367
|
+
key: PlainValue
|
|
368
|
+
/** Always YAMLSeq<Alias(Map)>, stringified as *A if length = 1 */
|
|
369
|
+
value: YAMLSeq
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
interface FlowMap extends YAMLMap {
|
|
373
|
+
type: Type.FLOW_MAP
|
|
374
|
+
cstNode?: CST.FlowMap
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
interface BlockMap extends YAMLMap {
|
|
378
|
+
type: Type.MAP
|
|
379
|
+
cstNode?: CST.Map
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
interface FlowSeq extends YAMLSeq {
|
|
383
|
+
type: Type.FLOW_SEQ
|
|
384
|
+
items: Array<AstNode | Pair>
|
|
385
|
+
cstNode?: CST.FlowSeq
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
interface BlockSeq extends YAMLSeq {
|
|
389
|
+
type: Type.SEQ
|
|
390
|
+
items: Array<AstNode | null>
|
|
391
|
+
cstNode?: CST.Seq
|
|
392
|
+
}
|
|
393
|
+
}
|
package/types.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
const opt = require('./dist/tags/options')
|
|
2
2
|
exports.binaryOptions = opt.binaryOptions
|
|
3
3
|
exports.boolOptions = opt.boolOptions
|
|
4
|
+
exports.intOptions = opt.intOptions
|
|
4
5
|
exports.nullOptions = opt.nullOptions
|
|
5
6
|
exports.strOptions = opt.strOptions
|
|
6
7
|
|
|
7
|
-
exports.Schema = require('./dist/schema').
|
|
8
|
-
exports.YAMLMap = require('./dist/schema/Map').
|
|
9
|
-
exports.YAMLSeq = require('./dist/schema/Seq').
|
|
10
|
-
exports.Pair = require('./dist/schema/Pair').
|
|
11
|
-
exports.Scalar = require('./dist/schema/Scalar').
|
|
8
|
+
exports.Schema = require('./dist/schema').Schema
|
|
9
|
+
exports.YAMLMap = require('./dist/schema/Map').YAMLMap
|
|
10
|
+
exports.YAMLSeq = require('./dist/schema/Seq').YAMLSeq
|
|
11
|
+
exports.Pair = require('./dist/schema/Pair').Pair
|
|
12
|
+
exports.Scalar = require('./dist/schema/Scalar').Scalar
|
package/types.mjs
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import opt from './dist/tags/options.js'
|
|
2
2
|
export const binaryOptions = opt.binaryOptions
|
|
3
3
|
export const boolOptions = opt.boolOptions
|
|
4
|
+
export const intOptions = opt.intOptions
|
|
4
5
|
export const nullOptions = opt.nullOptions
|
|
5
6
|
export const strOptions = opt.strOptions
|
|
6
7
|
|
|
7
8
|
import schema from './dist/schema/index.js'
|
|
8
|
-
export const Schema = schema.
|
|
9
|
+
export const Schema = schema.Schema
|
|
9
10
|
|
|
10
11
|
import map from './dist/schema/Map.js'
|
|
11
|
-
export const YAMLMap = map.
|
|
12
|
+
export const YAMLMap = map.YAMLMap
|
|
12
13
|
|
|
13
14
|
import seq from './dist/schema/Seq.js'
|
|
14
|
-
export const YAMLSeq = seq.
|
|
15
|
+
export const YAMLSeq = seq.YAMLSeq
|
|
15
16
|
|
|
16
17
|
import pair from './dist/schema/Pair.js'
|
|
17
|
-
export const Pair = pair.
|
|
18
|
+
export const Pair = pair.Pair
|
|
18
19
|
|
|
19
20
|
import scalar from './dist/schema/Scalar.js'
|
|
20
|
-
export const Scalar = scalar.
|
|
21
|
+
export const Scalar = scalar.Scalar
|
package/util.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Document } from './index'
|
|
2
|
+
import { CST } from './parse-cst'
|
|
3
|
+
import { AST, Pair, Scalar, Schema } from './types'
|
|
4
|
+
|
|
5
|
+
export function findPair(items: any[], key: Scalar | any): Pair | undefined
|
|
6
|
+
|
|
7
|
+
export function parseMap(doc: Document, cst: CST.Map): AST.BlockMap
|
|
8
|
+
export function parseMap(doc: Document, cst: CST.FlowMap): AST.FlowMap
|
|
9
|
+
export function parseSeq(doc: Document, cst: CST.Seq): AST.BlockSeq
|
|
10
|
+
export function parseSeq(doc: Document, cst: CST.FlowSeq): AST.FlowSeq
|
|
11
|
+
|
|
12
|
+
export function stringifyNumber(item: Scalar): string
|
|
13
|
+
export function stringifyString(
|
|
14
|
+
item: Scalar,
|
|
15
|
+
ctx: Schema.StringifyContext,
|
|
16
|
+
onComment?: () => void,
|
|
17
|
+
onChompKeep?: () => void
|
|
18
|
+
): string
|
|
19
|
+
|
|
20
|
+
export function toJSON(
|
|
21
|
+
value: any,
|
|
22
|
+
arg?: any,
|
|
23
|
+
ctx?: Schema.CreateNodeContext
|
|
24
|
+
): any
|
|
25
|
+
|
|
26
|
+
export enum Type {
|
|
27
|
+
ALIAS = 'ALIAS',
|
|
28
|
+
BLANK_LINE = 'BLANK_LINE',
|
|
29
|
+
BLOCK_FOLDED = 'BLOCK_FOLDED',
|
|
30
|
+
BLOCK_LITERAL = 'BLOCK_LITERAL',
|
|
31
|
+
COMMENT = 'COMMENT',
|
|
32
|
+
DIRECTIVE = 'DIRECTIVE',
|
|
33
|
+
DOCUMENT = 'DOCUMENT',
|
|
34
|
+
FLOW_MAP = 'FLOW_MAP',
|
|
35
|
+
FLOW_SEQ = 'FLOW_SEQ',
|
|
36
|
+
MAP = 'MAP',
|
|
37
|
+
MAP_KEY = 'MAP_KEY',
|
|
38
|
+
MAP_VALUE = 'MAP_VALUE',
|
|
39
|
+
PLAIN = 'PLAIN',
|
|
40
|
+
QUOTE_DOUBLE = 'QUOTE_DOUBLE',
|
|
41
|
+
QUOTE_SINGLE = 'QUOTE_SINGLE',
|
|
42
|
+
SEQ = 'SEQ',
|
|
43
|
+
SEQ_ITEM = 'SEQ_ITEM'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface LinePos {
|
|
47
|
+
line: number
|
|
48
|
+
col: number
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export class YAMLError extends Error {
|
|
52
|
+
name:
|
|
53
|
+
| 'YAMLReferenceError'
|
|
54
|
+
| 'YAMLSemanticError'
|
|
55
|
+
| 'YAMLSyntaxError'
|
|
56
|
+
| 'YAMLWarning'
|
|
57
|
+
message: string
|
|
58
|
+
source?: CST.Node
|
|
59
|
+
|
|
60
|
+
nodeType?: Type
|
|
61
|
+
range?: CST.Range
|
|
62
|
+
linePos?: { start: LinePos; end: LinePos }
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Drops `source` and adds `nodeType`, `range` and `linePos`, as well as
|
|
66
|
+
* adding details to `message`. Run automatically for document errors if
|
|
67
|
+
* the `prettyErrors` option is set.
|
|
68
|
+
*/
|
|
69
|
+
makePretty(): void
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export class YAMLReferenceError extends YAMLError {
|
|
73
|
+
name: 'YAMLReferenceError'
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export class YAMLSemanticError extends YAMLError {
|
|
77
|
+
name: 'YAMLSemanticError'
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export class YAMLSyntaxError extends YAMLError {
|
|
81
|
+
name: 'YAMLSyntaxError'
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export class YAMLWarning extends YAMLError {
|
|
85
|
+
name: 'YAMLWarning'
|
|
86
|
+
}
|
package/util.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
exports.findPair = require('./dist/schema/Map').findPair
|
|
2
|
-
exports.parseMap = require('./dist/schema/parseMap').
|
|
3
|
-
exports.parseSeq = require('./dist/schema/parseSeq').
|
|
2
|
+
exports.parseMap = require('./dist/schema/parseMap').parseMap
|
|
3
|
+
exports.parseSeq = require('./dist/schema/parseSeq').parseSeq
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const str = require('./dist/stringify')
|
|
6
6
|
exports.stringifyNumber = str.stringifyNumber
|
|
7
7
|
exports.stringifyString = str.stringifyString
|
|
8
|
-
exports.toJSON = require('./dist/toJSON').
|
|
8
|
+
exports.toJSON = require('./dist/toJSON').toJSON
|
|
9
9
|
exports.Type = require('./dist/constants').Type
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
const err = require('./dist/errors')
|
|
12
|
+
exports.YAMLError = err.YAMLError
|
|
12
13
|
exports.YAMLReferenceError = err.YAMLReferenceError
|
|
13
14
|
exports.YAMLSemanticError = err.YAMLSemanticError
|
|
14
15
|
exports.YAMLSyntaxError = err.YAMLSyntaxError
|
package/util.mjs
CHANGED
|
@@ -2,22 +2,23 @@ import map from './dist/schema/Map.js'
|
|
|
2
2
|
export const findPair = map.findPair
|
|
3
3
|
|
|
4
4
|
import parseMapPkg from './dist/schema/parseMap.js'
|
|
5
|
-
export const parseMap = parseMapPkg.
|
|
5
|
+
export const parseMap = parseMapPkg.parseMap
|
|
6
6
|
|
|
7
7
|
import parseSeqPkg from './dist/schema/parseSeq.js'
|
|
8
|
-
export const parseSeq = parseSeqPkg.
|
|
8
|
+
export const parseSeq = parseSeqPkg.parseSeq
|
|
9
9
|
|
|
10
10
|
import str from './dist/stringify.js'
|
|
11
11
|
export const stringifyNumber = str.stringifyNumber
|
|
12
12
|
export const stringifyString = str.stringifyString
|
|
13
13
|
|
|
14
14
|
import toJsonPkg from './dist/toJSON.js'
|
|
15
|
-
export const toJSON = toJsonPkg.
|
|
15
|
+
export const toJSON = toJsonPkg.toJSON
|
|
16
16
|
|
|
17
17
|
import constants from './dist/constants.js'
|
|
18
18
|
export const Type = constants.Type
|
|
19
19
|
|
|
20
20
|
import err from './dist/errors.js'
|
|
21
|
+
export const YAMLError = err.YAMLError
|
|
21
22
|
export const YAMLReferenceError = err.YAMLReferenceError
|
|
22
23
|
export const YAMLSemanticError = err.YAMLSemanticError
|
|
23
24
|
export const YAMLSyntaxError = err.YAMLSyntaxError
|