CARVIEW |
Select Language
HTTP/2 301
location: https://raw.githubusercontent.com/nbubna/store/master/src/store.measure.js
accept-ranges: bytes
age: 0
date: Mon, 21 Jul 2025 03:15:20 GMT
via: 1.1 varnish
x-served-by: cache-bom4721-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753067720.373520,VS0,VE251
vary: Accept-Encoding
x-fastly-request-id: 1a03e6609fdd021b6838055189c46845244b6b67
content-length: 0
HTTP/2 200
cache-control: max-age=300
content-security-policy: default-src 'none'; style-src 'unsafe-inline'; sandbox
content-type: text/plain; charset=utf-8
etag: W/"2bf5cefe8f3b25a3a6a2c405fc5ba2a4e5ffec440e6c3798942807d4dd360333"
strict-transport-security: max-age=31536000
x-content-type-options: nosniff
x-frame-options: deny
x-xss-protection: 1; mode=block
x-github-request-id: 0B8A:5B873:3277BA:80DBAF:687DB0C8
content-encoding: gzip
accept-ranges: bytes
date: Mon, 21 Jul 2025 03:15:20 GMT
via: 1.1 varnish
x-served-by: cache-bom4733-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753067721.676350,VS0,VE323
vary: Authorization,Accept-Encoding
access-control-allow-origin: *
cross-origin-resource-policy: cross-origin
x-fastly-request-id: 24975546085d36ea779ac47ad4b2c3e450d4f8a8
expires: Mon, 21 Jul 2025 03:20:20 GMT
source-age: 0
content-length: 774
/**
* Copyright (c) 2013 ESHA Research
* Dual licensed under the MIT and GPL licenses:
* https://www.opensource.org/licenses/mit-license.php
* https://www.gnu.org/licenses/gpl.html
*
* store.remainingSpace();// returns remainingSpace value (if browser supports it)
* store.charsUsed();// returns length of all data when stringified
* store.charsLeft([true]);// tests how many more chars we can fit (crash threat!)
* store.charsTotal([true]);// charsUsed + charsLeft, duh.
*
* TODO: byte/string conversions
*
* Status: ALPHA - changing API *and* crash threats :)
*/
;(function(store, _) {
function put(area, s) {
try {
area.setItem("__test__", s);
return true;
} catch (e) {}
}
_.fn('remainingSpace', function() {
return this._area.remainingSpace;
});
_.fn('charsUsed', function() {
return _.stringify(this.getAll()).length - 2;
});
_.fn('charsLeft', function(test) {
if (this.isFake()){ return; }
if (arguments.length === 0) {
test = window.confirm('Calling store.charsLeft() may crash some browsers!');
}
if (test) {
var s = 's ', add = s;
// grow add for speed
while (put(store._area, 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 (put(store._area, s)) {
s += add;
}
add = add.substring(add.length/2);
}
_.remove(store._area, "__test__");
return s.length + 8;
}
});
_.fn('charsTotal', function(test) {
return store.charsUsed() + store.charsLeft(test);
});
})(window.store, window.store._);