1.0.1 • Published 8 years ago

var-type v1.0.1

Weekly downloads
41
License
MIT
Repository
github
Last release
8 years ago

var-type

Get the native type of any variable using Object.prototype.toString

Install

With npm

npm install var-type

Usage

Node.js

var varType = require('var-type')

console.log(varType('hello')) // String

// The 2nd argument will be used as a comparison test if sent
varType('foo', 'String') // true

// All additional arguments are flattened and used for comparison tests
varType(1, ['Number', 'String', 'Boolean']) // true
varType('hi', 'Function', 'Number') // false

Conversion Table

InputOutput
'meow'String
new String('bar')String
20Number
new Number(10)Number
NaNNumber
InfinityNumber
trueBoolean
new Boolean()Boolean
/ab+c/RegExp
new RegExp('ab+c')RegExp
1,2,3Array
new Array(4,5,6)Array
{a: 1}Object
new Object()Object
function() {}Function
new Function('a', 'b')Function
new Date()Date
new Error()Error
nullNull
undefinedUndefined

See tests.