🚀 Big News:Socket Has Acquired Secure Annex.Learn More
Socket
Book a DemoSign in
Socket

make-array

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

make-array - npm Package Compare versions

Comparing version
1.0.3
to
1.0.5
+24
-19
index.js

@@ -6,3 +6,3 @@ // @param {all} subject

// @param {Array=} host
export default function makeArray (subject, host){
module.exports = function (subject, host) {
// false -> [false]

@@ -12,28 +12,33 @@ // null -> []

if (subject === undefined || subject === null) {
return host || [];
return host || []
}
// if is already an array
if(Object.prototype.toString.call(subject) === '[object Array]'){
if (isArray(subject)) {
return host
? host.concat(subject)
: subject;
: subject
}
host || (host = []);
host || (host = [])
if (isArrayLikeObject(subject)) {
// IE fails on collections and <select>.options (refers to <select>)
// use subject clone instead of Array.prototype.slice
clonePureArray(subject, host);
clonePureArray(subject, host)
} else {
host.push(subject);
host.push(subject)
}
return host;
};
return host
}
var toString = Object.prototype.toString
function isArray (subject) {
return toString.call(subject) === '[object Array]'
}
// altered from jQuery
function isArrayLikeObject (subject) {
var length = subject.length;
var length = subject.length

@@ -47,7 +52,7 @@ if (

) {
return false;
return false
}
return length === 0
|| length > 0 && (length - 1) in subject;
|| length > 0 && (length - 1) in subject
}

@@ -60,11 +65,11 @@

*/
function clonePureArray(subject, host){
var i = subject.length;
var start = host.length;
function clonePureArray (subject, host) {
var i = subject.length
var start = host.length
while(i --){
host[start + i] = subject[i];
while (i --) {
host[start + i] = subject[i]
}
return host;
};
return host
}
{
"name": "make-array",
"version": "1.0.3",
"version": "1.0.5",
"description": "Creates a real Array from almost anything.",
"main": "make-array.js",
"module": "index.js",
"main": "index.js",
"scripts": {
"build": "babel index.js -o make-array.js",
"test": "npm run build && sh test.sh"
"test": "sh test.sh"
},
"files": [
"index.js",
"make-array.js"
"index.js"
],

@@ -36,4 +33,2 @@ "repository": {

"devDependencies": {
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"chai": "*",

@@ -40,0 +35,0 @@ "mocha": "*"

[![NPM version](https://badge.fury.io/js/make-array.svg)](http://badge.fury.io/js/make-array)
[![Build Status](https://travis-ci.org/kaelzhang/make-array.svg?branch=master)](https://travis-ci.org/kaelzhang/make-array)
[![Dependency Status](https://gemnasium.com/kaelzhang/make-array.svg)](https://gemnasium.com/kaelzhang/make-array)

@@ -12,3 +11,3 @@ # make-array

```bash
$ npm install make-array --save
$ npm i make-array --save
```

@@ -63,2 +62,2 @@

MIT
<!-- do not want to make nodeinit to complicated, you can edit this whenever you want. -->
<!-- do not want to make nodeinit to complicated, you can edit this whenever you want. -->
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = makeArray;
// @param {all} subject
// if nodelist, returns an array which generated from the nodelist
// if Array, returns the array itself
// otherwise, returns an array contains the subject
// @param {Array=} host
function makeArray(subject, host) {
// false -> [false]
// null -> []
// undefined -> makeArray() -> []
if (subject === undefined || subject === null) {
return host || [];
}
// if is already an array
if (Object.prototype.toString.call(subject) === '[object Array]') {
return host ? host.concat(subject) : subject;
}
host || (host = []);
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);
}
return host;
};
// 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;
}
/**
* clone an object as a pure subject, and ignore non-number properties
* @param {Array} subject
* @param {Array|Object} host required, receiver which the subject be cloned to
*/
function clonePureArray(subject, host) {
var i = subject.length;
var start = host.length;
while (i--) {
host[start + i] = subject[i];
}
return host;
};
module.exports = exports['default'];