@structium/yaml - API documentation β
Functions β
deserialize() β
ts
function deserialize<Res>(content: string, options?: LoadOptions): Promise<Res>Deserialize a YAML string into an object.
Type Parameters β
| Type Parameter | Default type | Description |
|---|---|---|
Res extends CommonObj | CommonObj | The expected return type of the deserialized object |
Parameters β
| Parameter | Type | Description |
|---|---|---|
content | string | The YAML content string |
options? | LoadOptions | Options |
Returns β
Promise<Res>
- The deserialized JavaScript object
Throws β
If the input string is not valid YAML
Example β
ts
import { deserialize } from "@structium/yaml"
const yamlContent = `
name: Alice
age: 30
city: New York
`
const obj = await deserialize( yamlContent )
console.log( obj )serialize() β
ts
function serialize(content: object, options?: DumpOptions): Promise<string>Serializes an object into a YAML string.
Parameters β
| Parameter | Type | Description |
|---|---|---|
content | object | The object to serialize. |
options? | DumpOptions | Options |
Returns β
Promise<string>
A promise that resolves to the YAML string representation of the object.
