Skip to main content

Class: NumberValidator<T>

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:21

Extends

Type Parameters

Type Parameter
T extends number

Constructors

new NumberValidator()

new NumberValidator<T>(validatorOptions: ValidatorOptions, constraints: readonly IConstraint<T, T>[]): NumberValidator<T>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:22

Parameters

ParameterTypeDefault value
validatorOptionsValidatorOptions{}
constraintsreadonly IConstraint<T, T>[][]

Returns

NumberValidator<T>

Inherited from

BaseValidator.constructor

Properties

constraints

protected constraints: readonly IConstraint<T, T>[] = []

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:19

Inherited from

BaseValidator.constraints


description?

optional description: string

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:16

Inherited from

BaseValidator.description


isValidationEnabled

protected isValidationEnabled: null | boolean | () => boolean = null

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:20

Inherited from

BaseValidator.isValidationEnabled


parent?

protected optional parent: object

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:18

Inherited from

BaseValidator.parent


validatorOptions

protected validatorOptions: ValidatorOptions

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:17

Inherited from

BaseValidator.validatorOptions

Accessors

shouldRunConstraints

Get Signature

get protected shouldRunConstraints(): boolean

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:143

Returns

boolean

Inherited from

BaseValidator.shouldRunConstraints

Methods

abs()

abs(options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:74

Parameters

ParameterType
optionsValidatorOptions

Returns

this


addConstraint()

protected addConstraint(constraint: IConstraint<T, T>, validatorOptions: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:155

Parameters

ParameterType
constraintIConstraint<T, T>
validatorOptionsValidatorOptions

Returns

this

Inherited from

BaseValidator.addConstraint


array()

array(options: ValidatorOptions): ArrayValidator<T[], T>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:44

Parameters

ParameterType
optionsValidatorOptions

Returns

ArrayValidator<T[], T>

Inherited from

BaseValidator.array


ceil()

ceil(options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:98

Parameters

ParameterType
optionsValidatorOptions

Returns

this


clone()

protected clone(): this

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:147

Returns

this

Inherited from

BaseValidator.clone


default()

default(value: Exclude<T, undefined> | () => Exclude<T, undefined>, options: ValidatorOptions): DefaultValidator<Exclude<T, undefined>>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:81

Parameters

ParameterType
valueExclude<T, undefined> | () => Exclude<T, undefined>
optionsValidatorOptions

Returns

DefaultValidator<Exclude<T, undefined>>

Inherited from

BaseValidator.default


describe()

describe(description: string): this

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:96

Parameters

ParameterType
descriptionstring

Returns

this

Inherited from

BaseValidator.describe


divisibleBy()

divisibleBy(divider: number, options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:70

Parameters

ParameterType
dividernumber
optionsValidatorOptions

Returns

this


equal()

equal<N>(number: N, options: ValidatorOptions): NumberValidator<N>

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:38

Type Parameters

Type Parameter
N extends number

Parameters

ParameterType
numberN
optionsValidatorOptions

Returns

NumberValidator<N>


finite()

finite(options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:58

Parameters

ParameterType
optionsValidatorOptions

Returns

this


floor()

floor(options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:86

Parameters

ParameterType
optionsValidatorOptions

Returns

this


fround()

fround(options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:90

Parameters

ParameterType
optionsValidatorOptions

Returns

this


getValidationEnabled()

getValidationEnabled(): null | boolean

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:139

Returns

null | boolean

Inherited from

BaseValidator.getValidationEnabled


greaterThan()

greaterThan(number: number, options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:30

Parameters

ParameterType
numbernumber
optionsValidatorOptions

Returns

this


greaterThanOrEqual()

greaterThanOrEqual(number: number, options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:34

Parameters

ParameterType
numbernumber
optionsValidatorOptions

Returns

this


handle()

protected handle(value: unknown): Result<T, ValidationError>

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:102

Parameters

ParameterType
valueunknown

Returns

Result<T, ValidationError>

Overrides

BaseValidator.handle


int()

int(options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:50

Parameters

ParameterType
optionsValidatorOptions

Returns

this


is()

is<R>(value: unknown): value is R

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:124

Type Parameters

Type ParameterDefault type
R extends numberT

Parameters

ParameterType
valueunknown

Returns

value is R

Inherited from

BaseValidator.is


lessThan()

lessThan(number: number, options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:22

Parameters

ParameterType
numbernumber
optionsValidatorOptions

Returns

this


lessThanOrEqual()

lessThanOrEqual(number: number, options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:26

Parameters

ParameterType
numbernumber
optionsValidatorOptions

Returns

this


negative()

negative(options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:66

Parameters

ParameterType
optionsValidatorOptions

Returns

this


notEqual()

notEqual(number: number, options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:44

Parameters

ParameterType
numbernumber
optionsValidatorOptions

Returns

this


nullable()

nullable(options: ValidatorOptions): UnionValidator<null | T>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:36

Parameters

ParameterType
optionsValidatorOptions

Returns

UnionValidator<null | T>

Inherited from

BaseValidator.nullable


nullish()

nullish(options: ValidatorOptions): UnionValidator<undefined | null | T>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:40

Parameters

ParameterType
optionsValidatorOptions

Returns

UnionValidator<undefined | null | T>

Inherited from

BaseValidator.nullish


optional()

optional(options: ValidatorOptions): UnionValidator<undefined | T>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:32

Parameters

ParameterType
optionsValidatorOptions

Returns

UnionValidator<undefined | T>

Inherited from

BaseValidator.optional


or()

or<O>(...predicates: readonly BaseValidator<O>[]): UnionValidator<T | O>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:52

Type Parameters

Type Parameter
O

Parameters

ParameterType
...predicatesreadonly BaseValidator<O>[]

Returns

UnionValidator<T | O>

Inherited from

BaseValidator.or


parse()

parse<R>(value: unknown): R

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:114

Type Parameters

Type ParameterDefault type
R extends numberT

Parameters

ParameterType
valueunknown

Returns

R

Inherited from

BaseValidator.parse


positive()

positive(options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:62

Parameters

ParameterType
optionsValidatorOptions

Returns

this


reshape()

Call Signature

reshape(cb: (input: T) => Result<T>, options?: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:67

Parameters
ParameterType
cb(input: T) => Result<T>
options?ValidatorOptions
Returns

this

Inherited from

BaseValidator.reshape

Call Signature

reshape<R, O>(cb: (input: T) => R, options?: ValidatorOptions): BaseValidator<O>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:68

Type Parameters
Type ParameterDefault type
R extends Result<unknown>-
OInferResultType<R>
Parameters
ParameterType
cb(input: T) => R
options?ValidatorOptions
Returns

BaseValidator<O>

Inherited from

BaseValidator.reshape


round()

round(options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:94

Parameters

ParameterType
optionsValidatorOptions

Returns

this


run()

run(value: unknown): Result<T, BaseError>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:102

Parameters

ParameterType
valueunknown

Returns

Result<T, BaseError>

Inherited from

BaseValidator.run


safeInt()

safeInt(options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:54

Parameters

ParameterType
optionsValidatorOptions

Returns

this


set()

set(options: ValidatorOptions): SetValidator<T>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:48

Parameters

ParameterType
optionsValidatorOptions

Returns

SetValidator<T>

Inherited from

BaseValidator.set


setParent()

setParent(parent: object): this

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:27

Parameters

ParameterType
parentobject

Returns

this

Inherited from

BaseValidator.setParent


setValidationEnabled()

setValidationEnabled(isValidationEnabled: null | boolean | () => boolean): this

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:133

Sets if the validator should also run constraints or just do basic checks.

Parameters

ParameterTypeDescription
isValidationEnablednull | boolean | () => booleanWhether this validator should be enabled or disabled. You can pass boolean or a function returning boolean which will be called just before parsing. Set to null to go off of the global configuration.

Returns

this

Inherited from

BaseValidator.setValidationEnabled


sign()

sign(options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:78

Parameters

ParameterType
optionsValidatorOptions

Returns

this


transform()

Call Signature

transform(cb: (value: T) => T, options?: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:56

Parameters
ParameterType
cb(value: T) => T
options?ValidatorOptions
Returns

this

Inherited from

BaseValidator.transform

Call Signature

transform<O>(cb: (value: T) => O, options?: ValidatorOptions): BaseValidator<O>

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:57

Type Parameters
Type Parameter
O
Parameters
ParameterType
cb(value: T) => O
options?ValidatorOptions
Returns

BaseValidator<O>

Inherited from

BaseValidator.transform


trunc()

trunc(options: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/NumberValidator.ts:82

Parameters

ParameterType
optionsValidatorOptions

Returns

this


when()

when<Key, This>(key: Key, options: WhenOptions<This, Key>, validatorOptions?: ValidatorOptions): this

Defined in: projects/shapeshift/src/validators/BaseValidator.ts:88

Type Parameters

Type ParameterDefault type
Key extends WhenKey-
This extends BaseValidator<any>NumberValidator<T>

Parameters

ParameterType
keyKey
optionsWhenOptions<This, Key>
validatorOptions?ValidatorOptions

Returns

this

Inherited from

BaseValidator.when