From 64de5c9ae089881226e63e87a3d6e7599e2ad7fa Mon Sep 17 00:00:00 2001 From: Haydn Ewers <27211+haydn@users.noreply.github.com> Date: Wed, 1 Sep 2021 22:33:31 +1000 Subject: [PATCH] Make persistence classes node compatible --- index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.ts b/index.ts index f955769..af9b15b 100644 --- a/index.ts +++ b/index.ts @@ -552,7 +552,7 @@ class LocalStoragePersistence implements Persistence { } load(): Array | null { - const value = window.localStorage.getItem(this.key); + const value = typeof window === "object" ? window.localStorage.getItem(this.key) : null; return value ? JSON.parse(value) : null; } @@ -564,11 +564,11 @@ class LocalStoragePersistence implements Persistence { class UrlPersistence implements Persistence { load(): Array | null { let persistedRecords = null; - const hash = window.location.hash.slice(1).trim(); + const hash = typeof window === "object" ? window.location.hash.slice(1).trim() : null; - if (hash.length > 0) { + if (hash && hash.length > 0) { try { - persistedRecords = JSON.parse(fromBase64(hash)) as unknown; + persistedRecords = JSON.parse(fromBase64(hash)); } catch (error) { console.log(error); } -- 2.51.2