Skip to content

yyued/Runtime-Type-Check-Proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Runtime-Type-Check-Proxy

Through "proxy" function, to check the arguments type. It is different from the static methods such as TypeScript and is only used as a lightweight runtime arguments checking function.

简体中文

Type

number / string / boolean / null / array / date / regexp / function / undefined / NaN / Infinity

Installing

$ npm i rtcp --save

or download RTCP.min.js

<script src="./RTCP.min.js"></script>

Example

RTCP.fail(( name, fail ) => {
    console.error( `function ${ name }`, fail );
})

function X ( x ) {
    console.log( x + 1 );
}

function Y ( x, y ) {
    console.log( x + y );
}

RTCP( X, 'number' )( 1 );
RTCP( X, 'number|string' )( '1' );
RTCP( X, 'number' )( '1' ); // fail

RTCP( Y, [ 'number', 'number' ] )( 1, 1 );
RTCP( Y, [ 'number', 'number' ] )( 1, '1' ); // fail

Support as decorator

class X {
    @RTCP( 'string' )
    hello ( name ) {
        console.log( `hello, ${ name }` );
    }
}

( new X() ).hello( 'foo' );
( new X() ).hello(); // fail

License

MIT

About

lightweight runtime arguments checking function.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published