From 70fc2436dad8d4896ed63934fa1849a5cbdbf69f Mon Sep 17 00:00:00 2001 From: Dmitry Sharabin Date: Wed, 3 Dec 2025 14:06:07 +0100 Subject: [PATCH] Correctly stringify `undefined` and `null` --- src/objects.js | 2 +- tests/stringify.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/objects.js b/src/objects.js index 9047194..be0d70e 100644 --- a/src/objects.js +++ b/src/objects.js @@ -234,7 +234,7 @@ export function stringify (obj, options = {}) { switch (obj) { case undefined: case null: - return obj; + return obj + ""; } switch (typeof obj) { diff --git a/tests/stringify.js b/tests/stringify.js index 8c5e682..36be78e 100644 --- a/tests/stringify.js +++ b/tests/stringify.js @@ -3,6 +3,8 @@ import { stringify } from "../src/util.js"; export default { run: stringify, tests: [ + { arg: undefined, expect: "undefined" }, + { arg: null, expect: "null" }, { arg: 1, expect: "1" }, { arg: NaN, expect: "NaN" }, { arg: "foo", expect: '"foo"' },