array.from.mjs.map 5.18 KB
{"version":3,"sources":["../../sources/polyfills/array.from.ts"],"names":["toStr","Object","prototype","toString","isCallable","fn","call","toInteger","value","number","Number","isNaN","isFinite","Math","floor","abs","maxSafeInteger","pow","toLength","len","min","max","arrayFrom","arrayLike","mapFn","C","Array","items","TypeError","length","A","k","kValue"],"mappings":"AAAA;AACA;AACA;AACA;AACA,IAAMA,KAAK,GAAGC,MAAM,CAACC,SAAP,CAAiBC,QAA/B;;AACA,SAASC,UAAT,CAAoBC,EAApB,EAA0C;AACzC,SAAO,OAAOA,EAAP,KAAc,UAAd,IAA4BL,KAAK,CAACM,IAAN,CAAWD,EAAX,MAAmB,mBAAtD;AACA;;AACD,SAASE,SAAT,CAAmBC,KAAnB,EAA2C;AAC1C,MAAMC,MAAM,GAAGC,MAAM,CAACF,KAAD,CAArB;;AACA,MAAIG,KAAK,CAACF,MAAD,CAAT,EAAmB;AAClB,WAAO,CAAP;AACA;;AACD,MAAIA,MAAM,KAAK,CAAX,IAAgB,CAACG,QAAQ,CAACH,MAAD,CAA7B,EAAuC;AACtC,WAAOA,MAAP;AACA;;AACD,SAAO,CAACA,MAAM,GAAG,CAAT,GAAa,CAAb,GAAiB,CAAC,CAAnB,IAAwBI,IAAI,CAACC,KAAL,CAAWD,IAAI,CAACE,GAAL,CAASN,MAAT,CAAX,CAA/B;AACA;;AACD,IAAMO,cAAc,GAAGH,IAAI,CAACI,GAAL,CAAS,CAAT,EAAY,EAAZ,IAAkB,CAAzC;;AACA,SAASC,QAAT,CAAkBV,KAAlB,EAA0C;AACzC,MAAMW,GAAG,GAAGZ,SAAS,CAACC,KAAD,CAArB;AACA,SAAOK,IAAI,CAACO,GAAL,CAASP,IAAI,CAACQ,GAAL,CAASF,GAAT,EAAc,CAAd,CAAT,EAA2BH,cAA3B,CAAP;AACA;AACD;AACA;AACA;AACA;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASM,SAAT,CACdC,SADc,EAEdC,KAFc,EAGR;AACN;AACA;AACA,MAAMC,CAAC,GAAGC,KAAV,CAHM,CAKN;;AACA,MAAMC,KAAK,GAAG1B,MAAM,CAACsB,SAAD,CAApB,CANM,CAQN;;AACA,MAAIA,SAAS,IAAI,IAAjB,EAAuB;AACtB,UAAM,IAAIK,SAAJ,CACL,kEADK,CAAN;AAGA,GAbK,CAeN;AACA;;;AAEA,MAAI,OAAOJ,KAAP,KAAiB,WAArB,EAAkC;AACjC;AACA;AACA,QAAI,CAACpB,UAAU,CAACoB,KAAD,CAAf,EAAwB;AACvB,YAAM,IAAII,SAAJ,CACL,mEADK,CAAN;AAGA;AACD,GA1BK,CA4BN;AACA;;;AACA,MAAMT,GAAG,GAAGD,QAAQ,CAACS,KAAK,CAACE,MAAP,CAApB,CA9BM,CAgCN;AACA;AACA;AACA;;AACA,MAAMC,CAAC,GAAG1B,UAAU,CAACqB,CAAD,CAAV,GAAgBxB,MAAM,CAAC,IAAIwB,CAAJ,CAAMN,GAAN,CAAD,CAAtB,GAAqC,IAAIO,KAAJ,CAAUP,GAAV,CAA/C,CApCM,CAsCN;;AACA,MAAIY,CAAC,GAAG,CAAR,CAvCM,CAwCN;;AACA,MAAIC,MAAJ;;AACA,SAAOD,CAAC,GAAGZ,GAAX,EAAgB;AACfa,IAAAA,MAAM,GAAGL,KAAK,CAACI,CAAD,CAAd;;AACA,QAAIP,KAAJ,EAAW;AACVM,MAAAA,CAAC,CAACC,CAAD,CAAD,GAAOP,KAAK,CAACQ,MAAD,EAASD,CAAT,CAAZ;AACA,KAFD,MAEO;AACND,MAAAA,CAAC,CAACC,CAAD,CAAD,GAAOC,MAAP;AACA;;AACDD,IAAAA,CAAC,IAAI,CAAL;AACA,GAlDK,CAmDN;;;AACAD,EAAAA,CAAC,CAACD,MAAF,GAAWV,GAAX,CApDM,CAqDN;;AACA,SAAOW,CAAP;AACA","sourcesContent":["/**\n * @source {https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from#Polyfill}\n * but without thisArg (too hard to type, no need to `this`)\n */\nconst toStr = Object.prototype.toString;\nfunction isCallable(fn: unknown): boolean {\n\treturn typeof fn === \"function\" || toStr.call(fn) === \"[object Function]\";\n}\nfunction toInteger(value: unknown): number {\n\tconst number = Number(value);\n\tif (isNaN(number)) {\n\t\treturn 0;\n\t}\n\tif (number === 0 || !isFinite(number)) {\n\t\treturn number;\n\t}\n\treturn (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));\n}\nconst maxSafeInteger = Math.pow(2, 53) - 1;\nfunction toLength(value: unknown): number {\n\tconst len = toInteger(value);\n\treturn Math.min(Math.max(len, 0), maxSafeInteger);\n}\n/**\n * Creates an array from an iterable object.\n * @param iterable An iterable object to convert to an array.\n */\nexport default function arrayFrom<T>(iterable: Iterable<T> | ArrayLike<T>): T[];\n/**\n * Creates an array from an iterable object.\n * @param iterable An iterable object to convert to an array.\n * @param mapfn A mapping function to call on every element of the array.\n * @param thisArg Value of 'this' used to invoke the mapfn.\n */\nexport default function arrayFrom<T, U>(\n\tarrayLike: Iterable<T> | ArrayLike<T>,\n\tmapFn?: (v: T, k: number) => U\n): U[] {\n\t// 1. Let C be the this value.\n\t// edit(@eps1lon): we're not calling it as Array.from\n\tconst C = Array;\n\n\t// 2. Let items be ToObject(arrayLike).\n\tconst items = Object(arrayLike);\n\n\t// 3. ReturnIfAbrupt(items).\n\tif (arrayLike == null) {\n\t\tthrow new TypeError(\n\t\t\t\"Array.from requires an array-like object - not null or undefined\"\n\t\t);\n\t}\n\n\t// 4. If mapfn is undefined, then let mapping be false.\n\t// const mapFn = arguments.length > 1 ? arguments[1] : void undefined;\n\n\tif (typeof mapFn !== \"undefined\") {\n\t\t// 5. else\n\t\t// 5. a If IsCallable(mapfn) is false, throw a TypeError exception.\n\t\tif (!isCallable(mapFn)) {\n\t\t\tthrow new TypeError(\n\t\t\t\t\"Array.from: when provided, the second argument must be a function\"\n\t\t\t);\n\t\t}\n\t}\n\n\t// 10. Let lenValue be Get(items, \"length\").\n\t// 11. Let len be ToLength(lenValue).\n\tconst len = toLength(items.length);\n\n\t// 13. If IsConstructor(C) is true, then\n\t// 13. a. Let A be the result of calling the [[Construct]] internal method\n\t// of C with an argument list containing the single item len.\n\t// 14. a. Else, Let A be ArrayCreate(len).\n\tconst A = isCallable(C) ? Object(new C(len)) : new Array(len);\n\n\t// 16. Let k be 0.\n\tlet k = 0;\n\t// 17. Repeat, while k < len… (also steps a - h)\n\tlet kValue;\n\twhile (k < len) {\n\t\tkValue = items[k];\n\t\tif (mapFn) {\n\t\t\tA[k] = mapFn(kValue, k);\n\t\t} else {\n\t\t\tA[k] = kValue;\n\t\t}\n\t\tk += 1;\n\t}\n\t// 18. Let putStatus be Put(A, \"length\", len, true).\n\tA.length = len;\n\t// 20. Return A.\n\treturn A;\n}\n"],"file":"array.from.mjs"}