Skip to main content

Class: NativeEnumValidator<T>

Type parameters

NameType
Textends NativeEnumLike

Hierarchy

Constructors

constructor

new NativeEnumValidator<T>(enumShape): NativeEnumValidator<T>

Type parameters

NameType
Textends NativeEnumLike

Parameters

NameType
enumShapeT

Returns

NativeEnumValidator<T>

Overrides

BaseValidator.constructor

Defined in

projects/shapeshift/src/validators/NativeEnumValidator.ts:12

Properties

constraints

Protected constraints: readonly IConstraint<T[keyof T], T[keyof 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


enumKeys

Private Readonly enumKeys: string[]

Defined in

projects/shapeshift/src/validators/NativeEnumValidator.ts:9


enumMapping

Private Readonly enumMapping: Map<string | number, T[keyof T]>

Defined in

projects/shapeshift/src/validators/NativeEnumValidator.ts:10


enumShape

Readonly enumShape: T

Defined in

projects/shapeshift/src/validators/NativeEnumValidator.ts:7


hasNumericElements

Readonly hasNumericElements: boolean = false

Defined in

projects/shapeshift/src/validators/NativeEnumValidator.ts:8


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

array

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

Returns

ArrayValidator<T[], T>

Inherited from

BaseValidator.array

Defined in

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


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


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

Methods

addConstraint

addConstraint(constraint): this

Parameters

NameType
constraintIConstraint<T[keyof T], T[keyof T]>

Returns

this

Inherited from

BaseValidator.addConstraint

Defined in

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


clone

clone(): this

Returns

this

Overrides

BaseValidator.clone

Defined in

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


default

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

Parameters

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

Returns

DefaultValidator<Exclude<T[keyof 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


getValidationEnabled

getValidationEnabled(): null | boolean

Returns

null | boolean

Inherited from

BaseValidator.getValidationEnabled

Defined in

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


handle

handle(value): Result<T[keyof T], ValidationError | UnknownEnumValueError>

Parameters

NameType
valueunknown

Returns

Result<T[keyof T], ValidationError | UnknownEnumValueError>

Overrides

BaseValidator.handle

Defined in

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


is

is<R>(value): value is R

Type parameters

NameType
Rextends string | number = T[keyof T]

Parameters

NameType
valueunknown

Returns

value is R

Inherited from

BaseValidator.is

Defined in

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


or

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

Type parameters

Name
O

Parameters

NameType
...predicatesreadonly BaseValidator<O>[]

Returns

UnionValidator<T[keyof T] | O>

Inherited from

BaseValidator.or

Defined in

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


parse

parse<R>(value): R

Type parameters

NameType
Rextends string | number = T[keyof 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[keyof T]) => Result<T[keyof 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[keyof T]) => R

Returns

BaseValidator<O>

Inherited from

BaseValidator.reshape

Defined in

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


run

run(value): Result<T[keyof T], BaseError>

Parameters

NameType
valueunknown

Returns

Result<T[keyof 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[keyof T]) => T[keyof 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[keyof 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> = NativeEnumValidator<T>

Parameters

NameType
keyKey
optionsWhenOptions<This, Key>

Returns

this

Inherited from

BaseValidator.when

Defined in

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