1.1 KiB
1.1 KiB
Functions
assert
▸ assert<T>(test: Falsy | T, message: string | MessageFn, code?: number, data?: any): boolean
Defined in assert.ts:28
name: assert
summary: Checks for a valid test, if not ExtError is thrown.
description: Checks that test is a truthy value. If value is falsy (null, undefined, false, ...), it throws an ExtError with the supplied message and an optional code and data. When test passes, true is returned.
example:
const { assert } from '@polkadot/util';
assert(true, 'True should be true'); // true returned
assert(false, 'False should not be true'); // ExtError thrown
assert(false, () => 'message'); // ExtError with 'message'
Type parameters:
T
Parameters:
| Name | Type | Default value |
|---|---|---|
| test | Falsy | T |
- |
| message | string | MessageFn |
- |
Default value code |
number |
ExtError.CODES.ASSERT |
Optional data |
any |
- |
Returns: boolean