![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.
ensure-array
Advanced tools
Ensure that an object is an array. Moves error checking out of your code.
Simple convenience function which ensures that you are dealing with an array and you can eliminate noise from your code.
For Example:
var array = require('ensure-array');
function foo(bar) {
array(bar).forEach(function (x) {
//do something with each item
});
}
Instead of doing something like this:
function foo(bar) {
if (bar === undefined) return;
if (bar === null) return;
if (!Array.isArray(bar)) bar = [bar];
bar.forEach(function (x) {
//do something with each item
});
}
It gets rid of the noise and coerces what is provided into an array, so you do not have to litter your code with a bunch of extraneous checks.
Here is the logic behind the function:
Here is the actual code which makes it happen
module.exports = function array(a, b, n) {
if (arguments.length === 0) return []; //no args, ret []
if (arguments.length === 1) { //single argument
if (a === undefined || a === null) return []; // undefined or null, ret []
if (Array.isArray(a)) return a; // isArray, return it
}
return Array.prototype.slice.call(arguments); //return array with copy of all arguments
};
npm install ensure-array
var array = require('ensure-array'); // get handle to the function
var foo = array(whatever); // foo will now safely be an array
FAQs
Ensure that an object is an array. Moves error checking out of your code.
The npm package ensure-array receives a total of 29,624 weekly downloads. As such, ensure-array popularity was classified as popular.
We found that ensure-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
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.