UNPKG

2.3 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 type { YAMLMap } from './YAMLMap.js';
9import type { YAMLSeq } from './YAMLSeq.js';
10export type Node<T = unknown> = Alias | Scalar<T> | YAMLMap<unknown, T> | YAMLSeq<T>;
11/** Utility type mapper */
12export 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 {
13 [key: string]: any;
14} ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : T extends {
15 [key: number]: any;
16} ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : Node;
17export type ParsedNode = Alias.Parsed | Scalar.Parsed | YAMLMap.Parsed | YAMLSeq.Parsed;
18/** `[start, value-end, node-end]` */
19export type Range = [number, number, number];
20export declare abstract class NodeBase {
21 readonly [NODE_TYPE]: symbol;
22 /** A comment on or immediately after this */
23 comment?: string | null;
24 /** A comment before this */
25 commentBefore?: string | null;
26 /**
27 * The `[start, value-end, node-end]` character offsets for the part of the
28 * source parsed into this node (undefined if not parsed). The `value-end`
29 * and `node-end` positions are themselves not included in their respective
30 * ranges.
31 */
32 range?: Range | null;
33 /** A blank line before this node and its commentBefore */
34 spaceBefore?: boolean;
35 /** The CST token that was composed into this node. */
36 srcToken?: Token;
37 /** A fully qualified tag, if required */
38 tag?: string;
39 /** A plain JS representation of this node */
40 abstract toJSON(): any;
41 abstract toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
42 constructor(type: symbol);
43 /** Create a copy of this node. */
44 clone(): NodeBase;
45 /** A plain JavaScript representation of this node. */
46 toJS(doc: Document<Node, boolean>, { mapAsMap, maxAliasCount, onAnchor, reviver }?: ToJSOptions): any;
47}