Skip to content
A small library for identifying Javascript types.
JavaScript
Find file
Failed to load latest commit information.
test Corrected erroneous assertions for Node vows Sep 5, 2012
.gitignore Added tests for node.js environment Sep 4, 2012
MIT-LICENSE.txt Added Readme and License Aug 18, 2012
README.md Add bower installation instructions Feb 13, 2013
component.json
is.js Changed code style, included "use strict" Apr 17, 2013
package.json Corrected erroneous assertions for Node vows Sep 5, 2012

README.md

is.js

Installing

Cloning: git clone https://github.com/scottrabin/is-js.git is-js

NPM: npm install is-js

Bower: bower install is-js

Usage

Basic type checking
is.string(s) Determines if the argument is a string
is.number(n) Determines if the argument is a number
is.bool(b) Determines if the argument is a boolean (true or false)
is.fn(f) Determines if the argument is a function
is.array(a) Determines if the argument is an array
is.object(o) Determines if the argument is an object. Since nearly all Javascript types inherit from Object, this will most likely return true for anything but numbers, strings, booleans, and null/undefined. This function can be used to determine if arbitrary properties can be set on the given object.
is.regex(r) Determines if the argument is a regular expression object
is.element(e) Determines if the argument is an HTMLElement. Does not return true for window or document.
Specialized type checking
is.numeric(n) Determines if the argument is a number-like value; numbers (i.e. values that return true from is.number(n)) will return true, as well as any string representation of a number. See the test page for is.numeric to see what strings are accepted as numeric.
is.hash(h) Determines if the argument is a hash, or key/value pair object that is not an Array, function, or user-defined object.
Collection properties
is.inside(collection, value) Determines if the specified value is contained within the given collection. If collection is an array, is.inside will check to see if value is an element in the array. If collection is an object, is.inside will check if any property directly on the object is equal to the specified value.
is.set(variable) Determines if the specified variable is undefined or null.
is.empty(collection) Determines if the specified collection is empty, or is otherwise falsy. If collection is an array, is.empty checks that the array has no elements. If collection is an object, is.empty checks that the object has no properties declared directly on the object. If collection is neither an array or object, is.empty checks if the given value is falsy; this includes null, false, and empty strings.

Testing

See the unit tests page at scottrabin.com/is-js/test.html.

License

is.js is released under the MIT License. See MIT-LICENSE.txt for more details.

Something went wrong with that request. Please try again.