zappan / is-js

A small library for identifying Javascript types.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

is.js

Installing

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

NPM: npm 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.

About

A small library for identifying Javascript types.

License:MIT License


Languages

Language:JavaScript 100.0%