
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
lodash.castarray
Advanced tools
The lodash.castarray package is a utility function from the Lodash library that ensures a value is wrapped in an array. If the value is already an array, it returns the value unchanged. This is useful for normalizing inputs to functions that expect arrays.
Cast a single value to an array
This feature takes a single value and returns it as an array. If the input is not an array, it wraps the value in an array.
const castArray = require('lodash.castarray');
const result = castArray(1);
console.log(result); // [1]
Return an array unchanged
This feature checks if the input is already an array and returns it unchanged.
const castArray = require('lodash.castarray');
const result = castArray([1, 2, 3]);
console.log(result); // [1, 2, 3]
Handle various data types
This feature demonstrates that lodash.castarray can handle various data types, including strings, objects, and null values, wrapping them in an array.
const castArray = require('lodash.castarray');
console.log(castArray('string')); // ['string']
console.log(castArray({ key: 'value' })); // [{ key: 'value' }]
console.log(castArray(null)); // [null]
The arrayify package provides similar functionality by converting a value to an array if it is not already one. It is a lightweight alternative to lodash.castarray and is useful for normalizing inputs.
The ensure-array package ensures that the input is an array. If the input is not an array, it wraps it in one. This package is similar to lodash.castarray but focuses solely on this functionality without the additional utilities provided by Lodash.
The to-array package converts an array-like object or a single value to an array. It is useful for normalizing inputs and is similar to lodash.castarray in its core functionality.
The lodash method _.castArray
exported as a Node.js module.
Using npm:
$ {sudo -H} npm i -g npm
$ npm i --save lodash.castarray
In Node.js:
var castArray = require('lodash.castarray');
See the documentation or package source for more details.
FAQs
The lodash method `_.castArray` exported as a module.
The npm package lodash.castarray receives a total of 2,123,139 weekly downloads. As such, lodash.castarray popularity was classified as popular.
We found that lodash.castarray 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
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.