UNPKG

@tldraw/utils

Version:

tldraw infinite canvas SDK (private utilities).

8 lines (7 loc) 3.13 kB
{ "version": 3, "sources": ["../../src/lib/storage.tsx"], "sourcesContent": ["/* eslint-disable no-restricted-syntax */\n\n/**\n * Get a value from local storage.\n *\n * @param key - The key to get.\n *\n * @internal\n */\nexport function getFromLocalStorage(key: string) {\n\ttry {\n\t\treturn localStorage.getItem(key)\n\t} catch {\n\t\treturn null\n\t}\n}\n\n/**\n * Set a value in local storage. Will not throw an error if localStorage is not available.\n *\n * @param key - The key to set.\n * @param value - The value to set.\n *\n * @internal\n */\nexport function setInLocalStorage(key: string, value: string) {\n\ttry {\n\t\tlocalStorage.setItem(key, value)\n\t} catch {\n\t\t// noop\n\t}\n}\n\n/**\n * Remove a value from local storage. Will not throw an error if localStorage is not available.\n *\n * @param key - The key to set.\n *\n * @internal\n */\nexport function deleteFromLocalStorage(key: string) {\n\ttry {\n\t\tlocalStorage.removeItem(key)\n\t} catch {\n\t\t// noop\n\t}\n}\n\n/**\n * Clear all values from local storage. Will not throw an error if localStorage is not available.\n *\n * @internal\n */\nexport function clearLocalStorage() {\n\ttry {\n\t\tlocalStorage.clear()\n\t} catch {\n\t\t// noop\n\t}\n}\n\n/**\n * Get a value from session storage.\n *\n * @param key - The key to get.\n *\n * @internal\n */\nexport function getFromSessionStorage(key: string) {\n\ttry {\n\t\treturn sessionStorage.getItem(key)\n\t} catch {\n\t\treturn null\n\t}\n}\n\n/**\n * Set a value in session storage. Will not throw an error if sessionStorage is not available.\n *\n * @param key - The key to set.\n * @param value - The value to set.\n *\n * @internal\n */\nexport function setInSessionStorage(key: string, value: string) {\n\ttry {\n\t\tsessionStorage.setItem(key, value)\n\t} catch {\n\t\t// noop\n\t}\n}\n\n/**\n * Remove a value from session storage. Will not throw an error if sessionStorage is not available.\n *\n * @param key - The key to set.\n *\n * @internal\n */\nexport function deleteFromSessionStorage(key: string) {\n\ttry {\n\t\tsessionStorage.removeItem(key)\n\t} catch {\n\t\t// noop\n\t}\n}\n\n/**\n * Clear all values from session storage. Will not throw an error if sessionStorage is not available.\n *\n * @internal\n */\nexport function clearSessionStorage() {\n\ttry {\n\t\tsessionStorage.clear()\n\t} catch {\n\t\t// noop\n\t}\n}\n"], "mappings": "AASO,SAAS,oBAAoB,KAAa;AAChD,MAAI;AACH,WAAO,aAAa,QAAQ,GAAG;AAAA,EAChC,QAAQ;AACP,WAAO;AAAA,EACR;AACD;AAUO,SAAS,kBAAkB,KAAa,OAAe;AAC7D,MAAI;AACH,iBAAa,QAAQ,KAAK,KAAK;AAAA,EAChC,QAAQ;AAAA,EAER;AACD;AASO,SAAS,uBAAuB,KAAa;AACnD,MAAI;AACH,iBAAa,WAAW,GAAG;AAAA,EAC5B,QAAQ;AAAA,EAER;AACD;AAOO,SAAS,oBAAoB;AACnC,MAAI;AACH,iBAAa,MAAM;AAAA,EACpB,QAAQ;AAAA,EAER;AACD;AASO,SAAS,sBAAsB,KAAa;AAClD,MAAI;AACH,WAAO,eAAe,QAAQ,GAAG;AAAA,EAClC,QAAQ;AACP,WAAO;AAAA,EACR;AACD;AAUO,SAAS,oBAAoB,KAAa,OAAe;AAC/D,MAAI;AACH,mBAAe,QAAQ,KAAK,KAAK;AAAA,EAClC,QAAQ;AAAA,EAER;AACD;AASO,SAAS,yBAAyB,KAAa;AACrD,MAAI;AACH,mBAAe,WAAW,GAAG;AAAA,EAC9B,QAAQ;AAAA,EAER;AACD;AAOO,SAAS,sBAAsB;AACrC,MAAI;AACH,mBAAe,MAAM;AAAA,EACtB,QAAQ;AAAA,EAER;AACD;", "names": [] }