Skip to content

Commit

Permalink
feat: clear method added to storages
Browse files Browse the repository at this point in the history
  • Loading branch information
matiaslopezd committed Jul 29, 2024
1 parent 9b03230 commit cfe039e
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,33 @@ global.document = {

global.localStorage = {
store: {},
getItem: (key = '') => localStorage.store[key],
setItem: (key = '', value = '') => {
localStorage.store[key] = value;
getItem(key = '') {
return this.store[key];
},
removeItem: (key = '') => {
delete localStorage.store[key];
setItem(key = '', value = '') {
this.store[key] = value;
},
removeItem(key = '') {
delete this.store[key];
},
clear() {
this.store = {};
}
};

global.sessionStorage = {
store: {},
getItem: (key = '') => sessionStorage.store[key],
setItem: (key = '', value = '') => {
sessionStorage.store[key] = value;
getItem(key = '') {
return this.store[key];
},
setItem(key = '', value = '') {
this.store[key] = value;
},
removeItem(key = '') {
delete this.store[key];
},
removeItem: (key = '') => {
delete sessionStorage.store[key];
clear() {
this.store = {};
}
};

Expand Down

0 comments on commit cfe039e

Please sign in to comment.