0.10.0 • Published 11 years ago

to-array.js v0.10.0

Weekly downloads
29
License
MIT
Repository
github
Last release
11 years ago

to-array.js

Build Status NPM version NPM downloads LICENSE

Converts primitives and objects (plain or array-like) to a sensible array representation for Node.js and the browser.

Examples

Array ... Array

toArray([1, 2, 3]);
//=> [1, 2, 3]

undefined/null ... Array

toArray(void 0 || null)
//=> []

String ... Array

toArray('id');
//=> ['id']

Delimited String ... Array

toArray('a,b,c', ',');
//=> ['a', 'b', 'c']

Number ... Array

toArray(42);
//=> [42]

DOM nodeList

var elements = document.getElementsByTagName('textarea');
toArray(elements);
//=> [ <textarea id="wgjc"></textarea>, <textarea id="wgjs"></textarea>, <textarea id="wgju"></textarea> ]

DOM classList

<div id="example" class="one two">
toArray(document.getElementById('example').classList);
//=> [ "one", "two" ]

Installation

npm

% npm install to-array.js

component

% component install wilmoore/to-array.js

bower

% bower install to-array.js

jam

% jam install to-array.js

volo

% volo add wilmoore/to-array.js

manual

  1. download

    % curl -#O https://raw.github.com/wilmoore/to-array.js/master/to-array.js
  2. use

    <script src="to-array.js"></script>

Alternatives

Building a release

% make to-array.js
% git commit …
% npm version minor
% git push
% git push --tags
% npm publish

License

MIT

0.10.0

11 years ago

0.9.0

11 years ago

0.8.0

11 years ago

0.7.0

11 years ago

0.6.0

11 years ago

0.5.0

11 years ago

0.4.0

12 years ago

0.3.0

12 years ago

0.2.0

12 years ago