EmbyCrackedClient/web/modules/polyfills/array.js
2025-06-25 11:46:04 +08:00

1 line
No EOL
2.2 KiB
JavaScript

Array.prototype.filter||(Array.prototype.filter=function(fun){if(null==this)throw new TypeError;var t=Object(this),len=t.length>>>0;if("function"!=typeof fun)throw new TypeError;var val,res=[],thisp=arguments[1];for(let i=0;i<len;i++)i in t&&(val=t[i],fun.call(thisp,val,i,t))&&res.push(val);return res}),Array.prototype.includes||Object.defineProperty(Array.prototype,"includes",{value:function(searchElement,fromIndex){if(null==this)throw new TypeError('"this" is null or not defined');var o=Object(this),len=o.length>>>0;if(0!=len){var x,y,fromIndex=0|fromIndex;let k=Math.max(0<=fromIndex?fromIndex:len-Math.abs(fromIndex),0);for(;k<len;){if((x=o[k])===(y=searchElement)||"number"==typeof x&&"number"==typeof y&&isNaN(x)&&isNaN(y))return!0;k++}}return!1}}),Array.isArray||(Array.isArray=function(arg){return"[object Array]"===Object.prototype.toString.call(arg)}),Array.prototype.some||(Array.prototype.some=function(fun,thisArg){if(null==this)throw new TypeError("Array.prototype.some called on null or undefined");if("function"!=typeof fun)throw new TypeError;var t=Object(this),len=t.length>>>0;for(let i=0;i<len;i++)if(i in t&&fun.call(thisArg,t[i],i,t))return!0;return!1}),Array.from||(Array.from=(()=>{function isCallable(fn){return"function"==typeof fn||"[object Function]"===toStr.call(fn)}function toLength(value){return value=(value=>(value=Number(value),isNaN(value)?0:0!==value&&isFinite(value)?(0<value?1:-1)*Math.floor(Math.abs(value)):value))(value),Math.min(Math.max(value,0),maxSafeInteger)}let toStr=Object.prototype.toString,maxSafeInteger=Math.pow(2,53)-1;return function(arrayLike){var items=Object(arrayLike);if(null==arrayLike)throw new TypeError("Array.from requires an array-like object - not null or undefined");var mapFn=1<arguments.length?arguments[1]:void 0;let T;if(void 0!==mapFn){if(!isCallable(mapFn))throw new TypeError("Array.from: when provided, the second argument must be a function");2<arguments.length&&(T=arguments[2])}if(items instanceof Set){let array=[];return items.forEach(v=>array.push(v)),array}var kValue,len=toLength(items.length),A=isCallable(this)?Object(new this(len)):new Array(len);let k=0;for(;k<len;)kValue=items[k],A[k]=mapFn?void 0===T?mapFn(kValue,k):mapFn.call(T,kValue,k):kValue,k+=1;return A.length=len,A}})());