
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
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.
The npm package make-array receives a total of 185,524 weekly downloads. As such, make-array popularity was classified as popular.
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
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.