Socket
Socket
Sign inDemoInstall

lodash.castarray

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lodash.castarray

The lodash method `_.castArray` exported as a module.


Version published
Weekly downloads
1.6M
increased by7.42%
Maintainers
1
Weekly downloads
 
Created

What is lodash.castarray?

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.

What are lodash.castarray's main functionalities?

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]

Other packages similar to lodash.castarray

Keywords

FAQs

Package last updated on 16 Feb 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc