micro-storage
Advanced tools
Comparing version 0.0.7 to 0.0.8
/*! | ||
* @ProjectName micro-storage | ||
* @Version 0.0.7 | ||
* @Version 0.0.8 | ||
* @Author lixinliang(https://github.com/lixinliang) | ||
* @Update 2016-09-24 12:17:55 am | ||
* @Update 2016-09-25 1:12:27 pm | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.microStorage=t():e.microStorage=t()}(this,function(){return function(e){function t(r){if(o[r])return o[r].exports;var n=o[r]={exports:{},id:r,loaded:!1};return e[r].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var o={};return t.m=e,t.c=o,t.p="",t(0)}([function(e,t){"use strict";function o(e){function t(t,o){if(0!=arguments.length){if(1==arguments.length){var r=JSON.parse(localStorage.getItem(e+"."+t));return r?r.$:r}return localStorage.setItem(e+"."+t,JSON.stringify({$:o})),o}}return t.remove=function(t){localStorage.removeItem(e+"."+t)},t}o.version="0.0.7",e.exports=o}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.microStorage=t():e.microStorage=t()}(this,function(){return function(e){function t(r){if(o[r])return o[r].exports;var n=o[r]={exports:{},id:r,loaded:!1};return e[r].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var o={};return t.m=e,t.c=o,t.p="",t(0)}([function(e,t){"use strict";function o(e){function t(t,o){if(0!=arguments.length){if(1==arguments.length){var n=JSON.parse(localStorage.getItem(e+"."+t));return n?n.$:n}return localStorage.setItem(e+"."+t,JSON.stringify({$:o})),r[e][t]="",localStorage.setItem("micro-storage",JSON.stringify(r)),o}}return r[e]=r[e]||{},localStorage.setItem("micro-storage",JSON.stringify(r)),t.remove=function(t){localStorage.removeItem(e+"."+t),delete r[e][t],localStorage.setItem("micro-storage",JSON.stringify(r))},t.list=function(){return Object.keys(r[e])},t.clear=function(){var e=this;this.list().forEach(function(t){e.remove(t)})},t}o.version="0.0.8";var r=JSON.parse(localStorage.getItem("micro-storage"))||{};e.exports=o}])}); |
{ | ||
"name": "micro-storage", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "(<1kb) A lite localStorage plugin with namespace.", | ||
@@ -5,0 +5,0 @@ "main": "dist/micro-storage.min.js", |
@@ -35,4 +35,14 @@ # micro-storage | ||
#### ShowList | ||
``` | ||
example.list(); // ['myKey'] | ||
``` | ||
#### ClearItem | ||
``` | ||
example.clear(); | ||
``` | ||
## License | ||
MIT |
microStorage.version = '@VERSION'; | ||
let list = JSON.parse(localStorage.getItem('@NAME')) || {}; | ||
/** | ||
@@ -9,2 +11,6 @@ * A lite localStorage plugin with namespace | ||
function microStorage ( namespace ) { | ||
list[namespace] = list[namespace] || {}; | ||
localStorage.setItem('@NAME', JSON.stringify(list)); | ||
/** | ||
@@ -25,4 +31,7 @@ * Get or set value from storage | ||
localStorage.setItem(`${ namespace }.${ name }`, JSON.stringify({ $ : value })); | ||
list[namespace][name] = ''; | ||
localStorage.setItem('@NAME', JSON.stringify(list)); | ||
return value; | ||
}; | ||
/** | ||
@@ -34,3 +43,23 @@ * Remove value from storage | ||
localStorage.removeItem(`${ namespace }.${ name }`); | ||
delete list[namespace][name]; | ||
localStorage.setItem('@NAME', JSON.stringify(list)); | ||
}; | ||
/** | ||
* Return value list of storage | ||
* @return {Array} list list of storage | ||
*/ | ||
storage.list = function () { | ||
return Object.keys(list[namespace]); | ||
}; | ||
/** | ||
* Clear all value from storage | ||
*/ | ||
storage.clear = function () { | ||
this.list().forEach(( name ) => { | ||
this.remove(name); | ||
}); | ||
}; | ||
return storage; | ||
@@ -37,0 +66,0 @@ } |
@@ -71,2 +71,3 @@ 'use strict'; | ||
new PackageInfo({ | ||
'@NAME' : packageJson.name, | ||
'@VERSION' : packageJson.version, | ||
@@ -73,0 +74,0 @@ }), |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18263
373
48