array.from
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -1,84 +0,83 @@ | ||
/*! http://mths.be/array-from v0.2.0 by @mathias */ | ||
if (!Array.from) { | ||
(function() { | ||
'use strict'; | ||
var defineProperty = (function() { | ||
// IE 8 only supports `Object.defineProperty` on DOM elements. | ||
try { | ||
var object = {}; | ||
var $defineProperty = Object.defineProperty; | ||
var result = $defineProperty(object, object, object) && $defineProperty; | ||
} catch(error) {} | ||
return result || function put(object, key, descriptor) { | ||
object[key] = descriptor.value; | ||
}; | ||
}()); | ||
var toStr = Object.prototype.toString; | ||
var isCallable = function(fn) { | ||
// In a perfect world, the `typeof` check would be sufficient. However, | ||
// in Chrome 1–12, `typeof /x/ == 'object'`, and in IE 6–8 | ||
// `typeof alert == 'object'` and similar for other host objects. | ||
return typeof fn == 'function' || toStr.call(fn) == '[object Function]'; | ||
/*! https://mths.be/array-from v0.2.0 by @mathias */ | ||
(function() { | ||
'use strict'; | ||
var defineProperty = (function() { | ||
// IE 8 only supports `Object.defineProperty` on DOM elements. | ||
try { | ||
var object = {}; | ||
var $defineProperty = Object.defineProperty; | ||
var result = $defineProperty(object, object, object) && $defineProperty; | ||
} catch(error) {} | ||
return result || function put(object, key, descriptor) { | ||
object[key] = descriptor.value; | ||
}; | ||
var toInteger = function(value) { | ||
var number = Number(value); | ||
if (isNaN(number)) { | ||
return 0; | ||
}()); | ||
var toStr = Object.prototype.toString; | ||
var isCallable = function(fn) { | ||
// In a perfect world, the `typeof` check would be sufficient. However, | ||
// in Chrome 1–12, `typeof /x/ == 'object'`, and in IE 6–8 | ||
// `typeof alert == 'object'` and similar for other host objects. | ||
return typeof fn == 'function' || toStr.call(fn) == '[object Function]'; | ||
}; | ||
var toInteger = function(value) { | ||
var number = Number(value); | ||
if (isNaN(number)) { | ||
return 0; | ||
} | ||
if (number == 0 || !isFinite(number)) { | ||
return number; | ||
} | ||
return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number)); | ||
}; | ||
var maxSafeInteger = Math.pow(2, 53) - 1; | ||
var toLength = function(value) { | ||
var len = toInteger(value); | ||
return Math.min(Math.max(len, 0), maxSafeInteger); | ||
}; | ||
var from = function from(arrayLike) { | ||
var C = this; | ||
if (arrayLike == null) { | ||
throw new TypeError('`Array.from` requires an array-like object, not `null` or `undefined`'); | ||
} | ||
var items = Object(arrayLike); | ||
var mapping = arguments.length > 1; | ||
var mapFn, T; | ||
if (arguments.length > 1) { | ||
mapFn = arguments[1]; | ||
if (!isCallable(mapFn)) { | ||
throw new TypeError('When provided, the second argument to `Array.from` must be a function'); | ||
} | ||
if (number == 0 || !isFinite(number)) { | ||
return number; | ||
if (arguments.length > 2) { | ||
T = arguments[2]; | ||
} | ||
return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number)); | ||
}; | ||
var maxSafeInteger = Math.pow(2, 53) - 1; | ||
var toLength = function(value) { | ||
var len = toInteger(value); | ||
return Math.min(Math.max(len, 0), maxSafeInteger); | ||
}; | ||
var from = function(arrayLike) { | ||
var C = this; | ||
if (arrayLike == null) { | ||
throw new TypeError('`Array.from` requires an array-like object, not `null` or `undefined`'); | ||
} | ||
var items = Object(arrayLike); | ||
var mapping = arguments.length > 1; | ||
} | ||
var mapFn, T; | ||
if (arguments.length > 1) { | ||
mapFn = arguments[1]; | ||
if (!isCallable(mapFn)) { | ||
throw new TypeError('When provided, the second argument to `Array.from` must be a function'); | ||
} | ||
if (arguments.length > 2) { | ||
T = arguments[2]; | ||
} | ||
var len = toLength(items.length); | ||
var A = isCallable(C) ? Object(new C(len)) : new Array(len); | ||
var k = 0; | ||
var kValue, mappedValue; | ||
while (k < len) { | ||
kValue = items[k]; | ||
if (mapFn) { | ||
mappedValue = typeof T == 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k); | ||
} else { | ||
mappedValue = kValue; | ||
} | ||
var len = toLength(items.length); | ||
var A = isCallable(C) ? Object(new C(len)) : new Array(len); | ||
var k = 0; | ||
var kValue, mappedValue; | ||
while (k < len) { | ||
kValue = items[k]; | ||
if (mapFn) { | ||
mappedValue = typeof T == 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k); | ||
} else { | ||
mappedValue = kValue; | ||
} | ||
defineProperty(A, k, { | ||
'value': mappedValue, | ||
'configurable': true, | ||
'enumerable': true | ||
}); | ||
++k; | ||
} | ||
A.length = len; | ||
return A; | ||
}; | ||
defineProperty(Array, 'from', { | ||
'value': from, | ||
'configurable': true, | ||
'writable': true | ||
}); | ||
}()); | ||
} | ||
defineProperty(A, k, { | ||
'value': mappedValue, | ||
'configurable': true, | ||
'enumerable': true, | ||
'writable': true | ||
}); | ||
++k; | ||
} | ||
A.length = len; | ||
return A; | ||
}; | ||
defineProperty(Array, 'from', { | ||
'value': from, | ||
'configurable': true, | ||
'writable': true | ||
}); | ||
}()); |
@@ -1,2 +0,2 @@ | ||
Copyright Mathias Bynens <http://mathiasbynens.be/> | ||
Copyright Mathias Bynens <https://mathiasbynens.be/> | ||
@@ -3,0 +3,0 @@ Permission is hereby granted, free of charge, to any person obtaining |
{ | ||
"name": "array.from", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "A robust & optimized `Array.from` polyfill, based on the ECMAScript 6 specification.", | ||
"homepage": "http://mths.be/array-from", | ||
"main": "array-from.js", | ||
"homepage": "https://mths.be/array-from", | ||
"main": "detect.js", | ||
"keywords": [ | ||
@@ -13,12 +13,18 @@ "array", | ||
], | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "http://mths.be/mit" | ||
} | ||
], | ||
"license": "MIT", | ||
"author": { | ||
"name": "Mathias Bynens", | ||
"url": "http://mathiasbynens.be/" | ||
"url": "https://mathiasbynens.be/" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Mathias Bynens", | ||
"url": "https://mathiasbynens.be/" | ||
}, | ||
{ | ||
"name": "Jordan Harband", | ||
"email": "ljharb@gmail.com", | ||
"url": "http://ljharb.codes" | ||
} | ||
], | ||
"repository": { | ||
@@ -28,8 +34,7 @@ "type": "git", | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/mathiasbynens/Array.from/issues" | ||
}, | ||
"bugs": "https://github.com/mathiasbynens/Array.from/issues", | ||
"files": [ | ||
"LICENSE-MIT.txt", | ||
"array-from.js" | ||
"array-from.js", | ||
"detect.js" | ||
], | ||
@@ -44,5 +49,5 @@ "directories": { | ||
"devDependencies": { | ||
"covert": "~1.0.0", | ||
"tape": "~2.14.0" | ||
"covert": "^1.1.0", | ||
"tape": "^4.2.2" | ||
} | ||
} |
# ES6 `Array.from` polyfill [![Build status](https://travis-ci.org/mathiasbynens/Array.from.svg?branch=master)](https://travis-ci.org/mathiasbynens/Array.from) | ||
A robust & optimized ES3-compatible polyfill for [the `Array.from` method in ECMAScript 6](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.from). | ||
A robust & optimized ES3-compatible polyfill for [the `Array.from` method in ECMAScript 6](http://ecma-international.org/ecma-262/6.0/#sec-array.from). | ||
@@ -13,3 +13,3 @@ ## Installation | ||
Via [npm](http://npmjs.org/): | ||
Via [npm](https://www.npmjs.com/): | ||
@@ -20,3 +20,3 @@ ```bash | ||
Then, in [Node.js](http://nodejs.org/): | ||
Then, in [Node.js](https://nodejs.org/): | ||
@@ -35,6 +35,6 @@ ```js | ||
|---| | ||
| [Mathias Bynens](http://mathiasbynens.be/) | | ||
| [Mathias Bynens](https://mathiasbynens.be/) | | ||
## License | ||
This polyfill is available under the [MIT](http://mths.be/mit) license. | ||
This polyfill is available under the [MIT](https://mths.be/mit) license. |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
5917
6
84
1