UNPKG

@sky-mavis/tanto-connect

Version:
34 lines 1.26 kB
const STORAGE_PREFIX = 'tanto'; const LocalStorage = { isAccessible: () => typeof localStorage !== 'undefined', set: (key, data) => { if (!LocalStorage.isAccessible()) { return false; } localStorage.setItem(key, JSON.stringify(data)); return true; }, get: (key) => { if (!LocalStorage.isAccessible()) { return undefined; } const data = localStorage.getItem(key); if (data) { return JSON.parse(data); } return undefined; }, remove: (key) => { if (!LocalStorage.isAccessible()) { return false; } localStorage.removeItem(key); return true; }, }; const ReconnectStorage = { get: (connectorId) => LocalStorage.get(`${STORAGE_PREFIX}.RECONNECT.${connectorId}`) ?? false, add: (connectorId) => LocalStorage.set(`${STORAGE_PREFIX}.RECONNECT.${connectorId}`, true), remove: (connectorId) => LocalStorage.remove(`${STORAGE_PREFIX}.RECONNECT.${connectorId}`), }; const WAYPOINT_ACCESS_TOKEN_STORAGE_KEY = `${STORAGE_PREFIX}.WAYPOINT.ACCESS_TOKEN`;export{LocalStorage,ReconnectStorage,STORAGE_PREFIX,WAYPOINT_ACCESS_TOKEN_STORAGE_KEY};