Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

arrify

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arrify

Convert a value to an array

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
31M
increased by6.63%
Maintainers
1
Weekly downloads
 
Created

What is arrify?

The arrify npm package is designed to convert a value to an array. If the input value is already an array, it is returned as is. If the input is null or undefined, an empty array is returned. For any other input, the value is placed as a single item within an array. This package is particularly useful for ensuring that data is in array form without having to write repetitive checks and conversions throughout your code.

What are arrify's main functionalities?

Converting non-array values to an array

This feature demonstrates how to convert various types of non-array values (like strings or numbers) into an array containing that value.

const arrify = require('arrify');

console.log(arrify('hello')); // ['hello']
console.log(arrify(5)); // [5]

Handling null or undefined values

This feature shows how arrify converts null or undefined inputs into an empty array, which is useful for avoiding errors when working with potentially null or undefined data.

const arrify = require('arrify');

console.log(arrify(null)); // []
console.log(arrify(undefined)); // []

Preserving array inputs

This feature illustrates that arrify will return the input as is if it's already an array, ensuring that array inputs are not modified or wrapped in another array.

const arrify = require('arrify');

console.log(arrify(['already', 'an', 'array'])); // ['already', 'an', 'array']

Other packages similar to arrify

Keywords

FAQs

Package last updated on 28 Apr 2021

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