Skip to main content

Class: NumberValidator<T>

Type parameters

NameType
Textends number

Hierarchy

Constructors

constructor

new NumberValidator<T>(constraints?): NumberValidator<T>

Type parameters

NameType
Textends number

Parameters

NameTypeDefault value
constraintsreadonly IConstraint<T, T>[][]

Returns

NumberValidator<T>

Inherited from

BaseValidator.constructor

Defined in

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

Properties

constraints

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

Inherited from

BaseValidator.constraints

Defined in

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


description

Optional description: string

Inherited from

BaseValidator.description

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:15


isValidationEnabled

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

Inherited from

BaseValidator.isValidationEnabled

Defined in

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


parent

Protected Optional parent: object

Inherited from

BaseValidator.parent

Defined in

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

Accessors

abs

get abs(): this

Returns

this

Defined in

projects/shapeshift/src/validators/NumberValidator.ts:73


array

get array(): ArrayValidator<T[], T>

Returns

ArrayValidator<T[], T>

Inherited from

BaseValidator.array

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:41


ceil

get ceil(): this

Returns

this

Defined in

projects/shapeshift/src/validators/NumberValidator.ts:97


finite

get finite(): this

Returns

this

Defined in

projects/shapeshift/src/validators/NumberValidator.ts:57


floor

get floor(): this

Returns

this

Defined in

projects/shapeshift/src/validators/NumberValidator.ts:85


fround

get fround(): this

Returns

this

Defined in

projects/shapeshift/src/validators/NumberValidator.ts:89


int

get int(): this

Returns

this

Defined in

projects/shapeshift/src/validators/NumberValidator.ts:49


negative

get negative(): this

Returns

this

Defined in

projects/shapeshift/src/validators/NumberValidator.ts:65


nullable

get nullable(): UnionValidator<null | T>

Returns

UnionValidator<null | T>

Inherited from

BaseValidator.nullable

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:33


nullish

get nullish(): UnionValidator<undefined | null | T>

Returns

UnionValidator<undefined | null | T>

Inherited from

BaseValidator.nullish

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:37


optional

get optional(): UnionValidator<undefined | T>

Returns

UnionValidator<undefined | T>

Inherited from

BaseValidator.optional

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:29


positive

get positive(): this

Returns

this

Defined in

projects/shapeshift/src/validators/NumberValidator.ts:61


round

get round(): this

Returns

this

Defined in

projects/shapeshift/src/validators/NumberValidator.ts:93


safeInt

get safeInt(): this

Returns

this

Defined in

projects/shapeshift/src/validators/NumberValidator.ts:53


set

get set(): SetValidator<T>

Returns

SetValidator<T>

Inherited from

BaseValidator.set

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:45


shouldRunConstraints

get shouldRunConstraints(): boolean

Returns

boolean

Inherited from

BaseValidator.shouldRunConstraints

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:120


sign

get sign(): this

Returns

this

Defined in

projects/shapeshift/src/validators/NumberValidator.ts:77


trunc

get trunc(): this

Returns

this

Defined in

projects/shapeshift/src/validators/NumberValidator.ts:81

Methods

addConstraint

addConstraint(constraint): this

Parameters

NameType
constraintIConstraint<T, T>

Returns

this

Inherited from

BaseValidator.addConstraint

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:132


clone

clone(): this

Returns

this

Inherited from

BaseValidator.clone

Defined in

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


default

default(value): DefaultValidator<Exclude<T, undefined>>

Parameters

NameType
valueExclude<T, undefined> | () => Exclude<T, undefined>

Returns

DefaultValidator<Exclude<T, undefined>>

Inherited from

BaseValidator.default

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:65


describe

describe(description): this

Parameters

NameType
descriptionstring

Returns

this

Inherited from

BaseValidator.describe

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:73


divisibleBy

divisibleBy(divider): this

Parameters

NameType
dividernumber

Returns

this

Defined in

projects/shapeshift/src/validators/NumberValidator.ts:69


equal

equal<N>(number): NumberValidator<N>

Type parameters

NameType
Nextends number

Parameters

NameType
numberN

Returns

NumberValidator<N>

Defined in

projects/shapeshift/src/validators/NumberValidator.ts:37


getValidationEnabled

getValidationEnabled(): null | boolean

Returns

null | boolean

Inherited from

BaseValidator.getValidationEnabled

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:116


greaterThan

greaterThan(number): this

Parameters

NameType
numbernumber

Returns

this

Defined in

projects/shapeshift/src/validators/NumberValidator.ts:29


greaterThanOrEqual

greaterThanOrEqual(number): this

Parameters

NameType
numbernumber

Returns

this

Defined in

projects/shapeshift/src/validators/NumberValidator.ts:33


handle

handle(value): Result<T, ValidationError>

Parameters

NameType
valueunknown

Returns

Result<T, ValidationError>

Overrides

BaseValidator.handle

Defined in

projects/shapeshift/src/validators/NumberValidator.ts:101


is

is<R>(value): value is R

Type parameters

NameType
Rextends number = T

Parameters

NameType
valueunknown

Returns

value is R

Inherited from

BaseValidator.is

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:101


lessThan

lessThan(number): this

Parameters

NameType
numbernumber

Returns

this

Defined in

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


lessThanOrEqual

lessThanOrEqual(number): this

Parameters

NameType
numbernumber

Returns

this

Defined in

projects/shapeshift/src/validators/NumberValidator.ts:25


notEqual

notEqual(number): this

Parameters

NameType
numbernumber

Returns

this

Defined in

projects/shapeshift/src/validators/NumberValidator.ts:43


or

or<O>(...predicates): UnionValidator<T | O>

Type parameters

Name
O

Parameters

NameType
...predicatesreadonly BaseValidator<O>[]

Returns

UnionValidator<T | O>

Inherited from

BaseValidator.or

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:49


parse

parse<R>(value): R

Type parameters

NameType
Rextends number = T

Parameters

NameType
valueunknown

Returns

R

Inherited from

BaseValidator.parse

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:91


reshape

reshape(cb): this

Parameters

NameType
cb(input: T) => Result<T, Error>

Returns

this

Inherited from

BaseValidator.reshape

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:59

reshape<R, O>(cb): BaseValidator<O>

Type parameters

NameType
Rextends Result<unknown, Error>
OInferResultType<R>

Parameters

NameType
cb(input: T) => R

Returns

BaseValidator<O>

Inherited from

BaseValidator.reshape

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:60


run

run(value): Result<T, BaseError>

Parameters

NameType
valueunknown

Returns

Result<T, BaseError>

Inherited from

BaseValidator.run

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:79


setParent

setParent(parent): this

Parameters

NameType
parentobject

Returns

this

Inherited from

BaseValidator.setParent

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:24


setValidationEnabled

setValidationEnabled(isValidationEnabled): this

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

Parameters

NameTypeDescription
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

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:110


transform

transform(cb): this

Parameters

NameType
cb(value: T) => T

Returns

this

Inherited from

BaseValidator.transform

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:53

transform<O>(cb): BaseValidator<O>

Type parameters

Name
O

Parameters

NameType
cb(value: T) => O

Returns

BaseValidator<O>

Inherited from

BaseValidator.transform

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:54


when

when<Key, This>(key, options): this

Type parameters

NameType
Keyextends WhenKey
Thisextends BaseValidator<any> = NumberValidator<T>

Parameters

NameType
keyKey
optionsWhenOptions<This, Key>

Returns

this

Inherited from

BaseValidator.when

Defined in

projects/shapeshift/src/validators/BaseValidator.ts:69