![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
The array-ify npm package is a utility that ensures a given value is returned as an array. If the value is already an array, it returns the value unchanged. If the value is not an array, it wraps the value in an array. This can be particularly useful for functions that need to handle inputs that could be either a single item or an array of items.
Convert single value to array
This feature takes a single value and converts it into an array containing that value. This is useful when you want to ensure that a variable is always an array, even if it starts as a single value.
const arrayify = require('array-ify');
const singleValue = 'hello';
const result = arrayify(singleValue);
console.log(result); // ['hello']
Return array unchanged
This feature checks if the input is already an array and returns it unchanged. This is useful for functions that need to handle both single values and arrays uniformly.
const arrayify = require('array-ify');
const arrayValue = ['hello', 'world'];
const result = arrayify(arrayValue);
console.log(result); // ['hello', 'world']
Handle null or undefined
This feature ensures that if the input is null or undefined, it returns an empty array. This is useful for avoiding errors when dealing with potentially null or undefined values.
const arrayify = require('array-ify');
const nullValue = null;
const result = arrayify(nullValue);
console.log(result); // []
The arrify package is similar to array-ify in that it converts a value to an array. If the value is already an array, it returns it unchanged. If the value is null or undefined, it returns an empty array. It is a lightweight and straightforward alternative to array-ify.
The to-array package converts an array-like object or a single value to an array. It is more versatile in handling array-like objects such as NodeList or arguments objects, making it a good alternative to array-ify for more complex use cases.
The ensure-array package ensures that the input is always returned as an array. It is similar to array-ify but also provides additional options for handling different types of inputs, making it a more flexible alternative.
Turn anything into an array
$ npm install --save array-ify
var arrayify = require('array-ify');
arrayify('unicorn');
//=> ['unicorn']
arrayify(['unicorn']);
//=> ['unicorn']
arrayify(null);
//=> [null]
arrayify(undefined);
//=> [undefined]
The difference that is this module does NOT turn null
or undefined
to an empty array.
MIT © Steve Mao
FAQs
Turn anything into an array
We found that array-ify 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.