is-js

A small library for identifying Javascript types.

npm install is-js
1 downloads in the last day
17 downloads in the last week
64 downloads in the last month

is.js

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.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.in will check to see if value is an element in the array. If collection is an object, is.in 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.

npm loves you