Skip to content

Latest commit

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

arrayize

Return input if it is an array, otherwise return input wrapped in an array. If input is null or undefined, return empty array.

Installation

npm install arrayize

Usage

vararrayize=require('arrayize');// Empty array if passed undefined or nullarrayize();// => []arrayize(null);// => []// Original array if passed an arrayarrayize([]);// => []arrayize(['foo']);// => [ 'foo' ]arrayize(['foo','bar','baz']);// => [ 'foo', 'bar', 'baz' ]// Original value wrapped in an array if passed anything elsearrayize('foo');// => [ 'foo' ]arrayize(3);// => [ 3 ]arrayize({foo:'bar'});// => [ { foo: 'bar' } ]arrayize(function(){});// => [ [Function] ]arrayize(newDate());// => [ Wed Mar 05 2014 03:29:26 GMT-0800 (PST) ]arrayize(/foo/);// => [ /foo/ ]

Running tests

git clone http://github.com/tauren/arrayize
cd arrayize
npm install
npm test

About

Return input if it is an array, otherwise return input wrapped in an array. If input is null or undefined, return empty array.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages