Files
shlink-web-client/src/utils/Storage.js
Alejandro Celaya 3eaa66435a Fixed tests
2018-07-22 22:49:51 +02:00

19 lines
503 B
JavaScript

const PREFIX = 'shlink';
const buildPath = path => `${PREFIX}.${path}`;
export class Storage {
constructor(localStorage) {
this.localStorage = localStorage;
}
get = key => {
const item = this.localStorage.getItem(buildPath(key));
return item ? JSON.parse(item) : undefined;
};
set = (key, value) => this.localStorage.setItem(buildPath(key), JSON.stringify(value));
}
const storage = typeof localStorage !== 'undefined' ? localStorage : {};
export default new Storage(storage);