Skip to content

ForbesLindesay-Unmaintained/to-element-array

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DEPRECATED: use arrayify

to-element-array

Convert an array-like object into an Array, a single element into an array with one item, and does document.querySelectorAll for strings

Installation

Using component

$ component install ForbesLindesay/to-element-array

Alternatively you can download from here and reference with a script tag, then use the global toElementArray.

API

Given the html:

<div id="foo" class="bar"></div>
<div class="bar"></div>

You can do the following:

var toArray = require('to-element-array');

//pass a single element
toArray(document.getElementById('foo'))
// => [<div id="foo" class="bar"></div>]

//pass an array-like list of elements
toArray(document.getElementsByClassName('bar'))
// => [<div id="foo" class="bar"></div>, <div class="bar"></div>]

//pass a query selector
toArray('div.bar')
// => [<div id="foo" class="bar"></div>, <div class="bar"></div>]

The array returned from toElementArray(arr) is always a real array so you can safely use .foreach, .map etc. It is also never a live array, even if the input is. It creates a copy of whever array you pass in, so you can do what you like with it.

License

MIT

About

Deprecated, use `arrayify`

Resources

Stars

Watchers

Forks

Packages

No packages published