tchaflich / tipo

Quick and small type-detection code for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Table of Contents

tipo

A tiny, highly testable file; easy to add to your project and simple to use.

  • No duck typing
  • Works cross-iframe
  • Works with non-primitive constructed objects (new String(), new Number(), etc)

Meta

  • author: @tchaflich
  • license: MIT

getDetectedType

Grab the type JavaScript believes the parameter to be. Native types will often have an uppercased string, so this function converts to lowercase for ease of use.

Parameters

  • something any

Returns string

isString

Is the input a string?

Parameters

  • something any

Returns boolean

isNumber

Is the input a number? This will return true for NaN, despite how silly that sounds. It is still of a "numeric" type, much like Infinity.

Parameters

  • something any

Returns boolean

isArray

Is the input an array?

Parameters

  • something any

Returns boolean

isFunction

Is the input a function?

Parameters

  • something any

Returns boolean

isObject

Is the input an object? Defining 'object' in javascript is not a trivial exercise - the specification used here is that the argument is a non-primitive.

Parameters

  • something any

Returns undefined

isUndefined

Is the input undefined?

Parameters

  • something any

Returns boolean

isNull

Is the input null? This one is really just in here for completion's sake.

Parameters

  • something any

Returns boolean

isBoolean

Is the input a boolean?

Parameters

  • something any

Returns boolean

About

Quick and small type-detection code for JavaScript

License:MIT License


Languages

Language:JavaScript 100.0%