UNPKG

@exromany/lido-csm-sdk

Version:

[![GitHub license](https://img.shields.io/github/license/lidofinance/lido-csm-sdk?color=limegreen)](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [![Version npm](https://img.shields.io/npm/v/@lidofinance/lido-csm-sdk?label=version)](h

44 lines 1.15 kB
export const trySerializeLocalStorageItem = (key, value) => { const item = JSON.stringify(value); try { localStorage.setItem(key, item); } catch (error) { // New value couldn't be set, thus return an error result return { success: false, error: error, }; } // Everything's fine, thus return a success result return { success: true, }; }; export const tryDeserializeLocalStorageItem = (key) => { const item = localStorage.getItem(key); if (item === null) { // The item does not exist, thus return an error result return { success: false, error: new Error(`Item with key "${key}" does not exist`), }; } let value; try { value = JSON.parse(item); } catch (error) { // The item is not valid JSON, thus return an error result return { success: false, error: error, }; } // Everything's fine, thus return a success result return { success: true, value, }; }; //# sourceMappingURL=storage.js.map