November's Paddleball Marathon

    arc-is

    1.0.6 • Public • Published

    arc-is

    Build Status

    A simple, efficient but comprehensive typechecking suite

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

    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

    Install

    npm i arc-is

    DownloadsWeekly Downloads

    11,248

    Version

    1.0.6

    License

    ISC

    Unpacked Size

    14.4 kB

    Total Files

    6

    Last publish

    Collaborators

    • avatar