Skip to content

Function: number() ​

Call Signature ​

ts
export declare function number<const R extends boolean>(opts: NumberOptions & {
  required: R;
}): WithRequiredOption<CombinatorSchema<number>, R>

Create a number argument schema with optional range validation.

Accepts any numeric value (integer or float).

Type Parameters ​

NameDescription
R extends booleanThe type of required in the options, which the schema keeps.

Parameters ​

NameTypeDescription
optsNumberOptions & { required: R }Range options.

Returns ​

WithRequiredOption<CombinatorSchema<number>, R> — A combinator schema that resolves to number.

Examples ​

ts
const args = {
  timeout: number({ min: 0, max: 30000 })
}

Call Signature ​

ts
export declare function number<const R extends boolean | undefined = boolean | undefined>(opts?: NumberOptions & {
  required?: R;
}): WithUnrequiredOption<CombinatorSchema<number>, R>

Create a number argument schema with optional range validation.

Accepts any numeric value (integer or float).

Type Parameters ​

NameDescription
R extends boolean | undefined = boolean | undefinedThe type of required in the options, which the schema keeps when it may be false but not true, as for optional ? { required: false } : {}, so that a positional argument with it is optional.

Parameters ​

NameTypeDescription
optsNumberOptions & { required?: R }Range options. (optional)

Returns ​

WithUnrequiredOption<CombinatorSchema<number>, R> — A combinator schema that resolves to number.

Examples ​

ts
const args = {
  timeout: number({ min: 0, max: 30000 })
}

Call Signature ​

ts
export declare function number(opts?: NumberOptions): CombinatorSchema<number>

Create a number argument schema with optional range validation.

Accepts any numeric value (integer or float).

Parameters ​

NameTypeDescription
optsNumberOptionsRange options. (optional)

Returns ​

CombinatorSchema<number> — A combinator schema that resolves to number.

Examples ​

ts
const args = {
  timeout: number({ min: 0, max: 30000 })
}

Released under the MIT License.