-
-
Notifications
You must be signed in to change notification settings - Fork 101
/
Document.d.ts
176 lines (165 loc) · 5.44 KB
/
Document.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import { Alias, Collection, Merge, Node, Pair } from '../ast'
import { StreamDirectives } from '../compose/stream-directives'
import { Type } from '../constants'
import { CST } from '../cst'
import { YAMLError, YAMLWarning } from '../errors'
import { Options } from '../options'
import { Schema } from './Schema'
type Replacer = any[] | ((key: any, value: any) => boolean)
type Reviver = (key: any, value: any) => any
export interface CreateNodeOptions {
/**
* Filter or modify values while creating a node.
*
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter
*/
replacer?: Replacer
/**
* Specify the collection type, e.g. `"!!omap"`. Note that this requires the
* corresponding tag to be available in this document's schema.
*/
tag?: string
/**
* Wrap plain values in `Scalar` objects.
*
* Default: `true`
*/
wrapScalars?: boolean
}
export class Document extends Collection {
cstNode?: CST.Document
/**
* @param value - The initial value for the document, which will be wrapped
* in a Node container.
*/
constructor(value?: any, options?: Options)
constructor(value: any, replacer: null | Replacer, options?: Options)
directives?: StreamDirectives
tag: never
directivesEndMarker?: boolean
type: Type.DOCUMENT
/**
* Anchors associated with the document's nodes;
* also provides alias & merge node creators.
*/
anchors: Document.Anchors
/** The document contents. */
contents: any
/** Errors encountered during parsing. */
errors: YAMLError[]
/**
* The schema used with the document. Use `setSchema()` to change or
* initialise.
*/
options: Required<Options>
schema?: Schema
/**
* Array of prefixes; each will have a string `handle` that
* starts and ends with `!` and a string `prefix` that the handle will be replaced by.
*/
tagPrefixes: Document.TagPrefix[]
/**
* The parsed version of the source document;
* if true-ish, stringified output will include a `%YAML` directive.
*/
version?: string
/** Warnings encountered during parsing. */
warnings: YAMLWarning[]
/**
* Convert any value into a `Node` using the current schema, recursively
* turning objects into collections.
*/
createNode(
value: any,
{ replacer, tag, wrapScalars }?: CreateNodeOptions
): Node
/**
* Convert a key and a value into a `Pair` using the current schema,
* recursively wrapping all values as `Scalar` or `Collection` nodes.
*
* @param options If `wrapScalars` is not `false`, wraps plain values in
* `Scalar` objects.
*/
createPair(key: any, value: any, options?: { wrapScalars?: boolean }): Pair
/** Parse a CST into this document */
parse(cst: CST.Document): this
/**
* When a document is created with `new YAML.Document()`, the schema object is
* not set as it may be influenced by parsed directives; call this with no
* arguments to set it manually, or with arguments to change the schema used
* by the document.
*/
setSchema(
id?: Options['version'] | Schema.Name,
customTags?: (Schema.TagId | Schema.Tag)[]
): void
/** Set `handle` as a shorthand string for the `prefix` tag namespace. */
setTagPrefix(handle: string, prefix: string): void
/**
* A plain JavaScript representation of the document `contents`.
*
* @param mapAsMap - Use Map rather than Object to represent mappings.
* Overrides values set in Document or global options.
* @param onAnchor - If defined, called with the resolved `value` and
* reference `count` for each anchor in the document.
* @param reviver - A function that may filter or modify the output JS value
*/
toJS(opt?: {
mapAsMap?: boolean
onAnchor?: (value: any, count: number) => void
reviver?: Reviver
}): any
/**
* A JSON representation of the document `contents`.
*
* @param arg Used by `JSON.stringify` to indicate the array index or property
* name.
*/
toJSON(arg?: string): any
/** A YAML representation of the document. */
toString(): string
}
export namespace Document {
interface Parsed extends Document {
contents: Node.Parsed | null
directives: StreamDirectives
/** The schema used with the document. */
schema: Schema
}
interface Anchors {
/** @private */
_cstAliases: any[]
/** @private */
map: Record<string, Node | CST.Node>
/**
* Create a new `Alias` node, adding the required anchor for `node`.
* If `name` is empty, a new anchor name will be generated.
*/
createAlias(node: Node, name?: string): Alias
/**
* Create a new `Merge` node with the given source nodes.
* Non-`Alias` sources will be automatically wrapped.
*/
createMergePair(...nodes: Node[]): Merge
/** The anchor name associated with `node`, if set. */
getName(node: Node): undefined | string
/** List of all defined anchor names. */
getNames(): string[]
/** The node associated with the anchor `name`, if set. */
getNode(name: string): undefined | Node
/**
* Find an available anchor name with the given `prefix` and a
* numerical suffix.
*/
newName(prefix: string): string
/**
* Associate an anchor with `node`. If `name` is empty, a new name will be generated.
* To remove an anchor, use `setAnchor(null, name)`.
*/
setAnchor(node: Node | null, name?: string): void | string
}
interface TagPrefix {
handle: string
prefix: string
}
}