Skip to content

Function: float() ​

Call Signature ​

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

Create a floating-point argument schema with optional range validation.

Rejects NaN and Infinity values.

Type Parameters ​

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

Parameters ​

NameTypeDescription
optsFloatOptions & { required: R }Range options.

Returns ​

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

Examples ​

ts
const args = {
  ratio: float({ min: 0, max: 1 })
}

Call Signature ​

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

Create a floating-point argument schema with optional range validation.

Rejects NaN and Infinity values.

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
optsFloatOptions & { required?: R }Range options. (optional)

Returns ​

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

Examples ​

ts
const args = {
  ratio: float({ min: 0, max: 1 })
}

Call Signature ​

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

Create a floating-point argument schema with optional range validation.

Rejects NaN and Infinity values.

Parameters ​

NameTypeDescription
optsFloatOptionsRange options. (optional)

Returns ​

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

Examples ​

ts
const args = {
  ratio: float({ min: 0, max: 1 })
}

Released under the MIT License.