New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

var-type

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

var-type

Get the variable type

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-85.71%
Maintainers
1
Weekly downloads
 
Created
Source

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,3]Array
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.

Keywords

FAQs

Package last updated on 17 Jan 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc