aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/local_storage/local_storage.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/website/ts/local_storage/local_storage.ts')
-rw-r--r--packages/website/ts/local_storage/local_storage.ts35
1 files changed, 35 insertions, 0 deletions
diff --git a/packages/website/ts/local_storage/local_storage.ts b/packages/website/ts/local_storage/local_storage.ts
new file mode 100644
index 000000000..d94e6877b
--- /dev/null
+++ b/packages/website/ts/local_storage/local_storage.ts
@@ -0,0 +1,35 @@
+import * as _ from 'lodash';
+
+export const localStorage = {
+ doesExist() {
+ return !!window.localStorage;
+ },
+ getItemIfExists(key: string): string {
+ if (!this.doesExist) {
+ return undefined;
+ }
+ const item = window.localStorage.getItem(key);
+ if (_.isNull(item) || item === 'undefined') {
+ return '';
+ }
+ return item;
+ },
+ setItem(key: string, value: string) {
+ if (!this.doesExist || _.isUndefined(value)) {
+ return;
+ }
+ window.localStorage.setItem(key, value);
+ },
+ removeItem(key: string) {
+ if (!this.doesExist) {
+ return;
+ }
+ window.localStorage.removeItem(key);
+ },
+ getAllKeys(): string[] {
+ if (!this.doesExist) {
+ return [];
+ }
+ return _.keys(window.localStorage);
+ },
+};