Comparing version 0.1.1 to 0.1.2
34
index.js
@@ -26,16 +26,9 @@ 'use strict'; | ||
host || (host = []); | ||
if ( | ||
subject.length == null | ||
|| Object(subject) !== subject | ||
// `window` also has 'length' property | ||
|| 'setInterval' in subject | ||
) { | ||
host.push(subject); | ||
} else { | ||
if (isArrayLikeObject(subject)) { | ||
// IE fails on collections and <select>.options (refers to <select>) | ||
// use subject clone instead of Array.prototype.slice | ||
clonePureArray(subject, host); | ||
} else { | ||
host.push(subject); | ||
} | ||
@@ -47,2 +40,21 @@ | ||
// altered from jQuery | ||
function isArrayLikeObject (subject) { | ||
var length = subject.length; | ||
if ( | ||
typeof subject === 'function' | ||
|| Object(subject) !== subject | ||
|| typeof length !== 'number' | ||
// `window` already has a property `length` | ||
|| 'setInterval' in subject | ||
) { | ||
return false; | ||
} | ||
return length === 0 | ||
|| length > 0 && (length - 1) in subject; | ||
} | ||
/** | ||
@@ -49,0 +61,0 @@ * clone an object as a pure subject, and ignore non-number properties |
{ | ||
"name": "make-array", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Creates a real Array from almost anything.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,2 +6,7 @@ 'use strict'; | ||
var regex = /abc/; | ||
var func = function(){}; | ||
var long_func = function(a, b, c, d, e, f){}; | ||
var date = new Date; | ||
var obj = {}; | ||
@@ -15,2 +20,9 @@ var cases = [ | ||
['string', '1', ['1']], | ||
['regex', regex, [regex]], | ||
['function', func, [func]], | ||
['function with many arguments', long_func, [long_func]], | ||
['boolean', true, [true]], | ||
['false', false, [false]], | ||
['date', date, [date]], | ||
['object', obj, [obj]], | ||
['arguments 1, 2, 3', getArguments(1, 2, 3), [1, 2, 3]], | ||
@@ -17,0 +29,0 @@ ['array-like object', { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6851
115