New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

tagOf

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tagOf

typeof alternative

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

tagOf.js

version build status downloads

saucelabs matrix

typeof alternative:

  • robust and well tested
  • works with user-defined classes
  • works with node, AMD and all browsers, including legacy ones like IE6
// tagOf( value:any ): string

tagOf( null ) // 'null'
tagOf( undefined ) // 'undefined'
tagOf( 0 ) // 'number'
tagOf( new Number( 0 ) ) // 'number'
tagOf( '' ) // 'string'
tagOf( new String( '' ) ) // 'string'
tagOf( true ) // 'boolean'
tagOf( false ) // 'boolean'
tagOf( new Boolean( true ) ) // 'boolean'
tagOf( new Boolean( false ) ) // 'boolean'
tagOf( {} ) // 'object'
tagOf( [] ) // 'array'
tagOf( function () {} ) // 'function'
tagOf( new Date() ) // 'date'
tagOf( /^/i ) // 'regexp'
tagOf( new RegExp() ) // 'regexp'

// ES6 additions
tagOf( Symbol( 'tagOf') ) // 'symbol'
tagOf( Symbol.for( 'tagOf' ) ) // 'symbol'
tagOf( new Set() ) // 'set'
tagOf( new WeakSet() ) // 'weakset'
tagOf( new Map() ) // 'map'
tagOf( new WeakMap() ) // 'weakmap'

// user-defined classes
class Circle {}
function Square() {}
tagOf( new Circle() ) // 'circle'
tagOf( new Square() ) // 'square'
tagOf( new class {} ) // 'object' - does not work with anonymous class
tagOf( new ( function {} ) ) // 'object' - does not work with anonymous constructor

Install

Node:

$ npm install --save tagOf
const tagOf = require( 'tagOf' )

Browser:

<script src="path/to/tagOf.js"></script>

tagOf will register itself as an anonymous AMD module if AMD loader presents, otherwise it is defined as a browser global named unsuprisingly, tagOf

Caveats

Does not work with Error objects.

Keywords

type

FAQs

Package last updated on 17 Jun 2016

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