apps-script-utils 2.1.1 Help

requireCountable

function requireCountable( value: unknown, message: string = "Expected a non-negative safe integer." ): number;

A value that can serve as a quantity, a length or a zero-based index: a whole number, not negative, and small enough that integer arithmetic on it is still exact.

isX and nonX answer a question and never interrupt control flow; requireX and requireNonX hand the value back or throw. The scheme is explained in Validation conventions.

Parameters

Parameter

Type

Description

value

unknown

The value to validate.

message (optional) = "Expected a non-negative safe integer."

string

The message of the exception. A default is used when omitted.

Returns

number — the same value, typed as a countable number.

Throws

Exception

Condition

IllegalArgumentException

the value is not a countable number.

Examples

What passes and what does not

requireCountable(0); // => 0 requireCountable(42); // => 42 requireCountable(-1); // throws IllegalArgumentException requireCountable(1.5); // throws IllegalArgumentException

See also

Source

src/lang/number/requireCountable.ts

23 September 2026

This documentation was generated with AI (Claude) from the library's source code.