PageSourceSearch

https://novonordiskfonden.dk//app/plugins/embed-power-bi/assets/js/url-search-params-polyfill.js

js novonordiskfonden.dk collected 2026-09-24 08:41:46 UTC 9,168 bytes, 314 lines download raw bytes

1/**
2 *
3 *
4 * @author Jerry Bendy <[email protected]>
5 * @licence MIT
6 *
7 */
8
9(function(self) {
10    'use strict';
11
12    var nativeURLSearchParams = self.URLSearchParams ? self.URLSearchParams : null,
13        isSupportObjectConstructor = nativeURLSearchParams && (new nativeURLSearchParams({a: 1})).toString() === 'a=1',
14        // There is a bug in safari 10.1 (and earlier) that incorrectly decodes `%2B` as an empty space and not a plus.
15        decodesPlusesCorrectly = nativeURLSearchParams && (new nativeURLSearchParams('s=%2B').get('s') === '+'),
16        __URLSearchParams__ = "__URLSearchParams__",
17        // Fix bug in Edge which cannot encode ' &' correctly
18        encodesAmpersandsCorrectly = nativeURLSearchParams ? (function() {
19            var ampersandTest = new nativeURLSearchParams();
20            ampersandTest.append('s', ' &');
21            return ampersandTest.toString() === 's=+%26';
22        })() : true,
23        prototype = URLSearchParamsPolyfill.prototype,
24        iterable = !!(self.Symbol && self.Symbol.iterator);
25
26    if (nativeURLSearchParams && isSupportObjectConstructor && decodesPlusesCorrectly && encodesAmpersandsCorrectly) {
27        return;
28    }
29
30
31    /**
32     * Make a URLSearchParams instance
33     *
34     * @param {object|string|URLSearchParams} search
35     * @constructor
36     */
37    function URLSearchParamsPolyfill(search) {
38        search = search || "";
39
40        // support construct object with another URLSearchParams instance
41        if (search instanceof URLSearchParams || search instanceof URLSearchParamsPolyfill) {
42            search = search.toString();
43        }
44        this [__URLSearchParams__] = parseToDict(search);
45    }
46
47
48    /**
49     * Appends a specified key/value pair as a new search parameter.
50     *
51     * @param {string} name
52     * @param {string} value
53     */
54    prototype.append = function(name, value) {
55        appendTo(this [__URLSearchParams__], name, value);
56    };
57
58    /**
59     * Deletes the given search parameter, and its associated value,
60     * from the list of all search parameters.
61     *
62     * @param {string} name
63     */
64    prototype.delete = function(name) {
65        delete this [__URLSearchParams__] [name];
66    };
67
68    /**
69     * Returns the first value associated to the given search parameter.
70     *
71     * @param {string} name
72     * @returns {string|null}
73     */
74    prototype.get = function(name) {
75        var dict = this [__URLSearchParams__];
76        return name in dict ? dict[name][0] : null;
77    };
78
79    /**
80     * Returns all the values association with a given search parameter.
81     *
82     * @param {string} name
83     * @returns {Array}
84     */
85    prototype.getAll = function(name) {
86        var dict = this [__URLSearchParams__];
87        return name in dict ? dict [name].slice(0) : [];
88    };
89
90    /**
91     * Returns a Boolean indicating if such a search parameter exists.
92     *
93     * @param {string} name
94     * @returns {boolean}
95     */
96    prototype.has = function(name) {
97        return name in this [__URLSearchParams__];
98    };
99
100    /**
101     * Sets the value associated to a given search parameter to
102     * the given value. If there were several values, delete the
103     * others.
104     *
105     * @param {string} name
106     * @param {string} value
107     */
108    prototype.set = function set(name, value) {
109        this [__URLSearchParams__][name] = ['' + value];
110    };
111
112    /**
113     * Returns a string containg a query string suitable for use in a URL.
114     *
115     * @returns {string}
116     */
117    prototype.toString = function() {
118        var dict = this[__URLSearchParams__], query = [], i, key, name, value;
119        for (key in dict) {
120            name = encode(key);
121            for (i = 0, value = dict[key]; i < value.length; i++) {
122                query.push(name + '=' + encode(value[i]));
123            }
124        }
125        return query.join('&');
126    };
127
128    // There is a bug in Safari 10.1 and `Proxy`ing it is not enough.
129    var forSureUsePolyfill = !decodesPlusesCorrectly;
130    var useProxy = (!forSureUsePolyfill && nativeURLSearchParams && !isSupportObjectConstructor && self.Proxy)
131    /*
132     * Apply polifill to global object and append other prototype into it
133     */
134    self.URLSearchParams = useProxy ?
135        // Safari 10.0 doesn't support Proxy, so it won't extend URLSearchParams on safari 10.0
136        new Proxy(nativeURLSearchParams, {
137            construct: function(target, args) {
138                return new target((new URLSearchParamsPolyfill(args[0]).toString()));
139            }
140        }) :
141        URLSearchParamsPolyfill;
142
143
144    var USPProto = self.URLSearchParams.prototype;
145
146    USPProto.polyfill = true;
147
148    /**
149     *
150     * @param {function} callback
151     * @param {object} thisArg
152     */
153    USPProto.forEach = USPProto.forEach || function(callback, thisArg) {
154        var dict = parseToDict(this.toString());
155        Object.getOwnPropertyNames(dict).forEach(function(name) {
156            dict[name].forEach(function(value) {
157                callback.call(thisArg, value, name, this);
158            }, this);
159        }, this);
160    };
161
162    /**
163     * Sort all name-value pairs
164     */
165    USPProto.sort = USPProto.sort || function() {
166        var dict = parseToDict(this.toString()), keys = [], k, i, j;
167        for (k in dict) {
168            keys.push(k);
169        }
170        keys.sort();
171
172        for (i = 0; i < keys.length; i++) {
173            this.delete(keys[i]);
174        }
175        for (i = 0; i < keys.length; i++) {
176            var key = keys[i], values = dict[key];
177            for (j = 0; j < values.length; j++) {
178                this.append(key, values[j]);
179            }
180        }
181    };
182
183    /**
184     * Returns an iterator allowing to go through all keys of
185     * the key/value pairs contained in this object.
186     *
187     * @returns {function}
188     */
189    USPProto.keys = USPProto.keys || function() {
190        var items = [];
191        this.forEach(function(item, name) {
192            items.push(name);
193        });
194        return makeIterator(items);
195    };
196
197    /**
198     * Returns an iterator allowing to go through all values of
199     * the key/value pairs contained in this object.
200     *
201     * @returns {function}
202     */
203    USPProto.values = USPProto.values || function() {
204        var items = [];
205        this.forEach(function(item) {
206            items.push(item);
207        });
208        return makeIterator(items);
209    };
210
211    /**
212     * Returns an iterator allowing to go through all key/value
213     * pairs contained in this object.
214     *
215     * @returns {function}
216     */
217    USPProto.entries = USPProto.entries || function() {
218        var items = [];
219        this.forEach(function(item, name) {
220            items.push([name, item]);
221        });
222        return makeIterator(items);
223    };
224
225
226    if (iterable) {
227        USPProto[self.Symbol.iterator] = USPProto[self.Symbol.iterator] || USPProto.entries;
228    }
229
230
231    function encode(str) {
232        var replace = {
233            '!': '%21',
234            "'": '%27',
235            '(': '%28',
236            ')': '%29',
237            '~': '%7E',
238            '%20': '+',
239            '%00': '\x00'
240        };
241        return encodeURIComponent(str).replace(/[!'\(\)~]|%20|%00/g, function(match) {
242            return replace[match];
243        });
244    }
245
246    function decode(str) {
247        return decodeURIComponent(str.replace(/\+/g, ' '));
248    }
249
250    function makeIterator(arr) {
251        var iterator = {
252            next: function() {
253                var value = arr.shift();
254                return {done: value === undefined, value: value};
255            }
256        };
257
258        if (iterable) {
259            iterator[self.Symbol.iterator] = function() {
260                return iterator;
261            };
262        }
263
264        return iterator;
265    }
266
267    function parseToDict(search) {
268        var dict = {};
269
270        if (typeof search === "object") {
271            for (var key in search) {
272                if (search.hasOwnProperty(key)) {
273                    appendTo(dict, key, search[key])
274                }
275            }
276
277        } else {
278            // remove first '?'
279            if (search.indexOf("?") === 0) {
280                search = search.slice(1);
281            }
282
283            var pairs = search.split("&");
284            for (var j = 0; j < pairs.length; j++) {
285                var value = pairs [j],
286                    index = value.indexOf('=');
287
288                if (-1 < index) {
289                    appendTo(dict, decode(value.slice(0, index)), decode(value.slice(index + 1)));
290
291                } else {
292                    if (value) {
293                        appendTo(dict, decode(value), '');
294                    }
295                }
296            }
297        }
298
299        return dict;
300    }
301
302    function appendTo(dict, name, value) {
303        var val = typeof value === 'string' ? value : (
304            value !== null && value !== undefined && typeof value.toString === 'function' ? value.toString() : JSON.stringify(value)
305        )
306
307        if (name in dict) {
308            dict[name].push(val);
309        } else {
310            dict[name] = [val];
311        }
312    }
313
314})(typeof global !== 'undefined' ? global : (typeof window !== 'undefined' ? window : this));

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.