879144419689de707ed7384856e2277747ee941e1aed6594cc42e4857a938f00a526b1eff10f80ca8c927d5052d643694e92b3087085fa114c62e9d60eb65c 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { F as FormatOptions } from './shared/confbox.9745c98f.mjs';
  2. /**
  3. * Converts a [YAML](https://yaml.org/) string into an object.
  4. *
  5. * @NOTE This function does **not** understand multi-document sources, it throws exception on those.
  6. *
  7. * @NOTE Comments are not preserved after parsing.
  8. *
  9. * @NOTE This function does **not** support schema-specific tag resolution restrictions.
  10. * So, the JSON schema is not as strictly defined in the YAML specification.
  11. * It allows numbers in any notation, use `Null` and `NULL` as `null`, etc.
  12. * The core schema also has no such restrictions. It allows binary notation for integers.
  13. *
  14. * @template T The type of the return value.
  15. * @param text The YAML string to parse.
  16. * @param options Parsing options.
  17. * @returns The JavaScript value converted from the YAML string.
  18. */
  19. declare function parseYAML<T = unknown>(text: string, options?: YAMLParseOptions): T;
  20. /**
  21. * Converts a JavaScript value to a [YAML](https://yaml.org/) string.
  22. *
  23. * @NOTE Comments are not preserved in the output.
  24. *
  25. * @param value
  26. * @param options
  27. * @returns The YAML string converted from the JavaScript value.
  28. */
  29. declare function stringifyYAML(value: any, options?: YAMLStringifyOptions): string;
  30. interface YAMLParseOptions extends FormatOptions {
  31. /** string to be used as a file path in error/warning messages. */
  32. filename?: string | undefined;
  33. /** function to call on warning messages. */
  34. onWarning?(this: null, e: YAMLException): void;
  35. /** specifies a schema to use. */
  36. schema?: any | undefined;
  37. /** compatibility with JSON.parse behaviour. */
  38. json?: boolean | undefined;
  39. /** listener for parse events */
  40. listener?(this: any, eventType: any, state: any): void;
  41. }
  42. interface YAMLStringifyOptions extends FormatOptions {
  43. /** indentation width to use (in spaces). */
  44. indent?: number | undefined;
  45. /** when true, will not add an indentation level to array elements */
  46. noArrayIndent?: boolean | undefined;
  47. /** do not throw on invalid types (like function in the safe schema) and skip pairs and single values with such types. */
  48. skipInvalid?: boolean | undefined;
  49. /** specifies level of nesting, when to switch from block to flow style for collections. -1 means block style everwhere */
  50. flowLevel?: number | undefined;
  51. /** Each tag may have own set of styles. - "tag" => "style" map. */
  52. styles?: {
  53. [x: string]: any;
  54. } | undefined;
  55. /** specifies a schema to use. */
  56. schema?: any | undefined;
  57. /** if true, sort keys when dumping YAML. If a function, use the function to sort the keys. (default: false) */
  58. sortKeys?: boolean | ((a: any, b: any) => number) | undefined;
  59. /** set max line width. (default: 80) */
  60. lineWidth?: number | undefined;
  61. /** if true, don't convert duplicate objects into references (default: false) */
  62. noRefs?: boolean | undefined;
  63. /** if true don't try to be compatible with older yaml versions. Currently: don't quote "yes", "no" and so on, as required for YAML 1.1 (default: false) */
  64. noCompatMode?: boolean | undefined;
  65. /**
  66. * if true flow sequences will be condensed, omitting the space between `key: value` or `a, b`. Eg. `'[a,b]'` or `{a:{b:c}}`.
  67. * Can be useful when using yaml for pretty URL query params as spaces are %-encoded. (default: false).
  68. */
  69. condenseFlow?: boolean | undefined;
  70. /** strings will be quoted using this quoting style. If you specify single quotes, double quotes will still be used for non-printable characters. (default: `'`) */
  71. quotingType?: "'" | '"' | undefined;
  72. /** if true, all non-key strings will be quoted even if they normally don't need to. (default: false) */
  73. forceQuotes?: boolean | undefined;
  74. /** callback `function (key, value)` called recursively on each key/value in source object (see `replacer` docs for `JSON.stringify`). */
  75. replacer?: ((key: string, value: any) => any) | undefined;
  76. }
  77. interface Mark {
  78. buffer: string;
  79. column: number;
  80. line: number;
  81. name: string;
  82. position: number;
  83. snippet: string;
  84. }
  85. declare class YAMLException extends Error {
  86. constructor(reason?: string, mark?: Mark);
  87. toString(compact?: boolean): string;
  88. name: string;
  89. reason: string;
  90. message: string;
  91. mark: Mark;
  92. }
  93. export { type YAMLParseOptions, type YAMLStringifyOptions, parseYAML, stringifyYAML };