npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

cast-to-array

0.1.0

@jonschlinkert

npmHomeRepoSnykSocket
Downloads:1
$ npm install cast-to-array
DailyWeeklyMonthlyYearly

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

  • arr-map: Faster, node.js focused alternative to JavaScript's native array map. | homepage
  • array-last: Get the last or last n elements in an array. | homepage
  • array-map: [].map(f) for older browsers | homepage
  • array-sum: Add up all of the numbers in an array of numbers. Works when non-numbers are… more | homepage
  • array-xor: Returns the symmetric difference (exclusive-or) of an array of elements (elements that are present in… more | homepage

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

  • github/jonschlinkert
  • twitter/jonschlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.


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