https://github.com/sindresorhus/arrify
Convert a value to an array
https://github.com/sindresorhus/arrify
Last synced: 10 months ago
JSON representation
Convert a value to an array
- Host: GitHub
- URL: https://github.com/sindresorhus/arrify
- Owner: sindresorhus
- License: mit
- Created: 2015-02-16T14:53:33.000Z (about 11 years ago)
- Default Branch: main
- Last Pushed: 2021-11-09T19:53:52.000Z (over 4 years ago)
- Last Synced: 2025-05-10T00:48:03.993Z (10 months ago)
- Language: TypeScript
- Size: 14.6 KB
- Stars: 129
- Watchers: 6
- Forks: 27
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license
- Security: .github/security.md
Awesome Lists containing this project
- stars - arrify
README
# arrify
> Convert a value to an array
*If you simply want to accept both a single value and multiple values, you can use `[singleValueOrArray].flat()` instead.*
## Install
```sh
npm install arrify
```
## Usage
```js
import arrify from 'arrify';
arrify('🦄');
//=> ['🦄']
arrify(['🦄']);
//=> ['🦄']
arrify(new Set(['🦄']));
//=> ['🦄']
arrify(null);
//=> []
arrify(undefined);
//=> []
```
*Specifying `null` or `undefined` results in an empty array.*
---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.