Test whether an object is array-like, e.g arguments or NodeList.
JavaScript
Latest commit 16739e8 Dec 11, 2012 @timoxley Merge pull request #1 from javve/patch-1
Remove console.log
Failed to load latest commit information.
test Upgrade mocha generated files. Nov 24, 2012
.gitignore Initial Commit Nov 2, 2012
Makefile Initial Commit Nov 2, 2012
Readme.md Fix stupid example in readme. Nov 2, 2012
component.json Update description. Nov 2, 2012
index.js Remove console.log Dec 11, 2012

Readme.md

is-collection

Evaluates obj to determine if it's an array, an array-like collection, or something else. This is useful when working with the function arguments collection, NodeLists and HTMLElement collections.

Note: This implementation doesn't consider elements that are also collections, such as <form> and <select>, to be array-like.

Installation

$ component install timoxley/is-collection

Usage

isCollection(document.querySelectorAll('div')) // => truthy (2)
isCollection([]) // => truthy (1)

function() {
  return isCollection(arguments)
}() // => truthy (2)

API

isCollection(object)

Takes an object and returns a number indicating the results of the test:

  • 0: Neither an array nor an array-like collection.
  • 1: Real array.
  • 2: Array-like collection.

Credit

Original code adapted from YUI.

License

BSD