is

Contains common type checking utility methods.

Methods


<static> array( value ) → {boolean}

Checks if the value is an array.

Parameters
Name Type Description
value *

The value to check.

Returns

true if the supplied value is an array.

Examples

// alias the FooGallery.utils.is namespace
var _is = FooGallery.utils.is;

console.log( _is.array( [] ) ); // => true
console.log( _is.array( null ) ); // => false
console.log( _is.array( 123 ) ); // => false
console.log( _is.array( "" ) ); // => false


<static> boolean( value ) → {boolean}

Checks if the value is a boolean.

Parameters
Name Type Description
value *

The value to check.

Returns

true if the supplied value is a boolean.

Examples

// alias the FooGallery.utils.is namespace
var _is = FooGallery.utils.is;

console.log( _is.boolean( true ) ); // => true
console.log( _is.boolean( false ) ); // => true
console.log( _is.boolean( "true" ) ); // => false
console.log( _is.boolean( "false" ) ); // => false
console.log( _is.boolean( 1 ) ); // => false
console.log( _is.boolean( 0 ) ); // => false


<static> element( value ) → {boolean}

Checks if the value is an element.

Parameters
Name Type Description
value *

The value to check.

Returns

true if the supplied value is an element.

Examples

// alias the FooGallery.utils.is namespace
var _is = FooGallery.utils.is,
	// create an element to test
	el = document.createElement("span");

console.log( _is.element( el ) ); // => true
console.log( _is.element( $(el) ) ); // => false
console.log( _is.element( null ) ); // => false
console.log( _is.element( {} ) ); // => false


<static> empty( value ) → {boolean}

Checks if the value is empty.

Description

The following values are considered to be empty by this method:

  • "" - An empty string
  • 0 - 0 as an integer
  • 0.0 - 0 as a float
  • [] - An empty array
  • {} - An empty object
  • $() - An empty jQuery object
  • false
  • null
  • undefined
Parameters
Name Type Description
value *

The value to check.

Returns

true if the supplied value is empty.

Examples

// alias the FooGallery.utils.is namespace
var _is = FooGallery.utils.is;

console.log( _is.empty( undefined ) ); // => true
console.log( _is.empty( null ) ); // => true
console.log( _is.empty( 0 ) ); // => true
console.log( _is.empty( 0.0 ) ); // => true
console.log( _is.empty( "" ) ); // => true
console.log( _is.empty( [] ) ); // => true
console.log( _is.empty( {} ) ); // => true
console.log( _is.empty( 1 ) ); // => false
console.log( _is.empty( 0.1 ) ); // => false
console.log( _is.empty( "one" ) ); // => false
console.log( _is.empty( ["one"] ) ); // => false
console.log( _is.empty( { "name": "My Object" } ) ); // => false


<static> error( value ) → {boolean}

Checks if the value is an error.

Parameters
Name Type Description
value *

The value to check.

Returns

true if the supplied value is an error.

Examples

// alias the FooGallery.utils.is namespace
var _is = FooGallery.utils.is,
	// create some errors to test
	err1 = new Error("err1"),
	err2 = new SyntaxError("err2");

console.log( _is.error( err1 ) ); // => true
console.log( _is.error( err2 ) ); // => true
console.log( _is.error( null ) ); // => false
console.log( _is.error( 123 ) ); // => false
console.log( _is.error( "" ) ); // => false
console.log( _is.error( {} ) ); // => false
console.log( _is.error( [] ) ); // => false


<static> fn( value ) → {boolean}

Checks if the value is a function.

Parameters
Name Type Description
value *

The value to check.

Returns

true if the supplied value is a function.

Examples

// alias the FooGallery.utils.is namespace
var _is = FooGallery.utils.is,
	// create a function to test
	func = function(){};

console.log( _is.fn( func ) ); // => true
console.log( _is.fn( null ) ); // => false
console.log( _is.fn( 123 ) ); // => false
console.log( _is.fn( "" ) ); // => false


<static> hash( value ) → {boolean}

Checks if the value is a hash.

Parameters
Name Type Description
value *

The value to check.

Returns

true if the supplied value is a hash.

Examples

// alias the FooGallery.utils.is namespace
var _is = FooGallery.utils.is;

console.log( _is.hash( {"some": "prop"} ) ); // => true
console.log( _is.hash( {} ) ); // => true
console.log( _is.hash( window ) ); // => false
console.log( _is.hash( document ) ); // => false
console.log( _is.hash( "" ) ); // => false
console.log( _is.hash( 123 ) ); // => false


<static> jq( value ) → {boolean}

Checks if the value is a jQuery object.

Parameters
Name Type Description
value *

The value to check.

Returns

true if the supplied value is a jQuery object.

Examples

// alias the FooGallery.utils.is namespace
var _is = FooGallery.utils.is,
	// create an element to test
	el = document.createElement("span");

console.log( _is.jq( $(el) ) ); // => true
console.log( _is.jq( $() ) ); // => true
console.log( _is.jq( el ) ); // => false
console.log( _is.jq( {} ) ); // => false
console.log( _is.jq( null ) ); // => false
console.log( _is.jq( 123 ) ); // => false
console.log( _is.jq( "" ) ); // => false


<static> number( value ) → {boolean}

Checks if the value is a number.

Parameters
Name Type Description
value *

The value to check.

Returns
Examples

// alias the FooGallery.utils.is namespace
var _is = FooGallery.utils.is;

console.log( _is.number( 123 ) ); // => true
console.log( _is.number( undefined ) ); // => false
console.log( _is.number( null ) ); // => false
console.log( _is.number( "" ) ); // => false


<static> object( value ) → {boolean}

Checks if the value is an object.

Parameters
Name Type Description
value *

The value to check.

Returns

true if the supplied value is an object.

Examples

// alias the FooGallery.utils.is namespace
var _is = FooGallery.utils.is;

console.log( _is.object( {"some": "prop"} ) ); // => true
console.log( _is.object( {} ) ); // => true
console.log( _is.object( window ) ); // => true
console.log( _is.object( document ) ); // => true
console.log( _is.object( undefined ) ); // => false
console.log( _is.object( null ) ); // => false
console.log( _is.object( "" ) ); // => false
console.log( _is.object( 123 ) ); // => false


<static> promise( value ) → {boolean}

Checks if the value is a promise.

Description

This is a simple check to determine if an object is a jQuery promise object. It simply checks the object has a then and promise function defined.

The promise object is created as an object literal inside of jQuery.Deferred, it has no prototype, nor any other truly unique properties that could be used to distinguish it.

This method should be a little more accurate than the internal jQuery one that simply checks for a promise function.

Parameters
Name Type Description
value *

The object to check.

Returns

true if the supplied value is an object.

Examples

// alias the FooGallery.utils.is namespace
var _is = FooGallery.utils.is;

console.log( _is.promise( $.Deferred() ) ); // => true
console.log( _is.promise( {} ) ); // => false
console.log( _is.promise( undefined ) ); // => false
console.log( _is.promise( null ) ); // => false
console.log( _is.promise( "" ) ); // => false
console.log( _is.promise( 123 ) ); // => false


<static> size( value ) → {boolean}

Checks if the value is a valid CSS length.

Parameters
Name Type Description
value *

The value to check.

Returns

true if the value is a number or CSS length.

Examples

// alias the FooGallery.utils.is namespace
var _is = FooGallery.utils.is;

console.log( _is.size( 80 ) ); // => true
console.log( _is.size( "80px" ) ); // => true
console.log( _is.size( "80em" ) ); // => true
console.log( _is.size( "80%" ) ); // => true
console.log( _is.size( {} ) ); // => false
console.log( _is.size( undefined ) ); // => false
console.log( _is.size( null ) ); // => false
console.log( _is.size( "" ) ); // => false

Details

<length> - CSS | MDN for more information on CSS length values.


<static> string( value ) → {boolean}

Checks if the value is a string.

Parameters
Name Type Description
value *

The value to check.

Returns

true if the value is a string.

Examples

// alias the FooGallery.utils.is namespace
var _is = FooGallery.utils.is;

console.log( _is.string( "" ) ); // => true
console.log( _is.string( undefined ) ); // => false
console.log( _is.string( null ) ); // => false
console.log( _is.string( 123 ) ); // => false


<static> undef( value ) → {boolean}

Checks if the value is undefined.

Parameters
Name Type Description
value *

The value to check is undefined.

Returns

true if the supplied value is undefined.

Examples

// alias the FooGallery.utils.is namespace
var _is = FooGallery.utils.is;

console.log( _is.undef( undefined ) ); // => true
console.log( _is.undef( null ) ); // => false
console.log( _is.undef( 123 ) ); // => false
console.log( _is.undef( "" ) ); // => false