UNPKG

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