Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gyumeijie/arrify

convert a value to an array
https://github.com/gyumeijie/arrify

array arrify convert npm-package utility

Last synced: 10 days ago
JSON representation

convert a value to an array

Awesome Lists containing this project

README

        

# arraify [![](https://travis-ci.com/Gyumeijie/arrify.svg?branch=master)](https://travis-ci.com/Gyumeijie/arrify)

> Convert a value to an array

## Install

```
$ npm install arraify
```

## Usage

```js
const arrify = require('arraify');

const obj = {
0: 'zero',
1: 'one',
length: 2,
};
arrify(obj);
// ['zero', 'one']

const obj = {
0: 'zero',
1: 'one',
length: 3,
};

arrify.config.arraySimilarity = 2;
arrify(obj);
// [{ 0: 'zero', 1: 'one', length: 3 }]
arrify.config.arraySimilarity = 1;
arrify(obj);
// [{ 0: 'zero', 1: 'one', length: 3 }]

arrify.config.arraySimilarity = 0;
arrify(obj);
// ['zero', 'one', undefined]

arrify(1, 2, 3);
// [1, 2, 3]

arrify('string');
// ['s', 't', 'r', 'i', 'n', 'g']

arrify.config.splitString = false;
arrify('string');
// ['sting']

arrify([]);
// []

arrify();
// []

arrify(null);
// []

arrify(undefined);
// []
```

## Configs

```javascript
arrify.config = {
splitString: true,
arraySimilarity: 2,
};
```
splitString:
>true | false, defaults to `true`

[arraySimilarity](https://github.com/Gyumeijie/isArrayLike):
> 0 | 1 | 2, defaults to `2`

## License

MIT © [Gyumeijie](https://github.com/Gyumeijie)