Files
common/docs/is.md
T
Jaco Greeff 0f2b423160 Add number conversion utilities (#29)
* Add number conversion utilities

* Update after checks

* Add isNull
2017-11-29 21:22:49 +01:00

3.5 KiB

is

Type checking utilities

isBN

Tests for a BN object instance.

isBN (value: any): boolean

Checks to see if the input object is an instance of BN (bn.js).

import BN from 'bn.js';
import { isBN } from '@polkadot/util';

console.log('isBN', isBN(new BN(1))); // => true

isBuffer

Tests for a Buffer object instance.

isBuffer (value: any): boolean

Checks to see if the input object is an instance of Buffer.

import { isBuffer } from '@polkadot/util';

console.log('isBuffer', isBuffer(Buffer.from([]))); // => true

isError

Tests for a Error object instance.

isError (value: any): boolean

Checks to see if the input object is an instance of Error.

import { isError } from '@polkadot/util';

console.log('isError', isError(new Error('message'))); // => true

isFunction

Tests for a function.

isFunction (value: any): boolean

Checks to see if the input value is a JavaScript function.

import { isFunction } from '@polkadot/util';

console.log('isFunction', isFunction(() => false)); // => true

isHex

Tests for a hex string.

isHex (value: any): boolean

Checks to see if the input value is a 0x prefixed hex string.

import { isHex } from '@polkadot/util';

console.log('isHex', isHex('0x1234')); // => true

isInstanceOf

Tests for a instance of a class.

isInstanceOf (value: any, clazz: any): boolean

Checks to see if the input value is an instance of the test class.

import { isInstanceOf } from '@polkadot/util';

console.log('isinstanceOf', isInstanceOf(new Array(0), Array)); // => true

isNull

Tests for a null values.

isNull (value: any): boolean

Checks to see if the input value is null.

import { isNull } from '@polkadot/util';

console.log('isNull', isNull(null)); // => true

isNumber

Tests for a JavaScript number.

isNumber (value: any): boolean

Checks to see if the input value is a valid number.

import { isNumber } from '@polkadot/util';

console.log('isNumber', isNumber(1234)); // => true

isString

Tests for a string.

isString (value: any): boolean

Checks to see if the input value is a JavaScript string.

import { isString } from '@polkadot/util';

console.log('isString', isString('test')); // => true

isUint8Array

Tests for a Uint8Array object instance.

isUint8Array (value: any): boolean

Checks to see if the input object is an instance of Uint8Array.

import { isUint8Array } from '@polkadot/util';

console.log('isUint8Array', isUint8Array([])); // => false

isUndefined

Tests for a undefined values.

isUndefined (value: any): boolean

Checks to see if the input value is undefined.

import { isUndefined } from '@polkadot/util';

console.log('isUndefined', isUndefined(void(0))); // => true