1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 |
/**
* {@linkcode parse} and {@linkcode stringify} for handling
* {@link https://yaml.org/ | YAML} encoded data.
*
* Ported from
* {@link https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da | js-yaml v3.13.1}.
*
* Use {@linkcode parseAll} for parsing multiple documents in a single YAML
* string.
*
* This package generally supports
* {@link https://yaml.org/spec/1.2.2/ | YAML 1.2.x} (latest) and some
* {@link https://yaml.org/spec/1.1/current.html | YAML 1.1} features that are
* commonly used in the wild.
*
* Supported YAML 1.1 features include:
* - {@link https://yaml.org/type/merge.html | Merge} type (`<<` symbol)
*
* Unsupported YAML 1.1 features include:
* - Yes, No, On, Off literals for bool type
* - Sexagesimal numbers (e.g. `3:25:45`)
*
* ```ts
* import { parse, stringify } from "@std/yaml";
* import { assertEquals } from "@std/assert";
*
* const data = parse(`
* foo: bar
* baz:
* - qux
* - quux
* `);
* assertEquals(data, { foo: "bar", baz: [ "qux", "quux" ] });
*
* const yaml = stringify({ foo: "bar", baz: ["qux", "quux"] });
* assertEquals(yaml, `foo: bar
* baz:
* - qux
* - quux
* `);
* ```
*
* ## Limitations
* - `binary` type is currently not stable.
*
* @module
*/
import type { SchemaType as _typeAlias_SchemaType } from "jsr:@std/[email protected]"
/**
* Name of the schema to use.
*
* > [!NOTE]
* > It is recommended to use the schema that is most appropriate for your use
* > case. Doing so will avoid any unnecessary processing and benefit
* > performance.
*
* Options include:
* - `failsafe`: supports generic mappings, generic sequences and generic
* strings.
* - `json`: extends `failsafe` schema by also supporting nulls, booleans,
* integers and floats.
* - `core`: functionally the same as `json` schema.
* - `default`: extends `core` schema by also supporting binary, omap, pairs and
* set types.
* - `extended`: extends `default` schema by also supporting regular
* expressions and undefined values.
*
* See
* {@link https://yaml.org/spec/1.2.2/#chapter-10-recommended-schemas | YAML 1.2 spec}
* for more details on the `failsafe`, `json` and `core` schemas.
*/
type SchemaType = _typeAlias_SchemaType
export type { SchemaType }
import type { ParseOptions as _interface_ParseOptions } from "jsr:@std/[email protected]"
/**
* Options for {@linkcode parse}.
*/
interface ParseOptions extends _interface_ParseOptions {}
export type { ParseOptions }
import { parse as _function_parse } from "jsr:@std/[email protected]"
/**
* Parse and return a YAML string as a parsed YAML document object.
*
* Note: This does not support functions. Untrusted data is safe to parse.
*
* @example Usage
* ```ts
* import { parse } from "@std/yaml/parse";
* import { assertEquals } from "@std/assert";
*
* const data = parse(`
* id: 1
* name: Alice
* `);
*
* assertEquals(data, { id: 1, name: "Alice" });
* ```
*
* @throws Throws error on invalid YAML.
* @param content YAML string to parse.
* @param options Parsing options.
* @return Parsed document.
*/
const parse = _function_parse as typeof _function_parse
export { parse }
import { parseAll as _function_parseAll } from "jsr:@std/[email protected]"
/**
* Same as {@linkcode parse}, but understands multi-document YAML sources, and
* returns multiple parsed YAML document objects.
*
* @example Usage
* ```ts
* import { parseAll } from "@std/yaml/parse";
* import { assertEquals } from "@std/assert";
*
* const data = parseAll(`
* ---
* id: 1
* name: Alice
* ---
* id: 2
* name: Bob
* ---
* id: 3
* name: Eve
* `);
* assertEquals(data, [ { id: 1, name: "Alice" }, { id: 2, name: "Bob" }, { id: 3, name: "Eve" }]);
* ```
*
* @param content YAML string to parse.
* @param options Parsing options.
* @return Array of parsed documents.
*/
const parseAll = _function_parseAll as typeof _function_parseAll
export { parseAll }
import type { StyleVariant as _typeAlias_StyleVariant } from "jsr:@std/[email protected]"
/**
* The style variation for `styles` option of {@linkcode stringify}
*/
type StyleVariant = _typeAlias_StyleVariant
export type { StyleVariant }
import type { StringifyOptions as _typeAlias_StringifyOptions } from "jsr:@std/[email protected]"
/**
* Options for {@linkcode stringify}.
*/
type StringifyOptions = _typeAlias_StringifyOptions
export type { StringifyOptions }
import { stringify as _function_stringify } from "jsr:@std/[email protected]"
/**
* Converts a JavaScript object or value to a YAML document string.
*
* @example Usage
* ```ts
* import { stringify } from "@std/yaml/stringify";
* import { assertEquals } from "@std/assert";
*
* const data = { id: 1, name: "Alice" };
* const yaml = stringify(data);
*
* assertEquals(yaml, "id: 1\nname: Alice\n");
* ```
*
* @throws If `data` contains invalid types.
* @param data The data to serialize.
* @param options The options for serialization.
* @return A YAML string.
*/
const stringify = _function_stringify as typeof _function_stringify
export { stringify }
|