(Go Back) Choose State To Move From
' && typeof value !== 'object') {
return;
}
if (typeof value === 'object') {
this._setObject(key, value);
} else {
this._setKey(key, value);
}
}
/**
* Set a key value pair in the storage
* @param {string} key
* @param {string} value
*/
_setKey(key, value) {
if (typeof value === 'undefined') {
value = null;
}
this._storage[key] = value;
}
/**
* Set an object in the storage
* @param {string} key
* @param {Object} value
*/
_setObject(key, value) {
if (typeof value === 'undefined') {
value = {};
}
this._storage[key] = JSON.stringify(value);
}
/**
* Remove a key value pair in the storage
* @param {string} key
*/
remove(key) {
delete this._storage[key];
}
/**
* Get a key value pair in the storage
* @param {string} key
* @returns {string}
*/
get(key) {
let value = this._storage[key];
if (typeof value === 'undefined') {
return null;
}
return value;
}
/**
* Get an object in the storage
* @param {string} key
* @returns {Object}
*/
getObject(key) {
let value = this._storage[key];
if (typeof value === 'undefined') {
return null;
}
return JSON.parse(value);
}
/**
* Clear the storage
*/
clear() {
this._storage = {};
}
/**
* Get all key value pairs in the storage
* @returns {Array} Array of key value pairs
*/
getAll() {
return this._storage;
}
}
export default Storage;