Interf is fast and small javascript library.
It makes possible to determine whether a object is an instantiated of a class that implements an interface.
And it is possible to copy class and class.prototype properties by mix().in() too.
Basic usage
const Quackable = interf . create ( ' Quackable ' ) ;
const Duck = interf . implement ( Quackable ) . in ( class Duck { } ) ;
const donald = new Duck ( ) ;
Quackable . isInterfaceOf ( donald ) ;
Download
Installation
Using npm:
$ npm install --save interf
In Node.js:
const interf = require ( ' interf ' ) ;
In a browser:
< script src = " interf.js " > < / script >
Configuration
interf . configure ( {
warn : false ,
debug : false ,
afterImplement : false ,
descriptor : {
configurable : true ,
writable : false ,
enumerable : false ,
} ,
callbacks : {
warn : ( data ) => {
if ( typeof console === ' object ' && console . warn ) {
console . warn ( data . message ) ;
}
} ,
debug : ( data ) => {
if ( typeof console === ' object ' && console . log ) {
console . log ( data . message , data ) ;
}
} ,
afterImplement : ( classInterfaces , Class , interfaces ) => { } ,
} ,
mixin : {
createInit : true ,
interfaces : true ,
replace : true ,
notConfigurableNotWritableError : true ,
ignore : {
protoProps : [
' constructor ' ,
' apply ' ,
' bind ' ,
' call ' ,
' isGenerator ' ,
' toSource ' ,
' toString ' ,
' __proto__ ' ,
] ,
staticProps : [
' arguments ' ,
' arity ' ,
' caller ' ,
' length ' ,
' name ' ,
' displayName ' ,
' prototype ' ,
' __proto__ ' ,
] ,
} ,
} ,
} ) ;
Support
Tested in:
Chrome 58 - 59
Firefox 54
IE 9 - 11
Safari 5.1.7
Opera 45
Node.js 6
PhantomJS 2.1.14
License
Interf is released under the MIT license