Comparing version 2.8.0 to 2.9.0
@@ -200,7 +200,7 @@ ;(function(){ | ||
require.register("store/dist/store2.js", function(exports, require, module){ | ||
/*! store2 - v2.8.0 - 2019-07-23 | ||
/*! store2 - v2.9.0 - 2019-08-21 | ||
* Copyright (c) 2019 Nathan Bubna; Licensed (MIT OR GPL-3.0) */ | ||
;(function(window, define) { | ||
var _ = { | ||
version: "2.8.0", | ||
version: "2.9.0", | ||
areas: {}, | ||
@@ -368,4 +368,4 @@ apis: {}, | ||
}, | ||
remove: function(key) { | ||
var d = this.get(key); | ||
remove: function(key, alt) { | ||
var d = this.get(key, alt); | ||
_.remove(this._area, this._in(key)); | ||
@@ -372,0 +372,0 @@ return d; |
@@ -1,6 +0,6 @@ | ||
/*! store2 - v2.8.0 - 2019-07-23 | ||
/*! store2 - v2.9.0 - 2019-08-21 | ||
* Copyright (c) 2019 Nathan Bubna; Licensed (MIT OR GPL-3.0) */ | ||
;(function(window, define) { | ||
var _ = { | ||
version: "2.8.0", | ||
version: "2.9.0", | ||
areas: {}, | ||
@@ -168,4 +168,4 @@ apis: {}, | ||
}, | ||
remove: function(key) { | ||
var d = this.get(key); | ||
remove: function(key, alt) { | ||
var d = this.get(key, alt); | ||
_.remove(this._area, this._in(key)); | ||
@@ -172,0 +172,0 @@ return d; |
@@ -1,5 +0,5 @@ | ||
/*! store2 - v2.8.0 - 2019-07-23 | ||
/*! store2 - v2.9.0 - 2019-08-21 | ||
* Copyright (c) 2019 Nathan Bubna; Licensed (MIT OR GPL-3.0) */ | ||
!function(a,b){var c={version:"2.8.0",areas:{},apis:{},inherit:function(a,b){for(var c in a)b.hasOwnProperty(c)||Object.defineProperty(b,c,Object.getOwnPropertyDescriptor(a,c));return b},stringify:function(a){return void 0===a||"function"==typeof a?a+"":JSON.stringify(a)},parse:function(a){try{return JSON.parse(a)}catch(b){return a}},fn:function(a,b){c.storeAPI[a]=b;for(var d in c.apis)c.apis[d][a]=b},get:function(a,b){return a.getItem(b)},set:function(a,b,c){a.setItem(b,c)},remove:function(a,b){a.removeItem(b)},key:function(a,b){return a.key(b)},length:function(a){return a.length},clear:function(a){a.clear()},Store:function(a,b,d){var e=c.inherit(c.storeAPI,function(a,b,c){return 0===arguments.length?e.getAll():"function"==typeof b?e.transact(a,b,c):void 0!==b?e.set(a,b,c):"string"==typeof a||"number"==typeof a?e.get(a):"function"==typeof a?e.each(a):a?e.setAll(a,b):e.clear()});e._id=a;try{b.setItem("_-bad-_","wolf"),e._area=b,b.removeItem("_-bad-_")}catch(a){}return e._area||(e._area=c.inherit(c.storageAPI,{items:{},name:"fake"})),e._ns=d||"",c.areas[a]||(c.areas[a]=e._area),c.apis[e._ns+e._id]||(c.apis[e._ns+e._id]=e),e},storeAPI:{area:function(a,b){var d=this[a];return d&&d.area||(d=c.Store(a,b,this._ns),this[a]||(this[a]=d)),d},namespace:function(a,b){if(!a)return this._ns?this._ns.substring(0,this._ns.length-1):"";var d=a,e=this[d];return e&&e.namespace||(e=c.Store(this._id,this._area,this._ns+d+"."),this[d]||(this[d]=e),b||e.area("session",c.areas.session)),e},isFake:function(){return"fake"===this._area.name},toString:function(){return"store"+(this._ns?"."+this.namespace():"")+"["+this._id+"]"},has:function(a){return this._area.has?this._area.has(this._in(a)):!!(this._in(a)in this._area)},size:function(){return this.keys().length},each:function(a,b){for(var d=0,e=c.length(this._area);d<e;d++){var f=this._out(c.key(this._area,d));if(void 0!==f&&!1===a.call(this,f,this.get(f),b))break;e>c.length(this._area)&&(e--,d--)}return b||this},keys:function(a){return this.each(function(a,b,c){c.push(a)},a||[])},get:function(a,b){var d=c.get(this._area,this._in(a));return null!==d?c.parse(d):b||d},getAll:function(a){return this.each(function(a,b,c){c[a]=b},a||{})},transact:function(a,b,c){var d=this.get(a,c),e=b(d);return this.set(a,void 0===e?d:e),this},set:function(a,b,d){var e=this.get(a);return null!=e&&!1===d?b:c.set(this._area,this._in(a),c.stringify(b),d)||e},setAll:function(a,b){var c,d;for(var e in a)d=a[e],this.set(e,d,b)!==d&&(c=!0);return c},add:function(a,b){var d=this.get(a);if(d instanceof Array)b=d.concat(b);else if(null!==d){var e=typeof d;if(e===typeof b&&"object"===e){for(var f in b)d[f]=b[f];b=d}else b=d+b}return c.set(this._area,this._in(a),c.stringify(b)),b},remove:function(a){var b=this.get(a);return c.remove(this._area,this._in(a)),b},clear:function(){return this._ns?this.each(function(a){c.remove(this._area,this._in(a))},1):c.clear(this._area),this},clearAll:function(){var a=this._area;for(var b in c.areas)c.areas.hasOwnProperty(b)&&(this._area=c.areas[b],this.clear());return this._area=a,this},_in:function(a){return"string"!=typeof a&&(a=c.stringify(a)),this._ns?this._ns+a:a},_out:function(a){return this._ns?a&&0===a.indexOf(this._ns)?a.substring(this._ns.length):void 0:a}},storageAPI:{length:0,has:function(a){return this.items.hasOwnProperty(a)},key:function(a){var b=0;for(var c in this.items)if(this.has(c)&&a===b++)return c},setItem:function(a,b){this.has(a)||this.length++,this.items[a]=b},removeItem:function(a){this.has(a)&&(delete this.items[a],this.length--)},getItem:function(a){return this.has(a)?this.items[a]:null},clear:function(){for(var a in this.items)this.removeItem(a)},toString:function(){return this.length+" items in "+this.name+"Storage"}}},d=c.Store("local",function(){try{return localStorage}catch(a){}}());d.local=d,d._=c,d.area("session",function(){try{return sessionStorage}catch(a){}}()),"function"==typeof b&&void 0!==b.amd?b("store2",[],function(){return d}):"undefined"!=typeof module&&module.exports?module.exports=d:(a.store&&(c.conflict=a.store),a.store=d)}(this,this&&this.define); | ||
!function(a,b){var c={version:"2.9.0",areas:{},apis:{},inherit:function(a,b){for(var c in a)b.hasOwnProperty(c)||Object.defineProperty(b,c,Object.getOwnPropertyDescriptor(a,c));return b},stringify:function(a){return void 0===a||"function"==typeof a?a+"":JSON.stringify(a)},parse:function(a){try{return JSON.parse(a)}catch(b){return a}},fn:function(a,b){c.storeAPI[a]=b;for(var d in c.apis)c.apis[d][a]=b},get:function(a,b){return a.getItem(b)},set:function(a,b,c){a.setItem(b,c)},remove:function(a,b){a.removeItem(b)},key:function(a,b){return a.key(b)},length:function(a){return a.length},clear:function(a){a.clear()},Store:function(a,b,d){var e=c.inherit(c.storeAPI,function(a,b,c){return 0===arguments.length?e.getAll():"function"==typeof b?e.transact(a,b,c):void 0!==b?e.set(a,b,c):"string"==typeof a||"number"==typeof a?e.get(a):"function"==typeof a?e.each(a):a?e.setAll(a,b):e.clear()});e._id=a;try{b.setItem("_-bad-_","wolf"),e._area=b,b.removeItem("_-bad-_")}catch(a){}return e._area||(e._area=c.inherit(c.storageAPI,{items:{},name:"fake"})),e._ns=d||"",c.areas[a]||(c.areas[a]=e._area),c.apis[e._ns+e._id]||(c.apis[e._ns+e._id]=e),e},storeAPI:{area:function(a,b){var d=this[a];return d&&d.area||(d=c.Store(a,b,this._ns),this[a]||(this[a]=d)),d},namespace:function(a,b){if(!a)return this._ns?this._ns.substring(0,this._ns.length-1):"";var d=a,e=this[d];return e&&e.namespace||(e=c.Store(this._id,this._area,this._ns+d+"."),this[d]||(this[d]=e),b||e.area("session",c.areas.session)),e},isFake:function(){return"fake"===this._area.name},toString:function(){return"store"+(this._ns?"."+this.namespace():"")+"["+this._id+"]"},has:function(a){return this._area.has?this._area.has(this._in(a)):!!(this._in(a)in this._area)},size:function(){return this.keys().length},each:function(a,b){for(var d=0,e=c.length(this._area);d<e;d++){var f=this._out(c.key(this._area,d));if(void 0!==f&&!1===a.call(this,f,this.get(f),b))break;e>c.length(this._area)&&(e--,d--)}return b||this},keys:function(a){return this.each(function(a,b,c){c.push(a)},a||[])},get:function(a,b){var d=c.get(this._area,this._in(a));return null!==d?c.parse(d):b||d},getAll:function(a){return this.each(function(a,b,c){c[a]=b},a||{})},transact:function(a,b,c){var d=this.get(a,c),e=b(d);return this.set(a,void 0===e?d:e),this},set:function(a,b,d){var e=this.get(a);return null!=e&&!1===d?b:c.set(this._area,this._in(a),c.stringify(b),d)||e},setAll:function(a,b){var c,d;for(var e in a)d=a[e],this.set(e,d,b)!==d&&(c=!0);return c},add:function(a,b){var d=this.get(a);if(d instanceof Array)b=d.concat(b);else if(null!==d){var e=typeof d;if(e===typeof b&&"object"===e){for(var f in b)d[f]=b[f];b=d}else b=d+b}return c.set(this._area,this._in(a),c.stringify(b)),b},remove:function(a,b){var d=this.get(a,b);return c.remove(this._area,this._in(a)),d},clear:function(){return this._ns?this.each(function(a){c.remove(this._area,this._in(a))},1):c.clear(this._area),this},clearAll:function(){var a=this._area;for(var b in c.areas)c.areas.hasOwnProperty(b)&&(this._area=c.areas[b],this.clear());return this._area=a,this},_in:function(a){return"string"!=typeof a&&(a=c.stringify(a)),this._ns?this._ns+a:a},_out:function(a){return this._ns?a&&0===a.indexOf(this._ns)?a.substring(this._ns.length):void 0:a}},storageAPI:{length:0,has:function(a){return this.items.hasOwnProperty(a)},key:function(a){var b=0;for(var c in this.items)if(this.has(c)&&a===b++)return c},setItem:function(a,b){this.has(a)||this.length++,this.items[a]=b},removeItem:function(a){this.has(a)&&(delete this.items[a],this.length--)},getItem:function(a){return this.has(a)?this.items[a]:null},clear:function(){for(var a in this.items)this.removeItem(a)},toString:function(){return this.length+" items in "+this.name+"Storage"}}},d=c.Store("local",function(){try{return localStorage}catch(a){}}());d.local=d,d._=c,d.area("session",function(){try{return sessionStorage}catch(a){}}()),"function"==typeof b&&void 0!==b.amd?b("store2",[],function(){return d}):"undefined"!=typeof module&&module.exports?module.exports=d:(a.store&&(c.conflict=a.store),a.store=d)}(this,this&&this.define); | ||
//# sourceMappingURL=store2.min.js.map |
@@ -14,3 +14,3 @@ declare namespace store { | ||
export function has(key: any): boolean; | ||
export function remove(key: any): any; | ||
export function remove(key: any, alt?: any): any; | ||
export function each(callback: (key: any, data: any) => false | any, value?: any): StoreAPI; | ||
@@ -33,3 +33,3 @@ export function keys(fillList?: string[]): string[]; | ||
namespace(namespace: string, noSession?: true): StoreAPI; | ||
remove(key: any): any; | ||
remove(key: any, alt?: any): any; | ||
set(key: any, data: any, overwrite?: boolean): any; | ||
@@ -61,4 +61,4 @@ setAll(data: Object, overwrite?: boolean): StoredData; | ||
declare function store(obj: Object): store.StoredData | ||
declare function store(): store.StoredData | ||
declare function store(eachFn: (key: any, data: any) => false | any, value?: any): store.StoredData | ||
export = store; |
{ | ||
"name": "store2", | ||
"version": "2.8.0", | ||
"version": "2.9.0", | ||
"description": "Better localStorage", | ||
@@ -34,3 +34,3 @@ "keywords": [ | ||
"scripts": { | ||
"prepublishOnly": "grunt && git commit -m \"$npm_package_version\" README.md *.json dist && git tag $npm_package_version && git push && git push --tags", | ||
"prepubishOnly": "grunt && git commit -m \"$npm_package_version\" README.md *.json dist && git tag $npm_package_version && git push && git push --tags", | ||
"test": "grunt qunit" | ||
@@ -37,0 +37,0 @@ }, |
@@ -27,3 +27,3 @@ A feature-filled and friendly way to take advantage of localStorage and sessionStorage | ||
store(); // gets all stored key/data pairs as an object | ||
store(fn); // calls fn for each key/data in storage, return false to exit early | ||
store((key, data)=>{ }); // calls function for each key/data in storage, return false to exit | ||
store(false); // clears all items from storage | ||
@@ -42,3 +42,3 @@ ``` | ||
store.has(key); // returns true or false | ||
store.remove(key); // removes key and its data, then returns the data | ||
store.remove(key[, alt]); // removes key and its data, then returns the data or alt, if none | ||
store.each(fn[, fill]); // === store(fn); optional call arg will be 3rd fn arg (e.g. for gathering values) | ||
@@ -211,2 +211,3 @@ store.add(key, data); // concats, merges, or adds new value into existing one | ||
* 2019-07-23 [v2.8.0][] (public) - Add ```store(fn)``` shortcut for ```store.each```, copy properties when inheriting, and make ```store.each(fn, fill)``` always send fill as 3rd arg instead of replacing values. | ||
* 2019-08-21 [v2.9.0][] (public) - Add store.remove(key, alt) to match behavior of store.get(key, alt) (Issue #68) | ||
@@ -230,14 +231,2 @@ [v2.0.3]: https://github.com/nbubna/store/tree/2.0.3 | ||
[v2.8.0]: https://github.com/nbubna/store/tree/2.8.0 | ||
## Store vs Store | ||
When i went to publish this on NPM i discovered another [store.js][other] by Marcus Westin. | ||
To my pleasure, even our APIs had notable overlap, but his had fewer features and a focus on polyfilling old | ||
browsers (e.g. IE 6/7). He saw the library at the time as a temporary polyfill, while i intended mine | ||
to always be a better way to use localStorage and sessionStorage. We discussed merging the featuresets, | ||
but we agreed it wouldn't work due to different goals. To minimize confusion, i published this as 'store2', | ||
but kept the main function as `store`. Marcus' later decision to pivot and adopt the goals and many of | ||
the features of this library into a v2 of store.js has put these libraries into more direct competition. | ||
I believe this library to be superior in implementation and interface, though not in all aspects and the | ||
differences are admittedly small. There is still potential for unification, perhaps in a v3 someday. | ||
[other]: https://github.com/marcuswestin/store.js/ | ||
[v2.9.0]: https://github.com/nbubna/store/tree/2.9.0 |
@@ -172,4 +172,4 @@ /** | ||
}, | ||
remove: function(key) { | ||
var d = this.get(key); | ||
remove: function(key, alt) { | ||
var d = this.get(key, alt); | ||
_.remove(this._area, this._in(key)); | ||
@@ -176,0 +176,0 @@ return d; |
Sorry, the diff of this file is not supported yet
117633
229