Skip to main content
Version: 11.x

Function: assertInRange()

assertInRange(input, lowerBound, upperBound, inputName?): void

Defined in: src/utils/num.ts:168

Asserts input is within [lowerBound, upperBound], both bounds included.

The inputName parameter names the input in the assertion message.

Parameters​

input​

BigNumberish

Value to check

lowerBound​

BigNumberish

Lower bound value, included

upperBound​

BigNumberish

Upper bound value, included

inputName?​

string = ''

Name of the input for error message

Returns​

void

Throws​

Error if input is out of range

Example​

const input1:BigNumberish = 10;
assertInRange(input1, 5, 20, 'amount')

const input2: BigNumberish = 25;
assertInRange(input2, 5, 20, 'amount');
// throws Error: Value is out of amount range [5, 20]