🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a 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 - npm Package Compare versions

Comparing version

to
1.0.3

62

index.js

@@ -11,2 +11,3 @@

function Instanceof( obj, types ) {
if ( Array.isArray( types ) ) {

@@ -22,2 +23,20 @@ for ( var i = types.length; i--; ) if ( _Instanceof( obj, types[i] ) ) return true;

/* --------------------------------- GetType --------------------------------- */
Instanceof.getType = function ( obj ) {
var type = typeof obj;
switch ( type ) {
case 'number': return isNaN( obj ) ? 'NaN' : type;
case 'object': return Array.isArray( obj ) ? 'Array' : ( obj === null ? 'null' : type );
default: return type;
}
}
/* --------------------------------- _Instanceof --------------------------------- */

@@ -40,53 +59,32 @@

case 'nan':
return typeof obj == 'number' && isNaN( obj )
break;
case 'nan': return typeof obj == 'number' && isNaN( obj );
case Object:
case 'object':
return !Array.isArray( obj ) && obj !== null && typeof obj == 'object'
break;
case 'object': return !Array.isArray( obj ) && obj !== null && typeof obj == 'object';
case Array:
case 'array':
return Array.isArray( obj )
break;
case 'array': return Array.isArray( obj );
case String:
case 'string':
return typeof obj == 'string'
break;
case 'string': return typeof obj == 'string';
case Number:
case 'number':
return typeof obj == 'number' && !isNaN( obj )
break;
case 'number': return typeof obj == 'number' && !isNaN( obj );
case Boolean:
case 'boolean':
return typeof obj == 'boolean'
break;
case 'boolean': return typeof obj == 'boolean';
case Function:
case 'function':
return typeof obj == 'function'
break;
case 'function': return typeof obj == 'function';
case null:
case 'null':
return obj === null
break;
case 'null': return obj === null;
case undefined:
case 'undefined':
return obj === undefined
break;
case 'undefined': return obj === undefined;
case Symbol:
case 'symbol':
return typeof obj == 'symbol'
break;
case 'symbol': return typeof obj == 'symbol';
default:
return obj instanceof type;
default: return obj instanceof type;
}

@@ -93,0 +91,0 @@ }

{
"name": "instanceof",
"version": "1.0.2",
"version": "1.0.3",
"description": "JavaScript all types detection module (crossbrowser)",

@@ -5,0 +5,0 @@ "main": "index.js",

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

@@ -23,2 +24,9 @@ **Usage:**

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'
```