UNPKG

772 BJavaScriptView Raw
1import { isClass } from './class.js';
2/**
3 * @name isChildClass
4 * @summary Tests if the child extends the parent Class
5 * @description
6 * Checks to see if the child Class extends the parent Class
7 * @example
8 * <BR>
9 *
10 * ```javascript
11 * import { isChildClass } from '@polkadot/util';
12 *
13 * console.log('isChildClass', isChildClass(BN, BN); // => true
14 * console.log('isChildClass', isChildClass(BN, Uint8Array); // => false
15 * ```
16 */
17export function isChildClass(Parent, Child) {
18 // https://stackoverflow.com/questions/30993434/check-if-a-constructor-inherits-another-in-es6/30993664
19 return isClass(Child) && isClass(Parent)
20 // eslint-disable-next-line no-prototype-builtins
21 ? Parent === Child || Parent.isPrototypeOf(Child)
22 : false;
23}