@produck/is-sub-constructor
v1.0.2
Published
Use a modern way to check if a constructor is a sub-constructor (derived class) of another.
Readme
@produck/is-sub-constructor
Check if a constructor is a sub-constructor (derived class) of another.
Installation
npm install @produck/is-sub-constructorUsage
import { isSubConstructor } from "@produck/is-sub-constructor";
class Animal {}
class Dog extends Animal {}
class Bulldog extends Dog {}
isSubConstructor(Dog, Animal); // true
isSubConstructor(Bulldog, Animal); // true
isSubConstructor(Animal, Animal); // false
isSubConstructor(Animal, Dog); // false
isSubConstructor(123, Animal); // false
isSubConstructor(Array, Object); // trueAPI
isSubConstructor(value, base)
Returns true if value is a sub-constructor (derived class) of base,
false otherwise.
- value
unknown- The value to check. - base
constructor- The base constructor to check against. - Returns
boolean - Throws
TypeError- Ifbaseis not a constructor.
License
MIT
