Add castArray

This commit is contained in:
Angelos Chalaris
2018-01-23 20:54:12 +02:00
parent 4346b25279
commit 84a3fa1a8b
2 changed files with 15 additions and 0 deletions

14
snippets/castArray.md Normal file
View File

@ -0,0 +1,14 @@
### castArray
Casts the provided value as an array if it's not one.
Use `Array.isArray()` to determine if `val` is an array and return it as-is or encapsulated in an array accordingly.
```js
const castArray = val => Array.isArray(val) ? val : [val];
```
```js
castArray('foo'); // ['foo']
castArray([1]); // [1]
```

View File

@ -9,6 +9,7 @@ byteSize:string
call:adapter,function
capitalize:string,array
capitalizeEveryWord:string,regexp
castArray:utility,array,type
chainAsync:function
chunk:array
clampNumber:math