Fix handling of 'undefined' in YAML
This commit is contained in:
1 parent
a60a212a10
commit
51e160560c
1 file changed
+8
-3
+8
-3
@@ -116,8 +116,12 @@ function stringifyAny(
|
|||||||
prefix1 = "",
|
prefix1 = "",
|
||||||
prefix2 = ""
|
prefix2 = ""
|
||||||
): void {
|
): void {
|
||||||
if (obj == null || typeof obj === "number" || typeof obj === "boolean") {
|
if (obj == null) {
|
||||||
res.push(`${prefix1}${obj}`);
|
res.push(`${prefix1}null`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (typeof obj === "number" || typeof obj === "boolean") {
|
||||||
|
res.push(`${prefix1}${JSON.stringify(obj)}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (obj instanceof Date) {
|
if (obj instanceof Date) {
|
||||||
@@ -152,7 +156,7 @@ function stringifyAny(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const entries = Object.entries(obj);
|
const entries = Object.entries(obj).filter((e) => e[1] !== undefined);
|
||||||
|
|
||||||
if (!entries.length) {
|
if (!entries.length) {
|
||||||
res.push(prefix1 + "{}");
|
res.push(prefix1 + "{}");
|
||||||
@@ -192,6 +196,7 @@ function stringifyAny(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function stringify(obj: unknown): string {
|
export function stringify(obj: unknown): string {
|
||||||
|
if (obj === undefined) return undefined;
|
||||||
const lines: string[] = [];
|
const lines: string[] = [];
|
||||||
stringifyAny(obj, lines);
|
stringifyAny(obj, lines);
|
||||||
return lines.join("\n") + "\n";
|
return lines.join("\n") + "\n";
|
||||||
|
|||||||
Reference in new issue
Block a user