node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org ยป



Build Status


Get the type of a variable or one unevaluated operand in easy way and provides all the* functions from Node core.



var type = require('get-type')

type.get(operand) // returns a string

and all core-utils-is functions:

  • type.isArray(arr)
  • type.isBoolean(bool)
  • type.isNull(null)
  • type.isNullOrUndefined(null)
  • type.isNumber(num)
  • type.isString(str)
  • type.isSymbol(sym)
  • type.isUndefined(undef)
  • type.isRegExp(reg)
  • type.isObject(obj)
  • type.isDate(date)
  • type.isError(err)
  • type.isFunction(fn)
  • type.isPrimitive(prim)
  • type.isBuffer(buf)

more the isJSON function to check if a string is a valid JSON string


  var t = require('assert');
  var type = require('get-type');
  t.deepEqual(type.get('{"a": 2014, "b": [1,2]}'), 'json', 'should return a json');
  t.deepEqual(type.get([1,2,3,4]), 'array', 'should return an array');
  t.deepEqual(type.get(true), 'boolean', 'should return a boolean');
  t.deepEqual(type.get(null), 'null', 'should return null');
  t.deepEqual(type.get(2014), 'number', 'should return a  number');
  t.deepEqual(type.get('a string message'), 'string', 'should return a string');
  t.deepEqual(type.get(), 'undefined', 'should return undefined');
  t.deepEqual(type.get(/w/), 'regexp', 'should return a regexp');
  t.deepEqual(type.get({a:1}), 'object', 'should return an object');
  t.deepEqual(type.get(new Date()), 'date', 'should return a date object');
  t.deepEqual(type.get(new Error()), 'error', 'should return an error object');
  t.deepEqual(type.get(function () {}), 'function', 'should return a function');
  t.deepEqual(type.get(new Buffer('')), 'buffer', 'should return a buffer');