CARVIEW |
Select Language
HTTP/2 301
location: https://raw.githubusercontent.com/nbubna/store/master/src/store.array.js
accept-ranges: bytes
age: 0
date: Mon, 21 Jul 2025 06:38:31 GMT
via: 1.1 varnish
x-served-by: cache-bom4740-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753079912.585095,VS0,VE277
vary: Accept-Encoding
x-fastly-request-id: b99cf069d7351ff8d6cfe463abe2da3c996f0a32
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/"4a87018f19cdc299a2cd83652e333e750aed504052f363bca39c77f1171a7d47"
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: E258:248062:39605:758ED:687DE067
content-encoding: gzip
accept-ranges: bytes
date: Mon, 21 Jul 2025 06:38:32 GMT
via: 1.1 varnish
x-served-by: cache-bom4747-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753079912.913059,VS0,VE363
vary: Authorization,Accept-Encoding
access-control-allow-origin: *
cross-origin-resource-policy: cross-origin
x-fastly-request-id: ce61f4670deb5d717b0dc3a1cd8f00b1fff1fa7a
expires: Mon, 21 Jul 2025 06:43:32 GMT
source-age: 0
content-length: 918
/**
* Copyright (c) 2017 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
*
* Adds shortcut for safely applying all available Array functions to stored values. If there is no
* value, the functions will act as if upon an empty one. If there is a non, array value, it is put
* into an array before the function is applied. If the function results in an empty array, the
* key/value is removed from the storage, otherwise the array is restored.
*
* store.push('array', 'a', 1, true);// == store.set('array', (store.get('array')||[]).push('a', 1, true]));
* store.indexOf('array', true);// === store.get('array').indexOf(true)
*
* This will add all functions of Array.prototype that are specific to the Array interface and have no
* conflict with existing store functions.
*
* Status: BETA - useful, but adds more functions than reasonable
*/
;(function(_, Array) {
// expose internals on the underscore to allow extensibility
_.array = function(fnName, key, args) {
var value = this.get(key, []),
array = Array.isArray(value) ? value : [value],
ret = array[fnName].apply(array, args);
if (array.length > 0) {
this.set(key, array.length > 1 ? array : array[0]);
} else {
this.remove(key);
}
return ret;
};
_.arrayFn = function(fnName) {
return function(key) {
return this.array(fnName, key,
arguments.length > 1 ? Array.prototype.slice.call(arguments, 1) : null);
};
};
// add function(s) to the store interface
_.fn('array', _.array);
Object.getOwnPropertyNames(Array.prototype).forEach(function(name) {
// add Array interface functions w/o existing conflicts
if (typeof Array.prototype[name] === "function") {
if (!(name in _.storeAPI)) {
_.fn(name, _.array[name] = _.arrayFn(name));
}
}
});
})(window.store._, window.Array);