PageSourceSearch

https://cdn4.hola.org/util/es6_shim.js

js hola.org collected 2026-09-24 10:16:26 UTC 9,164 bytes, 288 lines download raw bytes

1// LICENSE_CODE ZON ISC
2'use strict'; /*jslint node:true, browser:true, -W103*/
3(function(){
4var define;
5var is_node = typeof module=='object' && module.exports && module.children;
6if (!is_node)
7    define = self.define;
8else
9    define = function(setup){ module.exports = setup(); };
10define(function(){
11var E = {t: {}};
12// shim for ES6/7. Need to support >=IE9 (including IE9 quirks mode),
13// Chrome, FF, Safari, Opera, and old android browsers.
14function add_prop(obj, prop, fn){
15    if (obj[prop])
16        return;
17    Object.defineProperty(obj, prop,
18        {enumerable: false, writable: true, configurable: true, value: fn});
19}
20
21E.t.object_assign = function(obj){
22    for (var i=1; i<arguments.length; i++)
23    {
24        var source = arguments[i];
25        if (!source)
26            continue;
27        for (var prop in source)
28        {
29            if (source.hasOwnProperty(prop))
30                obj[prop] = source[prop];
31        }
32    }
33    return obj;
34};
35add_prop(Object, 'assign', E.t.object_assign);
36E.t.object_values = function(obj){
37    if (obj==null)
38        throw new TypeError('Cannot convert undefined or null to object');
39    var res = [];
40    for (var prop in obj)
41    {
42        if (obj.hasOwnProperty(prop))
43            res.push(obj[prop]);
44    }
45    return res;
46};
47add_prop(Object, 'values', E.t.object_values);
48E.t.object_entries = function(obj){
49    if (obj==null)
50        throw new TypeError('Cannot convert undefined or null to object');
51    var res = [];
52    for (var prop in obj)
53    {
54        if (obj.hasOwnProperty(prop))
55            res.push([prop, obj[prop]]);
56    }
57    return res;
58};
59add_prop(Object, 'entries', E.t.object_entries);
60var can_set_proto = {__proto__: []} instanceof Array;
61E.t.object_setPrototypeOf = function(obj, proto){
62    if (can_set_proto)
63        obj.__proto__ = proto;
64    else // IE9/IE10
65    {
66        for (var prop in proto)
67            obj[prop] = proto[prop];
68    }
69    return true;
70};
71add_prop(Object, 'setPrototypeOf', E.t.object_setPrototypeOf);
72
73E.t.string_startsWith = function(head){
74    head = ''+head;
75    return !head || this.slice(0, head.length)===head;
76};
77add_prop(String.prototype, 'startsWith', E.t.string_startsWith);
78E.t.string_endsWith = function(tail){
79    tail = ''+tail;
80    return !tail || this.slice(-tail.length)==tail;
81};
82add_prop(String.prototype, 'endsWith', E.t.string_endsWith);
83E.t.string_includes = function(search, index){
84    return this.indexOf(search, index)>=0; };
85add_prop(String.prototype, 'includes', E.t.string_includes);
86E.t.string_repeat = function(n){
87    var s = '';
88    for (var i=0; i<n; i++)
89        s += this;
90    return s;
91};
92add_prop(String.prototype, 'repeat', E.t.string_repeat);
93E.t.string_trimLeft = function(){ return this.replace(/^\s+/, ''); };
94add_prop(String.prototype, 'trimLeft', E.t.string_trimLeft);
95E.t.string_trimRight = function(){ return this.replace(/\s+$/, ''); };
96add_prop(String.prototype, 'trimRight', E.t.string_trimRight);
97E.t.string_padStart = function(len, val){
98    val = val||' ';
99    var l = len-this.length;
100    return l<=0 ? this : val.repeat(Math.ceil(l/val.length)).slice(0, l)+this;
101};
102add_prop(String.prototype, 'padStart', E.t.string_padStart);
103E.t.string_padEnd = function(len, val){
104    val = val||' ';
105    var l = len-this.length;
106    return l<=0 ? this : this+val.repeat(Math.ceil(l/val.length)).slice(0, l);
107};
108add_prop(String.prototype, 'padEnd', E.t.string_padEnd);
109
110E.t.array_includes = function(search, index){
111    return this.indexOf(search, index)>=0; };
112add_prop(Array.prototype, 'includes', E.t.array_includes);
113E.t.array_find = function(fn, this_arg){
114    var a = this, value;
115    for (var i=0; i<a.length; i++)
116    {
117        value = a[i];
118        if (i in a && fn.call(this_arg, value, i, a))
119            return value;
120    }
121};
122add_prop(Array.prototype, 'find', E.t.array_find);
123E.t.array_findIndex = function(fn, this_arg){
124    var a = this, value;
125    for (var i=0; i<a.length; i++)
126    {
127        value = a[i];
128        if (i in a && fn.call(this_arg, value, i, a))
129            return i;
130    }
131    return -1;
132};
133add_prop(Array.prototype, 'findIndex', E.t.array_findIndex);
134E.t.array_of = function(){ return Array.prototype.slice.call(arguments); };
135add_prop(Array, 'of', E.t.array_of);
136E.t.array_from = function(a, fn, _this){
137    a = Array.prototype.slice.call(a);
138    return !fn ? a : a.map(fn, _this);
139};
140add_prop(Array, 'from', E.t.array_from);
141
142E.t.arraybuffer_slice = function(begin, end){
143    begin = begin|0;
144    end = (end==null ? this.byteLength : end)|0;
145    if (begin<0)
146        begin += this.byteLength;
147    if (end<0)
148        end += this.byteLength;
149    begin = Math.min(Math.max(0, begin), this.byteLength);
150    end = Math.min(Math.max(0, end), this.byteLength);
151    if (end-begin<=0)
152        return new ArrayBuffer(0);
153    var result = new ArrayBuffer(end-begin);
154    var resultBytes = new Uint8Array(result);
155    var sourceBytes = new Uint8Array(this, begin, end-begin);
156    resultBytes.set(sourceBytes);
157    return result;
158};
159if (typeof ArrayBuffer!='undefined')
160    add_prop(ArrayBuffer.prototype, 'slice', E.t.arraybuffer_slice);
161
162add_prop(Number, 'EPSILON', Math.pow(2, -52));
163E.t.number_isFinite = function(x){ return typeof x=='number' && isFinite(x); };
164add_prop(Number, 'isFinite', E.t.number_isFinite); // missing in IE (<edge)
165E.t.math_sign = function(x){
166    x = +x;
167    return x!==x ? NaN : !x ? x : x<0 ? -1 : 1;
168};
169add_prop(Math, 'sign', E.t.math_sign);
170E.t.math_trunc = function(x){
171    x = +x;
172    return x!==x ? NaN : x<0 ? Math.ceil(x) : Math.floor(x);
173};
174add_prop(Math, 'trunc', E.t.math_trunc);
175E.t.math_imul = function(x, y){
176    var hix = (x>>>16)&0xffff;
177    var lox = x&0xffff;
178    var hiy = (y>>>16)&0xffff;
179    var loy = y&0xffff;
180    return lox*loy+(((hix*loy + lox*hiy)<<16)>>>0)|0;
181};
182add_prop(Math, 'imul', E.t.math_imul);
183
184function ie9_console(){
185    if (typeof window!='object')
186        return;
187    if (window.console)
188    {
189        if (!window.console.debug) // ie9 has no debug() in native console
190            window.console.debug = window.console.info;
191        return;
192    }
193    var console = window.console = {};
194    ['assert', 'clear', 'count', 'debug', 'dir', 'dirxml',
195        'error', 'exception', 'group', 'groupCollapsed', 'groupEnd', 'info',
196        'log', 'markTimeline', 'profile', 'profiles', 'profileEnd', 'show',
197        'table', 'time', 'timeEnd', 'timeline', 'timelineEnd', 'timeStamp',
198        'trace', 'warn'
199    ].forEach(function(p){ console[p] = function(){}; });
200    ['memory'].forEach(function(p){ console[p] = {}; });
201}
202ie9_console();
203
204function ie9_location_origin(){
205    if (typeof window!='object' || !window.location ||
206        'origin' in window.location)
207    {
208        return;
209    }
210    var location = window.location;
211    var default_ports = {'http:': 80, 'https:': 443};
212    var port = location.port;
213    if (default_ports[location.protocol]==port) // omit default protocol port
214        port = null;
215    location.origin = location.protocol+'//'+location.hostname+
216        (port ? ':'+port : '');
217}
218ie9_location_origin();
219
220function element_matches(){
221    if (typeof Element!='object' && typeof Element!='function' ||
222        Element.prototype.matches)
223    {
224        return;
225    }
226    Element.prototype.matches = Element.prototype.matchesSelector ||
227        Element.prototype.mozMatchesSelector ||
228        Element.prototype.msMatchesSelector ||
229        Element.prototype.oMatchesSelector ||
230        Element.prototype.webkitMatchesSelector;
231    if (Element.prototype.matches)
232        return;
233    Element.prototype.matches = function(s){
234        var matches = (this.document||this.ownerDocument).querySelectorAll(s);
235        var i = matches.length;
236        while (--i>=0 && matches.item(i)!==this);
237        return i>-1;
238    };
239}
240element_matches();
241
242function ie_edge_closest(){
243    if (typeof Element!='object' && typeof Element!='function' ||
244        Element.prototype.closest)
245    {
246        return;
247    }
248    Element.prototype.closest = function(selector){
249        var el = this;
250        while (el)
251        {
252            if (el.matches(selector))
253                return el;
254            el = el.parentElement;
255        }
256        return null;
257    };
258}
259ie_edge_closest();
260
261E.t.function_name = function(){
262    // toString() on IE is very fast compared to chrome ~260k/s vs 26k/s on
263    // a small function.
264    // the regex is faster than a simple loop to extract non whitespace
265    // between 'function ' and '('
266    var n = this.toString().match(/^function\s+([^\s(]+)/);
267    return (n && n[1])||'';
268};
269function ie_function_name(){
270    if (ie_function_name.name=='ie_function_name')
271        return;
272    // IE doesn't support function.name (Edge does)
273    Object.defineProperty(Function.prototype, 'name', {enumerable: false,
274        configurable: false, get: E.t.function_name});
275}
276ie_function_name();
277
278// android api 18 and below
279function android18_animFrame(){
280    if (typeof window!='object' || window.requestAnimationFrame)
281        return;
282    var start = Date.now();
283    window.requestAnimationFrame = function(cb){
284        setTimeout(function(){ cb(Date.now()-start); }, 16); };
285}
286android18_animFrame();
287
288return E; }); }());

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.