Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

arc-is

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arc-is

Simple is() function for typechecking

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6K
increased by26.26%
Maintainers
1
Weekly downloads
 
Created
Source

arc-is

A simple, efficient but comprehensive typechecking suite

In addition to native typechecking, it provides reliable behavior for:

  • [ES6 new globally available constructor types] (http://www.ecma-international.org/ecma-262/6.0/#sec-constructor-properties-of-the-global-object)
  • ES6 style classes
  • ES6 extended classes (including native subclasses)
  • NaN, Infinity, Null, Undefined

Install

$ npm install --save arc-is

Usage

var is = require('arc-is');
is(someUnknownVariable [,returnObjectType]); 

Params

  • someUnknownVariable is the variable you want to typecheck.
  • returnObjectType is optional and tells the function if you want it to return a complex type (non native) if available. If false, is() will always return a lowercase string, otherwise it will return a case sensitive string.

Examples

var simpleObj = {};
is(simpleObj); //Returns 'object'
is(simpleObj,true); //Returns 'Object'

var es6global = new Map;
is(es6global); //Returns 'map'
is(es6global,true); //Returns 'Map'

class MyClass{ toString(){ return '[object '+this.constructor.name+']'; } }
is(new MyClass); //Returns 'object'
is(new MyClass,true); //Returns 'MyClass';

class MyArray extends Array{ return '[object '+this.constructor.name+']'; } }
is(new MyArray); //Returns 'array'
is(new MyArray,true); //Returns 'MyArray'

Caveats

  • It is far more efficient to not check for a complexType
  • If a class does not overwrite the toString() method, it will return the parent's toString() which will likely be Object
  • This goes for natively extended globally available classes such as the Error subclasses (ie. TypeError), as these do not overwrite the toString() method, they return the parent's toString() which is Error
  • For is() to return the appropriate class name, toString must return the name in the format of '[object $NAME]' which is standard for all native classes

Keywords

FAQs

Package last updated on 04 Nov 2022

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