mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-08-11 07:19:43 -04:00

Former-commit-id: 2ce10066e6d7b53aa1390d7e75189f18c7b59b8a [formerly e7fe66c76d904f511bfa246c059dade2d12911b6 [formerly 40d3b58c2cf6821c94cb138f86d45c498698beed]] Former-commit-id: f3cc4ecfb825af85e764ab89d1b350cdaca4b5e2 Former-commit-id: fa761722a44f952ce2dd17b8c9944b2b4f83adbf
33 lines
1012 B
JavaScript
33 lines
1012 B
JavaScript
/**
|
|
* Simple Array.from polyfill (with Set support) from https://stackoverflow.com/a/62682524/9727685
|
|
*/
|
|
(function () {
|
|
|
|
function arrayFrom(arr, callbackFn, thisArg) {
|
|
//if you need you can uncomment the following line
|
|
//if(!arr || typeof arr == 'function')throw new Error('This function requires an array-like object - not null, undefined or a function');
|
|
|
|
var arNew = [],
|
|
k = [], // used for convert Set to an Array
|
|
i = 0;
|
|
|
|
//if you do not need a Set object support then
|
|
//you can comment or delete the following if statement
|
|
if (window.Set && arr instanceof Set) {
|
|
//we use forEach from Set object
|
|
arr.forEach(function (v) {
|
|
k.push(v)
|
|
});
|
|
arr = k;
|
|
}
|
|
|
|
for (; i < arr.length; i++)
|
|
arNew[i] = callbackFn ?
|
|
callbackFn.call(thisArg, arr[i], i, arr) :
|
|
arr[i];
|
|
|
|
return arNew;
|
|
}
|
|
//You could also use it without the following line, but it is not recommended because native function is faster.
|
|
Array.from = Array.from || arrayFrom; //We set it as polyfill
|
|
}()); |