cast-to-array

0.1.0 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i cast-to-array

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • jonschlinkert