Skip to content

Instantly share code, notes, and snippets.

View mario-subo's full-sized avatar

Mario Subotic mario-subo

View GitHub Profile
@mario-subo
mario-subo / localStorage.ts
Last active July 5, 2022 16:26
simple JS local storage utility
export const setLocalStorage = (key: string, value: any) => {
if (typeof key !== "string") {
throw new Error(`Error in localStorage: key ${key} must be of type string but is ${typeof key}`);
}
const typeOfValue = typeof value;
console.log(`localStorage: about to save value of type ${typeOfValue} for key ${key}`);
let valueToStore;
switch (typeOfValue) {
case "string":