is-constructable provides a type predicate for identifying if a function is constructable, i.e. whether it can be used with the new operator, without actually invoking the constructor.
Install
# If you use npmnpm install is-constructable# If you use yarnyarn add is-constructable
Note: If you transpile to ES5 or below, your transpiler will convert some or all of your arrow functions, async functions, async arrow functions, generator functions and async generator functions to plain old functions, which are constructable in contrast to the original objects.
Under the hoood, the library implements two equivalent checks, one using Reflect and one using Proxy, which can be imported explicitly if so desired.
isConstructable will first attempt the check using Proxy and only if that fails, it will try to using the check using Reflect, because the Proxy check is about 3.3 times faster than the check using Reflect.