PageSourceSearch

https://c2-static.comparably.com/1.575/comparably/js/js-cookie.js?1.575

js comparably.com collected 2026-09-24 06:59:32 UTC 5,634 bytes, 163 lines download raw bytes

1(function ($) {
2    ;(function (factory) {
3        var registeredInModuleLoader = false;
4        if (typeof define === 'function' && define.amd) {
5            define(factory);
6            registeredInModuleLoader = true;
7        }
8        if (typeof exports === 'object') {
9            module.exports = factory();
10            registeredInModuleLoader = true;
11        }
12        if (!registeredInModuleLoader) {
13            var OldCookies = window.Cookies;
14            var api = window.Cookies = factory();
15            api.noConflict = function () {
16                window.Cookies = OldCookies;
17                return api;
18            };
19        }
20    }(function () {
21        function extend () {
22            var i = 0;
23            var result = {};
24            for (; i < arguments.length; i++) {
25                var attributes = arguments[ i ];
26                for (var key in attributes) {
27                    result[key] = attributes[key];
28                }
29            }
30            return result;
31        }
32
33        function init (converter) {
34            function api (key, value, attributes) {
35                var result;
36                if (typeof document === 'undefined') {
37                    return;
38                }
39
40                // Write
41
42                if (arguments.length > 1) {
43                    attributes = extend({
44                        path: '/'
45                    }, api.defaults, attributes);
46
47                    if (typeof attributes.expires === 'number') {
48                        var expires = new Date();
49                        expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5);
50                        attributes.expires = expires;
51                    }
52
53                    // We're using "expires" because "max-age" is not supported by IE
54                    attributes.expires = attributes.expires ? attributes.expires.toUTCString() : '';
55
56                    try {
57                        result = JSON.stringify(value);
58                        if (/^[\{\[]/.test(result)) {
59                            value = result;
60                        }
61                    } catch (e) {}
62
63                    if (!converter.write) {
64                        value = encodeURIComponent(String(value))
65                            .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
66                    } else {
67                        value = converter.write(value, key);
68                    }
69
70                    key = encodeURIComponent(String(key));
71                    key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
72                    key = key.replace(/[\(\)]/g, escape);
73
74                    var stringifiedAttributes = '';
75
76                    for (var attributeName in attributes) {
77                        if (!attributes[attributeName]) {
78                            continue;
79                        }
80                        stringifiedAttributes += '; ' + attributeName;
81                        if (attributes[attributeName] === true) {
82                            continue;
83                        }
84                        stringifiedAttributes += '=' + attributes[attributeName];
85                    }
86                    return (document.cookie = key + '=' + value + stringifiedAttributes);
87                }
88
89                // Read
90
91                if (!key) {
92                    result = {};
93                }
94
95                // To prevent the for loop in the first place assign an empty array
96                // in case there are no cookies at all. Also prevents odd result when
97                // calling "get()"
98                var cookies = document.cookie ? document.cookie.split('; ') : [];
99                var rdecode = /(%[0-9A-Z]{2})+/g;
100                var i = 0;
101
102                for (; i < cookies.length; i++) {
103                    var parts = cookies[i].split('=');
104                    var cookie = parts.slice(1).join('=');
105
106                    if (cookie.charAt(0) === '"') {
107                        cookie = cookie.slice(1, -1);
108                    }
109
110                    try {
111                        var name = parts[0].replace(rdecode, decodeURIComponent);
112                        cookie = converter.read ?
113                            converter.read(cookie, name) : converter(cookie, name) ||
114                            cookie.replace(rdecode, decodeURIComponent);
115
116                        if (this.json) {
117                            try {
118                                cookie = JSON.parse(cookie);
119                            } catch (e) {}
120                        }
121
122                        if (key === name) {
123                            result = cookie;
124                            break;
125                        }
126
127                        if (!key) {
128                            result[name] = cookie;
129                        }
130                    } catch (e) {}
131                }
132
133                return result;
134            }
135
136            api.set = api;
137            api.get = function (key) {
138                return api.call(api, key);
139            };
140            api.getJSON = function () {
141                return api.apply({
142                    json: true
143                }, [].slice.call(arguments));
144            };
145            api.defaults = {};
146
147            api.remove = function (key, attributes) {
148                api(key, '', extend(attributes, {
149                    expires: -1
150                }));
151            };
152
153            api.withConverter = init;
154
155            return api;
156        }
157
158        return init(function () {});
159    }));
160
161
162}(jQuery));
163

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.