Comparing version
19
index.js
@@ -30,4 +30,4 @@ 'use strict'; | ||
}, | ||
raw: { | ||
value() { | ||
rawKeys: { | ||
get() { | ||
const keys = []; | ||
@@ -46,5 +46,4 @@ for (let i = 0; i < storage.length; i += 1) { | ||
get() { | ||
return this.raw().map(key => | ||
key.replace(new RegExp(`^${namespace}.`), '') | ||
); | ||
return this.rawKeys.map(key => | ||
key.replace(new RegExp(`^${namespace}.`), '')); | ||
} | ||
@@ -67,6 +66,12 @@ }, | ||
}, | ||
stringify: { | ||
enumerable: true, | ||
value(replacer, space) { | ||
return JSON.stringify(this.valueOf(), replacer, space); | ||
} | ||
}, | ||
size: { | ||
enumerable: true, | ||
get() { | ||
return this.raw().length; | ||
return this.rawKeys.length; | ||
} | ||
@@ -83,3 +88,3 @@ }, | ||
value() { | ||
this.keys.forEach(key => { | ||
this.rawKeys.forEach(key => { | ||
storage.removeItem(key); | ||
@@ -86,0 +91,0 @@ }); |
{ | ||
"name": "pet-shop", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "A simple wrapper of Web Storage API", | ||
"main": "index.js", | ||
"license": "MIT", | ||
@@ -11,5 +10,11 @@ "author": { | ||
}, | ||
"engines": { | ||
"node": ">=8.3.0" | ||
}, | ||
"keywords": [ | ||
"cache", | ||
"config", | ||
"data", | ||
"localStorage", | ||
"sessionStorage", | ||
"storage", | ||
"store" | ||
], | ||
"repository": { | ||
@@ -20,11 +25,6 @@ "type": "git", | ||
}, | ||
"keywords": [ | ||
"data", | ||
"cache", | ||
"store", | ||
"config", | ||
"storage", | ||
"localStorage", | ||
"sessionStorage" | ||
] | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=8.3.0" | ||
} | ||
} |
@@ -20,1 +20,19 @@ # pet-shop | ||
``` | ||
Usage | ||
```js | ||
const store = PetShop({ | ||
namespace: 'pet-shop', | ||
storage: localStorage | ||
}); | ||
store.set('abc', 'xyz'); | ||
store.get('abc'); // output: 'xyz' | ||
store.size; // output: 0 | ||
localStorage.getItem('pet-shop.abc'); // output: 'xyz' | ||
store.remove('abc'); | ||
store.has('abc'); // output: false | ||
``` |
3534
14.78%91
5.81%38
90%