
Security News
Official Go SDK for MCP in Development, Stable Release Expected in August
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.
ensure-array
Advanced tools
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 57,216 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
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.
Security News
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.