Açıklama Yok

Node.d.ts 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import type { Document } from '../doc/Document.js';
  2. import { Token } from '../parse/cst.js';
  3. import type { StringifyContext } from '../stringify/stringify.js';
  4. import type { Alias } from './Alias.js';
  5. import type { Pair } from './Pair.js';
  6. import type { Scalar } from './Scalar.js';
  7. import type { YAMLMap } from './YAMLMap.js';
  8. import type { YAMLSeq } from './YAMLSeq.js';
  9. export type Node<T = unknown> = Alias | Scalar<T> | YAMLMap<unknown, T> | YAMLSeq<T>;
  10. /** Utility type mapper */
  11. export type NodeType<T> = T extends string | number | bigint | boolean | null ? Scalar<T> : T extends Array<any> ? YAMLSeq<NodeType<T[number]>> : T extends {
  12. [key: string]: any;
  13. } ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : T extends {
  14. [key: number]: any;
  15. } ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : Node;
  16. export type ParsedNode = Alias.Parsed | Scalar.Parsed | YAMLMap.Parsed | YAMLSeq.Parsed;
  17. export type Range = [number, number, number];
  18. export declare const ALIAS: unique symbol;
  19. export declare const DOC: unique symbol;
  20. export declare const MAP: unique symbol;
  21. export declare const PAIR: unique symbol;
  22. export declare const SCALAR: unique symbol;
  23. export declare const SEQ: unique symbol;
  24. export declare const NODE_TYPE: unique symbol;
  25. export declare const isAlias: (node: any) => node is Alias;
  26. export declare const isDocument: <T extends Node<unknown> = Node<unknown>>(node: any) => node is Document<T>;
  27. export declare const isMap: <K = unknown, V = unknown>(node: any) => node is YAMLMap<K, V>;
  28. export declare const isPair: <K = unknown, V = unknown>(node: any) => node is Pair<K, V>;
  29. export declare const isScalar: <T = unknown>(node: any) => node is Scalar<T>;
  30. export declare const isSeq: <T = unknown>(node: any) => node is YAMLSeq<T>;
  31. export declare function isCollection<K = unknown, V = unknown>(node: any): node is YAMLMap<K, V> | YAMLSeq<V>;
  32. export declare function isNode<T = unknown>(node: any): node is Node<T>;
  33. export declare const hasAnchor: <K = unknown, V = unknown>(node: unknown) => node is Scalar<V> | YAMLMap<K, V> | YAMLSeq<V>;
  34. export declare abstract class NodeBase {
  35. readonly [NODE_TYPE]: symbol;
  36. /** A comment on or immediately after this */
  37. comment?: string | null;
  38. /** A comment before this */
  39. commentBefore?: string | null;
  40. /**
  41. * The `[start, value-end, node-end]` character offsets for the part of the
  42. * source parsed into this node (undefined if not parsed). The `value-end`
  43. * and `node-end` positions are themselves not included in their respective
  44. * ranges.
  45. */
  46. range?: Range | null;
  47. /** A blank line before this node and its commentBefore */
  48. spaceBefore?: boolean;
  49. /** The CST token that was composed into this node. */
  50. srcToken?: Token;
  51. /** A fully qualified tag, if required */
  52. tag?: string;
  53. /** A plain JS representation of this node */
  54. abstract toJSON(): any;
  55. abstract toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
  56. constructor(type: symbol);
  57. /** Create a copy of this node. */
  58. clone(): NodeBase;
  59. }