Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/krmax44/always-array
Ensures you are always dealing with an array.
https://github.com/krmax44/always-array
Last synced: about 2 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 (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-02-12T13:53:12.000Z (almost 3 years ago)
- Last Synced: 2024-04-24T20:14:54.272Z (8 months 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
[![Build Status](https://travis-ci.com/krmax44/always-array.svg?branch=master)](https://travis-ci.com/krmax44/always-array)
[![bundle size](https://img.shields.io/bundlephobia/minzip/always-array)](https://bundlephobia.com/result?p=always-array)
[![install size](https://packagephobia.now.sh/badge?p=always-array)](https://packagephobia.now.sh/result?p=always-array)
[![npm version](https://img.shields.io/npm/v/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
```