Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/yaml.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { load, dump } from "js-yaml";
import { parse, stringify } from "yaml";
import { type FormatOptions, getFormat, storeFormat } from "./_format";

// Source: https://github.com/nodeca/js-yaml
// Types: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/js-yaml/index.d.ts
// https://eemeli.org/yaml/#yaml
// https://github.com/eemeli/yaml

/**
* Converts a [YAML](https://yaml.org/) string into an object.
Expand All @@ -25,7 +25,10 @@ export function parseYAML<T = unknown>(
text: string,
options?: YAMLParseOptions,
): T {
const obj = load(text, options);
const obj = parse(text, {
customTags: ["timestamp"],
...options,
});
storeFormat(text, obj, options);
return obj as T;
}
Expand All @@ -46,7 +49,7 @@ export function stringifyYAML(
const format = getFormat(value, { preserveIndentation: false });
const indentSize =
typeof format.indent === "string" ? format.indent.length : format.indent;
const str = dump(value, {
const str = stringify(value, {
indent: indentSize,
...options,
});
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ types:
- 3
object:
key: value
'null': null
"null": null
date: 1979-05-27T15:32:00.000Z
`;

Expand Down