🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

instanceof

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

instanceof

JavaScript all types detection module (crossbrowser)

1.0.6
latest
Source
npm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

Instanceof

Checks if variable is instance of some constructor.
Also can detect any type with Instanceof.getType()

Usage:

const Instanceof = require( 'instanceof' );

// Instanceof( {mixed}, {Array|mixed} ) => Boolean

Instanceof( 123, Number );                                  // true
Instanceof( 123, [ Number, Array, String, 'Boolean' ] );    // true
Instanceof( [], [ Number, Array ] );                        // true
Instanceof( [], 'Array' );                                  // true
Instanceof( NaN, NaN );                                     // true
Instanceof( Object, Function );                             // true

Instanceof( '123', Number );                                // false
Instanceof( Object, Object );                               // false
Instanceof( Object, [ Object, 'NaN', 'Null', null ] );      // false
Instanceof( 123, [ Object, 'NaN', 'Null', null, 'null' ] ); // false

// --- GetType ---

Instanceof.getType( NaN );									// 'NaN'
Instanceof.getType( { a: 123 } );							// 'object'
Instanceof.getType( [ 1, 2, 3 ] );							// 'array'
Instanceof.getType( null );									// 'null'

Keywords

instanceof

FAQs

Package last updated on 01 Nov 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