UNPKG

@cerberus-design/react

Version:

The Cerberus Design React component library.

1 lines 1.21 kB
{"version":3,"sources":["../../../src/utils/localStorage.ts"],"sourcesContent":["'use client'\n\n/**\n * A utility function to get a value from local storage.\n * @param key The key to get from local storage.\n * @param defaultValue The fallback value if the key is not found.\n * @returns key or defaultValue\n */\nexport function getLocalStorage<T extends string>(\n key: string,\n defaultValue: T,\n): T {\n const value = window.localStorage.getItem(key)\n if (value) {\n return value as T\n }\n return defaultValue\n}\n\n/**\n * A utility function to set a value in local storage.\n * @param key The key to set in local storage.\n * @param value The value to set in local storage.\n */\nexport function setLocalStorage<T>(key: string, value: T): void {\n const stringValue = typeof value === 'string' ? value : JSON.stringify(value)\n window.localStorage.setItem(key, stringValue)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQO,SAAS,gBACd,KACA,cACG;AACH,QAAM,QAAQ,OAAO,aAAa,QAAQ,GAAG;AAC7C,MAAI,OAAO;AACT,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAOO,SAAS,gBAAmB,KAAa,OAAgB;AAC9D,QAAM,cAAc,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,KAAK;AAC5E,SAAO,aAAa,QAAQ,KAAK,WAAW;AAC9C;","names":[]}