Nenhuma Descrição

YAMLMap.d.ts 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import type { BlockMap, FlowCollection } from '../parse/cst.js';
  2. import type { Schema } from '../schema/Schema.js';
  3. import type { StringifyContext } from '../stringify/stringify.js';
  4. import { Collection } from './Collection.js';
  5. import { ParsedNode, Range } from './Node.js';
  6. import { Pair } from './Pair.js';
  7. import { Scalar } from './Scalar.js';
  8. import type { ToJSContext } from './toJS.js';
  9. export type MapLike = Map<unknown, unknown> | Set<unknown> | Record<string | number | symbol, unknown>;
  10. export declare function findPair<K = unknown, V = unknown>(items: Iterable<Pair<K, V>>, key: unknown): Pair<K, V> | undefined;
  11. export declare namespace YAMLMap {
  12. interface Parsed<K extends ParsedNode = ParsedNode, V extends ParsedNode | null = ParsedNode | null> extends YAMLMap<K, V> {
  13. items: Pair<K, V>[];
  14. range: Range;
  15. srcToken?: BlockMap | FlowCollection;
  16. }
  17. }
  18. export declare class YAMLMap<K = unknown, V = unknown> extends Collection {
  19. static get tagName(): 'tag:yaml.org,2002:map';
  20. items: Pair<K, V>[];
  21. constructor(schema?: Schema);
  22. /**
  23. * Adds a value to the collection.
  24. *
  25. * @param overwrite - If not set `true`, using a key that is already in the
  26. * collection will throw. Otherwise, overwrites the previous value.
  27. */
  28. add(pair: Pair<K, V> | {
  29. key: K;
  30. value: V;
  31. }, overwrite?: boolean): void;
  32. delete(key: unknown): boolean;
  33. get(key: unknown, keepScalar: true): Scalar<V> | undefined;
  34. get(key: unknown, keepScalar?: false): V | undefined;
  35. get(key: unknown, keepScalar?: boolean): V | Scalar<V> | undefined;
  36. has(key: unknown): boolean;
  37. set(key: K, value: V): void;
  38. /**
  39. * @param ctx - Conversion context, originally set in Document#toJS()
  40. * @param {Class} Type - If set, forces the returned collection type
  41. * @returns Instance of Type, Map, or Object
  42. */
  43. toJSON<T extends MapLike = Map<unknown, unknown>>(_?: unknown, ctx?: ToJSContext, Type?: {
  44. new (): T;
  45. }): any;
  46. toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
  47. }