Skip to content

lisandropodesta/type-tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

type-tool

Flexible type checking including isUndefined, isNull, isBoolean, isNumber, isDate, isString, isRegExp, isArray, isArguments, isFunction and isObject.

Usage

Specific type testing

Determines whether a value is of a specific type.

  • .isUndefined( value )
  • .isNull( value )
  • .isBoolean( value )
  • .isNumber( value )
  • .isDate( value )
  • .isString( value )
  • .isRegExp( value )
  • .isArray( value )
  • .isArguments( value )
  • .isFunction( value )
  • .isObject( value )
var type = require( 'type-tool' );
if ( type.isFunction( value ) ) {
  // value is a function
}

.name( value )

Returns type name of value. Possible results are: 'undefined', 'null', 'boolean', 'number', 'date', 'string', 'regexp', 'array', 'arguments', 'function' and 'object'.

var type = require( 'type-tool' );
if ( type.name( value ) == 'array' ) {
  // value is an array
}

.get( value )

Returns type information of value including name and specific type flags.

var type = require( 'type-tool' );
var ti = type.get( [] ); // -> ti == { name: 'array', isArray: true }

ti = type.get( value );
if ( ti.isArray ) {
  // value is an array
}
else if ( ti.isFunction ) {
  // value is a function
}
else if ( ti.isNumber ) {
  // value is a number
}

License

type-tool is available under the [MIT license] (http://opensource.org/licenses/MIT).

About

Flexible type checking

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages