@bemoje/assert-constructor

1.0.1 • Public • Published

@bemoje/assert-constructor

Throws TypeError if 'value' is not a constructor.

Version

NPM version

Travis CI

dependencies

Dependencies

dependencies

Stats

NPM downloads Forks

Donate

Buy Me A Beer donate button PayPal donate button

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

/@bemoje/assert-constructor/

    Package Sidebar

    Install

    npm i @bemoje/assert-constructor

    Weekly Downloads

    0

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    8.18 kB

    Total Files

    5

    Last publish

    Collaborators

    • bemoje