Nenhuma Descrição

YAMLSeq.d.ts 2.3KB

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