CARVIEW |
Select Language
HTTP/2 301
location: https://raw.githubusercontent.com/nbubna/store/master/src/store.cookie.js
accept-ranges: bytes
age: 0
date: Mon, 21 Jul 2025 14:22:26 GMT
via: 1.1 varnish
x-served-by: cache-bom4750-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753107746.546209,VS0,VE998
vary: Accept-Encoding
x-fastly-request-id: 579989626231ac606214ab2fbcbf1655fee5df21
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/"e30cb686a26cd7ccc9cc2d961382d9970a911e2d6f94e5844a2a8d3151338579"
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: EB7B:2E653F:3FE2A5:80197C:687E4D21
content-encoding: gzip
accept-ranges: bytes
date: Mon, 21 Jul 2025 14:22:26 GMT
via: 1.1 varnish
x-served-by: cache-bom4736-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753107747.607266,VS0,VE382
vary: Authorization,Accept-Encoding
access-control-allow-origin: *
cross-origin-resource-policy: cross-origin
x-fastly-request-id: f9f231bdb0dfcbd6ed97488760c7bef752bb9a69
expires: Mon, 21 Jul 2025 14:27:26 GMT
source-age: 0
content-length: 983
/**
* Copyright (c) 2021 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
*
* Creates a store area that uses a single cookie as the backing storage.
* This gives you the store API for a specific 'store' cookie that your backend
* can access too. It could definitely use more testing.
*
* Status: BETA - unsupported, useful, needs testing
*/
;(function(window, document, store, _) {
var C = _.cookie = {// and that's good enough for me
name: 'store',
maxAge: 60*60*24*365*10,
suffix: ';path=/;sameSite=strict',
encode: function(state) {
return encodeURIComponent(JSON.stringify(state));
},
decode: function(state) {
return JSON.parse(decodeURIComponent(state));
}
};
C.all = function() {
return C.read(C.name) || {};
};
C.read = function(name) {
var match = document.cookie.match(new RegExp("(^| )"+(name||C.name)+"=([^;]+)"));
return match ? C.decode(match[2]) : null;
};
C.write = function(state, name) {
document.cookie = (name||C.name)+"="+C.encode(state)+";max-age="+C.maxAge+C.suffix;
};
C.remove = function(name) {
document.cookie = (name||C.name)+"=;expires=Thu, 01 Jan 1970 00:00:01 GMT"+C.suffix;
};
C.area = {
key: function(i) {
var c = 0,
state = C.all();
for (var k in state) {
if (state.hasOwnProperty(k) && i === c++) {
return k;
}
}
},
setItem: function(k, v) {
var state = C.all();
state[k] = v;
C.write(state);
},
getItem: function(k) {
var state = C.all();
return state.hasOwnProperty(k) ? state[k] : null;
},
has: function(k) {
return C.all().hasOwnProperty(k);
},
removeItem: function(k) {
var state = C.read(C.name);
delete state[k];
C.write(state);
},
clear: C.remove
};
Object.defineProperty(C.area, "length", {
get: function() {
var ln = 0,
state = C.all();
for (var k in state) {
if (state.hasOwnProperty(k)) {
ln++;
}
}
return ln;
}
});
// create the store api for this storage
store.area("cookie", C.area);
})(window, document, window.store, window.store._);