@bemoje/assert-constructor
Throws TypeError if 'value' is not a constructor.
Version
Travis CI
Dependencies
Stats
Donate
Installation
npm install @bemoje/assert-constructor
npm install --save @bemoje/assert-constructor
npm install --save-dev @bemoje/assert-constructor
Usage
import assertConstructor from '@bemoje/assert-constructor'
function constructorName(ctor) {
assertConstructor(ctor)
return ctor.name
}
constructorName(class MyClass {})
//=> 'MyClass
constructorName(function MyClass() {})
//=> 'MyClass
try {
constructorName(() => {})
//=> throw TypeError('Expected class constructor, got Function')
} catch (e) {
console.log(e)
}
try {
constructorName('asd')
//=> throw TypeError('Expected class constructor, got String')
} catch (e) {
console.log(e)
}
Tests
Uses Jest to test module functionality. Run tests to get coverage details.
npm run test
API
assertConstructor
Throws TypeError if 'value' is not a constructor.
Parameters
-
value
any The value to evaluate
Returns
void