From 7e80eca50e7c13dfa9e38d3f45bc03fc2591e883 Mon Sep 17 00:00:00 2001 From: Yasser Lahbibi Date: Mon, 6 Feb 2023 17:32:14 +0100 Subject: [PATCH] fix: allow stringify array (#147) --- src/_utils.ts | 2 +- test/storage.test.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/_utils.ts b/src/_utils.ts index a9c3c9a4..9bba95b0 100644 --- a/src/_utils.ts +++ b/src/_utils.ts @@ -35,7 +35,7 @@ export function stringify(value: any): string { return String(value); } - if (isPureObject(value)) { + if (isPureObject(value) || Array.isArray(value)) { return JSON.stringify(value); } diff --git a/test/storage.test.ts b/test/storage.test.ts index f83bd0f6..3e129d1a 100644 --- a/test/storage.test.ts +++ b/test/storage.test.ts @@ -109,4 +109,9 @@ describe("utils", () => { // Get keys from sub-storage expect(await mntStorage.getKeys("foo")).toStrictEqual(["foo:x", "foo:y"]); }); + + it("stringify", () => { + const storage = createStorage(); + expect(async () => await storage.setItem("foo", [])).not.toThrow(); + }); });