cast-to-array
Cast a value to an array.
Last updated 10 years ago by jonschlinkert .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install cast-to-array 
SYNC missed versions from official npm registry.

cast-to-array NPM version

Cast a value to an array.

Install

Install with npm

$ npm i cast-to-array --save

Usage

var arrayify = require('cast-to-array');

returns an empty array when value is null or undefined

arrayify(null);
arrayify(undefined);
//=> []

casts a non-array value to an array

arrayify('abc');
//=> ['abc']

arrayify(/xyz/);
//=> [/xyz/]

arrayify(new RegExp('.'));
//=> [new RegExp('.')]

arrayify([[]]);
//=> [[]]

arrayify({});
//=> [{}]

returns an array directly

arrayify(['foo']);
//=> ['foo']

arrayify([]);
//=> []

Similar projects

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Author

Jon Schlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on November 06, 2015.

Current Tags

  • 0.1.0                                ...           latest (10 years ago)

1 Versions

  • 0.1.0                                ...           10 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (1)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |