Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danigb/as-arr
Convert objects (specially strings) into arrays
https://github.com/danigb/as-arr
Last synced: 13 days ago
JSON representation
Convert objects (specially strings) into arrays
- Host: GitHub
- URL: https://github.com/danigb/as-arr
- Owner: danigb
- Created: 2016-06-07T12:17:33.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-06-07T12:20:01.000Z (over 8 years ago)
- Last Synced: 2024-10-13T14:15:32.426Z (about 1 month ago)
- Language: JavaScript
- Size: 1000 Bytes
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# as-arr [![npm](https://img.shields.io/npm/v/as-arr.svg?style=flat-square)](https://www.npmjs.com/package/as-arr)
Convert objects (specially strings) into arrays:
```js
var asArr = require('as-arr')// split strings by spaces
asArr('a b c') // => ['a', 'b', 'c']// by default all spaces are removed
asArr(' a b c ') // => ['a', 'b', 'c']// custom separators
asArr('a, b, c', /,\s*/) // => ['a', 'b', 'c']
asArr('abc', '') // => ['a', 'b', 'c']// arrays are bypassed
asArr(['a', 'b', 'c']) // => ['a', 'b', 'c']// objects are wrapped into an array
asArr(123) // => [ 123 ]
asArr(null) // => [ null ]// it ALWAYS returns an array
asArr() // => []// create a function with a custom separator
var toArr = asArr.use(/\s*\|\s*|\s*,\s*|\s+/)
toArr('a, b c | d') // => ['a', 'b', 'c', 'd']
```## License
MIT License