UNPKG

2.53 kBTypeScriptView Raw
1import { CreateNodeContext } from '../doc/createNode.js';
2import type { BlockSequence, FlowCollection } from '../parse/cst.js';
3import type { Schema } from '../schema/Schema.js';
4import type { StringifyContext } from '../stringify/stringify.js';
5import { Collection } from './Collection.js';
6import type { ParsedNode, Range } from './Node.js';
7import type { Pair } from './Pair.js';
8import { Scalar } from './Scalar.js';
9import { ToJSContext } from './toJS.js';
10export declare namespace YAMLSeq {
11 interface Parsed<T extends ParsedNode | Pair<ParsedNode, ParsedNode | null> = ParsedNode> extends YAMLSeq<T> {
12 items: T[];
13 range: Range;
14 srcToken?: BlockSequence | FlowCollection;
15 }
16}
17export declare class YAMLSeq<T = unknown> extends Collection {
18 static get tagName(): 'tag:yaml.org,2002:seq';
19 items: T[];
20 constructor(schema?: Schema);
21 add(value: T): void;
22 /**
23 * Removes a value from the collection.
24 *
25 * `key` must contain a representation of an integer for this to succeed.
26 * It may be wrapped in a `Scalar`.
27 *
28 * @returns `true` if the item was found and removed.
29 */
30 delete(key: unknown): boolean;
31 /**
32 * Returns item at `key`, or `undefined` if not found. By default unwraps
33 * scalar values from their surrounding node; to disable set `keepScalar` to
34 * `true` (collections are always returned intact).
35 *
36 * `key` must contain a representation of an integer for this to succeed.
37 * It may be wrapped in a `Scalar`.
38 */
39 get(key: unknown, keepScalar: true): Scalar<T> | undefined;
40 get(key: unknown, keepScalar?: false): T | undefined;
41 get(key: unknown, keepScalar?: boolean): T | Scalar<T> | undefined;
42 /**
43 * Checks if the collection includes a value with the key `key`.
44 *
45 * `key` must contain a representation of an integer for this to succeed.
46 * It may be wrapped in a `Scalar`.
47 */
48 has(key: unknown): boolean;
49 /**
50 * Sets a value in this collection. For `!!set`, `value` needs to be a
51 * boolean to add/remove the item from the set.
52 *
53 * If `key` does not contain a representation of an integer, this will throw.
54 * It may be wrapped in a `Scalar`.
55 */
56 set(key: unknown, value: T): void;
57 toJSON(_?: unknown, ctx?: ToJSContext): unknown[];
58 toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
59 static from(schema: Schema, obj: unknown, ctx: CreateNodeContext): YAMLSeq<unknown>;
60}