Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
The make-array package is a utility that helps in converting different types of values into arrays. It is particularly useful when you want to ensure that a value is always treated as an array, regardless of its original type.
Convert single value to array
This feature allows you to convert a single non-array value into an array containing that value. It ensures that the input is always returned as an array.
const makeArray = require('make-array');
const singleValue = 'hello';
const array = makeArray(singleValue); // ['hello']
Convert array-like objects to array
This feature converts array-like objects (such as arguments objects or objects with a length property) into proper arrays.
const makeArray = require('make-array');
const arrayLike = {0: 'a', 1: 'b', length: 2};
const array = makeArray(arrayLike); // ['a', 'b']
Handle null or undefined
This feature ensures that null or undefined values are converted into empty arrays, providing a consistent array output.
const makeArray = require('make-array');
const result = makeArray(null); // []
const result2 = makeArray(undefined); // []
The arrayify package provides similar functionality by converting a value into an array. It is comparable to make-array in that it also handles single values, array-like objects, and null/undefined values, ensuring the output is always an array.
The to-array package is another utility that converts array-like objects to arrays. It is similar to make-array but focuses more on array-like objects rather than single values or null/undefined handling.
The cast-array package from lodash is a utility that casts a value as an array if it's not already one. It is similar to make-array in its core functionality but is part of the larger lodash library, which offers a wide range of utility functions.
Creates a real Array from almost anything.
$ npm i make-array --save
var makeArray = require('make-array');
makeArray(); // []
makeArray(undefined); // []
makeArray(null); // []
makeArray(1); // [1]
makeArray([1, 2]); // [1, 2]
makeArray({
'0': 1,
'1': 2,
length: 2
}); // [1, 2]
function foo (){
return makeArray(arguments);
}
foo(1, 2, 3); // [1, 2, 3]
mixed
things you want to make it an arrayArray=
if host
is specified, the newly-created array will append to the end of the host
Returns Array
. If host
is specified, it will return the host
itself.
var host = [1, 2];
function foo(){
return arguments;
}
var result = makeArray(foo({}, []), host);
result; // [1, 2, {}, []];
result === host; // true
1.0.0: bump version to mark it as stable.
MIT
FAQs
Creates a real Array from almost anything.
We found that make-array demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.