UNPKG

2.56 kBTypeScriptView Raw
1import type { Document } from '../doc/Document.js';
2import type { ToJSOptions } from '../options.js';
3import { Token } from '../parse/cst.js';
4import type { StringifyContext } from '../stringify/stringify.js';
5import type { Alias } from './Alias.js';
6import { NODE_TYPE } from './identity.js';
7import type { Scalar } from './Scalar.js';
8import { ToJSContext } from './toJS.js';
9import type { MapLike, YAMLMap } from './YAMLMap.js';
10import type { YAMLSeq } from './YAMLSeq.js';
11export type Node<T = unknown> = Alias | Scalar<T> | YAMLMap<unknown, T> | YAMLSeq<T>;
12/** Utility type mapper */
13export type NodeType<T> = T extends string | number | bigint | boolean | null | undefined ? Scalar<T> : T extends Date ? Scalar<string | Date> : T extends Array<any> ? YAMLSeq<NodeType<T[number]>> : T extends {
14 [key: string]: any;
15} ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : T extends {
16 [key: number]: any;
17} ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : Node;
18export type ParsedNode = Alias.Parsed | Scalar.Parsed | YAMLMap.Parsed | YAMLSeq.Parsed;
19/** `[start, value-end, node-end]` */
20export type Range = [number, number, number];
21export declare abstract class NodeBase {
22 readonly [NODE_TYPE]: symbol;
23 /** A comment on or immediately after this */
24 comment?: string | null;
25 /** A comment before this */
26 commentBefore?: string | null;
27 /**
28 * The `[start, value-end, node-end]` character offsets for the part of the
29 * source parsed into this node (undefined if not parsed). The `value-end`
30 * and `node-end` positions are themselves not included in their respective
31 * ranges.
32 */
33 range?: Range | null;
34 /** A blank line before this node and its commentBefore */
35 spaceBefore?: boolean;
36 /** The CST token that was composed into this node. */
37 srcToken?: Token;
38 /** A fully qualified tag, if required */
39 tag?: string;
40 /**
41 * Customize the way that a key-value pair is resolved.
42 * Used for YAML 1.1 !!merge << handling.
43 */
44 addToJSMap?: (ctx: ToJSContext | undefined, map: MapLike, value: unknown) => void;
45 /** A plain JS representation of this node */
46 abstract toJSON(): any;
47 abstract toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
48 constructor(type: symbol);
49 /** Create a copy of this node. */
50 clone(): NodeBase;
51 /** A plain JavaScript representation of this node. */
52 toJS(doc: Document<Node, boolean>, { mapAsMap, maxAliasCount, onAnchor, reviver }?: ToJSOptions): any;
53}