https://github.com/krmax44/always-array
Ensures you are always dealing with an array.
https://github.com/krmax44/always-array
Last synced: 3 months ago
JSON representation
Ensures you are always dealing with an array.
- Host: GitHub
- URL: https://github.com/krmax44/always-array
- Owner: krmax44
- License: mit
- Created: 2019-09-15T12:18:20.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-02-12T13:53:12.000Z (over 3 years ago)
- Last Synced: 2024-04-24T20:14:54.272Z (about 1 year ago)
- Language: TypeScript
- Size: 1.58 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Always Array
[](https://travis-ci.com/krmax44/always-array)
[](https://bundlephobia.com/result?p=always-array)
[](https://packagephobia.now.sh/result?p=always-array)
[](https://www.npmjs.com/package/always-array)Ensures you are always dealing with an array. It uses `Array.isArray`.
## Installation
```bash
yarn add always-array
# or with npm
npm i always-array
```## Usage
Very simple.
```js
import alwaysArray from 'always-array';alwaysArray('foo'); // ['foo']
alwaysArray(['foo']); // ['foo']const set = new Set([1, 2, 3]);
alwaysArray(set); // [ Set { 1, 2, 3 } ]
alwaysArray.convertIterables(set); // [1, 2, 3]
alwaysArray.convertIterables('foo'); // ['foo'] - albeit being an iterable, strings won't be spread into an array
```