@polkadot/util
Version:
A collection of useful utilities for @polkadot
19 lines (18 loc) • 475 B
JavaScript
/**
* @name isInstanceOf
* @summary Tests for a instance of a class.
* @description
* Checks to see if the input value is an instance of the test class.
* @example
* <BR>
*
* ```javascript
* import { isInstanceOf } from '@polkadot/util';
*
* console.log('isInstanceOf', isInstanceOf(new Array(0), Array)); // => true
* ```
*/
export function isInstanceOf(value, Clazz) {
return (((value && value.constructor) === Clazz) ||
value instanceof Clazz);
}