New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

store2

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

store2 - npm Package Compare versions

Comparing version 2.0.3 to 2.1.0

src/store.measure.js

4

package.json
{
"name": "store2",
"description": "Better localStorage",
"keywords": "localStorage sessionStorage json namespace",
"version": "2.0.3",
"keywords": ["localStorage","sessionStorage","json","namespace","store"],
"version": "2.1.0",
"author": {

@@ -7,0 +7,0 @@ "name": "Nathan Bubna",

A feature-filled and friendly way to take advantage of localStorage and sessionStorage
(JSON, namespacing, extensions, etc).
Download: [store.min.js][prod] or [store.js][dev]
[NPM][npm]: ```npm install store2``` ([store was taken](#store-vs-store))
Bower: ```bower install store```
Download: [store2.min.js][prod] or [store2.js][dev]
[NPM][npm]: ```npm install store2```
Bower: ```bower install store2```
[prod]: https://raw.github.com/nbubna/store/master/dist/store.min.js
[dev]: https://raw.github.com/nbubna/store/master/dist/store.js
[prod]: https://raw.github.com/nbubna/store/master/dist/store2.min.js
[dev]: https://raw.github.com/nbubna/store/master/dist/store2.js
[npm]: https://npmjs.org/package/store2

@@ -35,5 +35,4 @@

store.remove(key); // removes key and its data
store.each(callback); // callback receives key, data, index args
store.each(callback); // callback receives key and data args
store.keys(); // returns array of keys
store.key(index); // return key at index
store.size(); // number of keys, not length of data

@@ -90,7 +89,9 @@ store.clearAll(); // clears *ALL* areas

* [store.old.js][old] - Add working localStorage and sessionStorage polyfills for older browsers
* [store.overflow.js][overflow] - Fall back to fake storage on quota errors (e.g. [Safari private mode][safari])
* [store.cache.js][cache] - To make data expire, pass a number of minutes as the overwrite param on ```set()``` calls
* [store.bind.js][bind] - Better, cross-browser storage event handling (in browsers that have such events)
* [store.quota.js][quota] - Add handlers for quota errors, experiments in measuring data use
* [store.overflow.js][overflow] - Short demo extension that probably has no legitimate use case.
* [store.measure.js][measure] - Experimental extension for measuring space used and available (needs work)
[old]: https://raw.github.com/nbubna/store/master/src/store.old.js

@@ -101,2 +102,4 @@ [cache]: https://raw.github.com/nbubna/store/master/src/store.cache.js

[overflow]: https://raw.github.com/nbubna/store/master/src/store.overflow.js
[measure]: https://raw.github.com/nbubna/store/master/src/store.measure.js
[safari]: https://github.com/marcuswestin/store.js/issues/66

@@ -117,5 +120,5 @@ ## Release History

Until such time as Marcus retires his polyfill, i will continue to publish on Bower as 'store' and NPM as 'store2'.
My apologies for any confusion this causes.
To minimize confusion, i will be publishing the library as 'store2', but the main function will always be ```store``` (kind of like json2.js). My apologies for the
confusion caused while i was publishing this as another 'store'.
[other]: https://github.com/marcuswestin/store.js/

@@ -15,3 +15,5 @@ /**

suffix = ';',
parse = _.parse;
parse = _.parse,
_get = _.get,
_set = _.set;
_.parse = function(s) {

@@ -34,3 +36,4 @@ if (s && s.indexOf(prefix) === 0) {

_.cache = function(area, key) {
var s = area.getItem(key), min = _.expires(s);
var s = _get(area, key),
min = _.expires(s);
if (min && _.when() >= min) {

@@ -50,3 +53,3 @@ return area.removeItem(key);

}
area.setItem(key, string);
_set(area, key, string);
} catch (e) {

@@ -53,0 +56,0 @@ if (e.name === 'QUOTA_EXCEEDED_ERR' || e.name === 'NS_ERROR_DOM_QUOTA_REACHED') {

@@ -8,37 +8,80 @@ /**

* When quota is reached on a storage area, this shifts incoming values to
* shorter-term areas (local overflows into session which overflows into fake).
* fake storage, so they last only as long as the page does. This is useful
* because it is more burdensome for localStorage to recover from quota errors
* than incomplete caches. In other words, it is wiser to rely on store.js
* never complaining than never missing data. You should already be checking
* the integrity of cached data on every page load. Also note that quota errors
* are thrown by Safari for *every* setItem when user is in private browsing mode.
* http://spin.atomicobject.com/2013/01/23/ios-private-browsing-localstorage/
*
* Status: EXPERIMENTAL - not likely to serve any useful purpose
* Status: BETA
*/
;(function(store, _) {
var set = _.set, get = _.get, remove = _.remove;
store.area('overflow');//create overflow area
var _set = _.set,
_get = _.get,
_remove = _.remove,
_key = _.key,
_length = _.length,
_clear = _.clear;
_.overflow = function(area, create) {
var name = area === _.areas.local ? '+local+' :
area === _.areas.session ? '+session+' : false;
if (name) {
var overflow = _.areas[name];
if (create && !overflow) {
overflow = store.area(name)._area;// area() copies to _.areas
} else if (create === false) {
delete _.areas[name];
delete store[name];
}
return overflow;
}
};
_.set = function(area, key, string) {
try {
_set.apply(this, arguments);
} catch (e) {
if (e.name === 'QUOTA_EXCEEDED_ERR' ||
e.name === 'NS_ERROR_DOM_QUOTA_REACHED') {
return _.set(_.overflow(area, true), key, string);
}
throw e;
}
};
_.get = function(area, key) {
var d = get.apply(this, arguments);
if (d !== null){ return d; }
if (area === _.areas.local){ return _.get(_.areas.session, key); }
if (area === _.areas.session){ return _.get(_.areas.overflow, key); }
return null;
var overflow = _.overflow(area);
return (overflow && _get.call(this, overflow, key)) ||
_get.apply(this, arguments);
};
_.remove = function(area, key) {
var d = get.apply(this, arguments);
if (d !== null){ return remove.apply(this, arguments); }
if (area === _.areas.local){ return _.remove(_.areas.session, key); }
if (area === _.areas.session){ return _.remove(_.areas.overflow, key); }
var overflow = _.overflow(area);
if (overflow){ _remove.call(this, overflow, key); }
_remove.apply(this, arguments);
};
_.set = function(area, key, string, ow) {
try {
set.apply(this, arguments);
} catch (e) {
if (e.name === 'QUOTA_EXCEEDED_ERR' || e.name === 'NS_ERROR_DOM_QUOTA_REACHED') {
if (area === _.areas.local) {
return _.set(_.areas.session, key, string, ow);
_.key = function(area, i) {
var overflow = _.overflow(area);
if (overflow) {
var l = _length.call(this, area);
if (i > l) {
i = i - l;// make i overflow-relative
for (var j=0, m=_length.call(this, overflow); j<m; j++) {
if (j === i) {// j is overflow index
return _key.call(this, overflow, j);
}
}
if (area === _.areas.session) {
return _.set(_.areas.overflow, key, string, ow);
}
}
throw e;
}
return _key.apply(this, arguments);
};
_.length = function(area) {
var length = _length(area),
overflow = _.overflow(area);
return overflow ? length + _length(overflow) : length;
};
_.clear = function(area) {
_.overflow(area, false);
_clear.apply(this, arguments);
};
})(window.store, window.store._);

@@ -7,20 +7,32 @@ /**

*
* Allows user to register handlers for quota errors, if a handler returns true
* other handlers are not called and the error is suppressed. Also provides methods
* to test available space, but *these are expensive and crash-prone*!
* Bind handlers to quota errors:
* store.quota(function(e, area, key, str) {
* console.log(e, area, key, str);
* });
* If a handler returns true other handlers are not called and
* the error is suppressed.
*
* Status: ALPHA - possibly useful, with some dangerous features (store.remaining())
* Think quota errors will never happen to you? Think again:
* http://spin.atomicobject.com/2013/01/23/ios-private-browsing-localstorage/
* (this affects sessionStorage too)
*
* Status: ALPHA - API could use unbind feature
*/
;(function(store, _) {
var set = _.set,
list = [];
store.full = function(fn){ list.push(fn); },
store.full.handlers = list;
_.set = function() {
store.quota = function(fn) {
store.quota.fns.push(fn);
};
store.quota.fns = [];
var _set = _.set;
_.set = function(area, key, str) {
try {
set.apply(this, arguments);
_set.apply(this, arguments);
} catch (e) {
if (e.name === 'QUOTA_EXCEEDED_ERR' || e.name === 'NS_ERROR_DOM_QUOTA_REACHED') {
for (var i=0,m=list.length; i<m; i++) {
if (true === list[i].apply(this, arguments)) {
if (e.name === 'QUOTA_EXCEEDED_ERR' ||
e.name === 'NS_ERROR_DOM_QUOTA_REACHED') {
var fns = store.quota.fns;
for (var i=0,m=fns.length; i<m; i++) {
if (true === fns[i].call(this, e, area, key, str)) {
return;

@@ -33,33 +45,3 @@ }

};
var test = function(s) {
try {
set(localStorage, "__test__", s);
return s;
} catch (e) {}
};
store.existing = function(){ return _.stringify(store()).length; };
store.remaining = function() {
if (store.isFake()){ return; }
if (store._area.remainingSpace){ return store._area.remainingSpace; }
var s = 's ', add = s;
// grow add for speed
while (test(s)) {
s += add;
if (add.length < 50000) {
add = s;
}
}
// shrink add for accuracy
while (add.length > 2) {
s = s.substring(0, s.length - (add.length/2));
while (test(s)) {
s += add;
}
add = add.substring(add.length/2);
}
_.remove(localStorage, "__test__");
return s.length + 8;
};
store.quota = function(){ return store.existing() + store.remaining(); };
})(window.store, window.store._);
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc