@uifabric/utilities
Version:
Fluent UI React utilities for building components.
1 lines • 1.53 kB
Source Map (JSON)
{"version":3,"file":"localStorage.js","sourceRoot":"../src/","sources":["localStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,GAAW;IACjC,IAAI,MAAM,GAAG,IAAI,CAAC;IAClB,IAAI;QACF,IAAM,GAAG,GAAG,SAAS,EAAE,CAAC;QACxB,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;KACrD;IAAC,OAAO,CAAC,EAAE;QACV,uBAAuB;KACxB;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,GAAW,EAAE,IAAY;IAC/C,IAAI;QACF,IAAM,GAAG,GAAG,SAAS,EAAE,CAAC;QAExB,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;KAC5C;IAAC,OAAO,CAAC,EAAE;QACV,uBAAuB;KACxB;AACH,CAAC","sourcesContent":["import { getWindow } from './dom/getWindow';\n\n/**\n * Fetches an item from local storage without throwing an exception\n * @param key The key of the item to fetch from local storage\n */\nexport function getItem(key: string): string | null {\n let result = null;\n try {\n const win = getWindow();\n result = win ? win.localStorage.getItem(key) : null;\n } catch (e) {\n /* Eat the exception */\n }\n return result;\n}\n\n/**\n * Inserts an item into local storage without throwing an exception\n * @param key The key of the item to add to local storage\n * @param data The data to put into local storage\n */\nexport function setItem(key: string, data: string): void {\n try {\n const win = getWindow();\n\n win && win.localStorage.setItem(key, data);\n } catch (e) {\n /* Eat the exception */\n }\n}\n"]}