Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/arrify
Convert a value to an array
https://github.com/sindresorhus/arrify
Last synced: 5 days 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 (almost 10 years ago)
- Default Branch: main
- Last Pushed: 2021-11-09T19:53:52.000Z (about 3 years ago)
- Last Synced: 2024-11-21T08:34:50.454Z (21 days ago)
- Language: TypeScript
- Size: 14.6 KB
- Stars: 131
- Watchers: 7
- Forks: 28
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license
- Security: .github/security.md
Awesome Lists containing this project
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.