polyfill-service
Version:
A polyfill combinator
1 lines • 4.78 kB
JSON
{"aliases":["es6","modernizr:es6array","blissfuljs","default"],"browsers":{"chrome":"<45","firefox":"4 - 31","ie":"6 - 11","ie_mob":"10 - *","opera":"*","safari":"<9","firefox_mob":"4 - *","ios_saf":"3 - 8"},"dependencies":["Object.defineProperty"],"spec":"http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.from","docs":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from","baseDir":"Array/from","hasTests":true,"rawSource":"\n// Array.from\n\n// Wrapped in IIFE to prevent leaking to global scope.\n(function () {\n\tfunction parseIterable (arraylike) {\n\t\tvar done = false;\n\t\tvar iterableResponse;\n\t\tvar tempArray = [];\n\n\t\t// if the iterable doesn't have next;\n\t\t// it is an iterable if 'next' is a function but it has not been defined on\n\t\t// the object itself.\n\t\tif (typeof arraylike.next === 'function' && arraylike.hasOwnProperty('next') === false) {\n\t\t\twhile (!done) {\n\t\t\t\titerableResponse = arraylike.next();\n\t\t\t\tif (\n\t\t\t\t\titerableResponse.hasOwnProperty('value') &&\n\t\t\t\t\titerableResponse.hasOwnProperty('done')\n\t\t\t\t) {\n\t\t\t\t\tif (iterableResponse.done === true) {\n\t\t\t\t\t\tdone = true;\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t// handle the case where the done value is not Boolean\n\t\t\t\t\t} else if (iterableResponse.done !== false) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\ttempArray.push(iterableResponse.value);\n\t\t\t\t} else {\n\n\t\t\t\t\t// it does not conform to the iterable pattern\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (done) {\n\t\t\treturn tempArray;\n\t\t} else {\n\n\t\t\t// something went wrong return false;\n\t\t\treturn false;\n\t\t}\n\n\t}\n\n\tObject.defineProperty(Array, 'from', {\n\t\tconfigurable: true,\n\t\tvalue: function from(source) {\n\t\t\t// handle non-objects\n\t\t\tif (source === undefined || source === null) {\n\t\t\t\tthrow new TypeError(source + ' is not an object');\n\t\t\t}\n\n\t\t\t// handle maps that are not functions\n\t\t\tif (1 in arguments && !(arguments[1] instanceof Function)) {\n\t\t\t\tthrow new TypeError(arguments[1] + ' is not a function');\n\t\t\t}\n\n\t\t\tvar arraylike = typeof source === 'string' ? source.split('') : Object(source);\n\t\t\tvar map = arguments[1];\n\t\t\tvar scope = arguments[2];\n\t\t\tvar array = [];\n\t\t\tvar index = -1;\n\t\t\tvar length = Math.min(Math.max(Number(arraylike.length) || 0, 0), 9007199254740991);\n\t\t\tvar value;\n\n\t\t\t// variables for rebuilding array from iterator\n\t\t\tvar arrayFromIterable;\n\n\t\t\t// if it is an iterable treat like one\n\t\t\tarrayFromIterable = parseIterable(arraylike);\n\n\t\t\t//if it is a Map or a Set then handle them appropriately\n\t\t\tif (\n\t\t\t\ttypeof arraylike.entries === 'function' &&\n\t\t\t\ttypeof arraylike.values === 'function'\n\t\t\t) {\n\t\t\t\tif (arraylike.constructor.name === 'Set' && 'values' in Set.prototype) {\n\t\t\t\t\tarrayFromIterable = parseIterable(arraylike.values());\n\t\t\t\t}\n\t\t\t\tif (arraylike.constructor.name === 'Map' && 'entries' in Map.prototype) {\n\t\t\t\t\tarrayFromIterable = parseIterable(arraylike.entries());\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (arrayFromIterable) {\n\t\t\t\tarraylike = arrayFromIterable;\n\t\t\t\tlength = arrayFromIterable.length;\n\t\t\t}\n\n\t\t\twhile (++index < length) {\n\t\t\t\tif (index in arraylike) {\n\t\t\t\t\tvalue = arraylike[index];\n\n\t\t\t\t\tarray[index] = map ? map.call(scope, value, index) : value;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tarray.length = length;\n\n\t\t\treturn array;\n\t\t},\n\t\twritable: true\n\t});\n}());\n","minSource":"!function(){function n(n){var e,t=!1,r=[];if(\"function\"==typeof n.next&&n.hasOwnProperty(\"next\")===!1)for(;!t&&(e=n.next(),e.hasOwnProperty(\"value\")&&e.hasOwnProperty(\"done\"));){if(e.done===!0){t=!0;break}if(e.done!==!1)break;r.push(e.value)}return t?r:!1}Object.defineProperty(Array,\"from\",{configurable:!0,value:function(e){if(void 0===e||null===e)throw new TypeError(e+\" is not an object\");if(1 in arguments&&!(arguments[1]instanceof Function))throw new TypeError(arguments[1]+\" is not a function\");var t,r,o=\"string\"==typeof e?e.split(\"\"):Object(e),i=arguments[1],a=arguments[2],f=[],u=-1,c=Math.min(Math.max(Number(o.length)||0,0),9007199254740991);r=n(o),\"function\"==typeof o.entries&&\"function\"==typeof o.values&&(\"Set\"===o.constructor.name&&\"values\"in Set.prototype&&(r=n(o.values())),\"Map\"===o.constructor.name&&\"entries\"in Map.prototype&&(r=n(o.entries()))),r&&(o=r,c=r.length);for(;++u<c;)u in o&&(t=o[u],f[u]=i?i.call(a,t,u):t);return f.length=c,f},writable:!0})}();","detectSource":"'from' in Array && (function () {\n\ttry {\n\t\tArray.from({ length: -Infinity });\n\n\t\treturn true;\n\t} catch (e) {\n\t\treturn false;\n\t}\n})()"}