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

array-ify

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-ify

Turn anything into an array

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is array-ify?

The array-ify npm package is a utility that ensures a given value is returned as an array. If the value is already an array, it returns the value unchanged. If the value is not an array, it wraps the value in an array. This can be particularly useful for functions that need to handle inputs that could be either a single item or an array of items.

What are array-ify's main functionalities?

Convert single value to array

This feature takes a single value and converts it into an array containing that value. This is useful when you want to ensure that a variable is always an array, even if it starts as a single value.

const arrayify = require('array-ify');
const singleValue = 'hello';
const result = arrayify(singleValue);
console.log(result); // ['hello']

Return array unchanged

This feature checks if the input is already an array and returns it unchanged. This is useful for functions that need to handle both single values and arrays uniformly.

const arrayify = require('array-ify');
const arrayValue = ['hello', 'world'];
const result = arrayify(arrayValue);
console.log(result); // ['hello', 'world']

Handle null or undefined

This feature ensures that if the input is null or undefined, it returns an empty array. This is useful for avoiding errors when dealing with potentially null or undefined values.

const arrayify = require('array-ify');
const nullValue = null;
const result = arrayify(nullValue);
console.log(result); // []

Other packages similar to array-ify

Keywords

FAQs

Package last updated on 14 Jun 2015

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