engauge
Version:
Javascript A/B Testing Library for Engauge
36 lines (34 loc) • 801 B
JavaScript
import store from 'store';
// a thin wrapper around store.js for easy swapping
class Storage {
constructor(key) {
if (!store.enabled) { throw 'local storage not supported'; }
this.namespace = key;
this.storage = store.get(this.namespace) || {};
}
set(key, value) {
this.storage[key] = value;
store.set(this.namespace, this.storage);
return value;
}
get(key) {
return this.storage[key];
}
isLocalStorageNameSupported() {
let testKey = 'test', storage;
if (typeof process !== 'undefined') {
return false;
}
else {
storage = window.sessionStorage;
}
try {
storage.setItem(testKey, '1');
storage.removeItem(testKey);
return true;
} catch (error) {
return false;
}
}
}
export default Storage;