🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

get-type

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-type

Get the type of a variable or one unevaluated operand

latest
npmnpm
Version
1.1.0
Version published
Weekly downloads
29
-50.85%
Maintainers
1
Weekly downloads
 
Created
Source

get-type

Build Status

####summary

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

V1

####app 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

####example

  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');

Keywords

typeof

FAQs

Package last updated on 19 Jul 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts