Validator

Hierarchy

  • Validator

Implements

Index

Constructors

Methods

Constructors

constructor

+ new Validator(validators?: Map‹string, PatternValidator›): Validator

Creates an instance of Validator. Creates an instance of Validator.

Parameters:

NameTypeDescription
validators?Map‹string, PatternValidatorOptional mappings of PatternValidator(s) as a Map instance.

Returns: Validator

Methods

getAllValidators

getAllValidators(): Map‹string, PatternValidator

Implementation of Validator

Returns all registered validators.

Returns: Map‹string, PatternValidator

Instance of a Map of all registered validators implementing PatternValidator.


getOrder

getOrder(): string[]

Implementation of Validator

Returns validators order.

Returns: string[]

List with registered validator id's in sorted order.


getValidator

getValidator(kind: string): PatternValidator | undefined

Implementation of Validator

Returns validator by mapping.

Parameters:

NameTypeDescription
kindstringIdentifier for which type, PatternValidator instance is mapped.

Returns: PatternValidator | undefined

Registered validator instance, else undefined.


getValidatorOrThrow

getValidatorOrThrow(kind: string): PatternValidator

Implementation of Validator

Returns validator by mapping or throws.

throws {PatternValidatorNotFoundError} Thrown if pattern validator for kind does not existing on validator.

Parameters:

NameTypeDescription
kindstringIdentifier for which type, PatternValidator instance is mapped.

Returns: PatternValidator

Registered validator instance, else throws.


getValidators

getValidators(): PatternValidator[]

Implementation of Validator

Returns ordered validators.

Returns: PatternValidator[]

Ordered(if order is provided) list of validators.


hasValidator

hasValidator(kind: string): boolean

Implementation of Validator

Evaluates if validator is already registered by mapping id.

Parameters:

NameTypeDescription
kindstringIdentifier for which type, PatternValidator instance is mapped.

Returns: boolean

Returns true if validator is registered, else false.


isInstanceOf

isInstanceOf(value: any, expectation: Expectation): boolean

Implementation of Validator

Validates if a value is instance of expectation.

Parameters:

NameTypeDescription
valueanyValue that needs to validated.
expectationExpectationExpectation as explicit Class, InstanceOf, Interface pattern instance against which value will be validated.

Returns: boolean

Returns true if validation is successful, else false.


isValid

isValid(value: any, expectation: Expectation, isStrict?: boolean): boolean

Implementation of Validator

Validates if a value matches an expectation.

Parameters:

NameTypeDescription
valueanyValue that needs to validated.
expectationExpectationExplicit Pattern instance, instance of Utility or implicit expectation against which value will be validated.
isStrict?booleanOptional flag indicating that evaluation should be done in strict mode.

Returns: boolean

Returns true if validation is successful, else false.


overrideValidator

overrideValidator(kind: string, validator: PatternValidator): void

Implementation of Validator

Overrides already existing validator by mapping on delegator.

Parameters:

NameTypeDescription
kindstringIdentifier for which type, PatternValidator instance is mapped.
validatorPatternValidatorValidator for registration.

Returns: void


registerValidator

registerValidator(kind: string, validator: PatternValidator, shouldOverride?: boolean): void

Implementation of Validator

Registers validator on delegator.

throws {PatternValidatorExistError} Thrown if mapping would overridden on delegator without explicit call.

Parameters:

NameTypeDescription
kindstringId for which mapping will be created.
validatorPatternValidatorValidator for registration.
shouldOverride?booleanOptional flag indicating that mapping should be overridden if exist.

Returns: void


removeValidator

removeValidator(kind: string): void

Implementation of Validator

Removes validator by mapping id.

Parameters:

NameTypeDescription
kindstringIdentifier for which type, PatternValidator instance is mapped.

Returns: void


setOrder

setOrder(order: string[]): void

Implementation of Validator

Set validators order by list with sorted ids.

Parameters:

NameTypeDescription
orderstring[]List with registered validator id's in sorted order.

Returns: void


setValidators

setValidators(validators: Map‹string, PatternValidator›): void

Implementation of Validator

Sets map of validators.

Parameters:

NameTypeDescription
validatorsMap‹string, PatternValidatorMap instance with of validators implementing PatternValidator.

Returns: void


validate

validate(value: any, expectation: Expectation, isStrict?: boolean): boolean

Implementation of Validator

Validates if a value matches an expectation or throws.

remarks Current implementation uses isStrict to differentiate strict validator from the loose one (Collection vs CollectionIncluding) to evaluate if implicit expectation of pattern should use deep strict comparison pattern Collection or allow arbitrary(loose) values by using CollectionIncluding for objects. However, developers can create their own pattern that could use isStrict flag on validation level(simplest example: different implementation of EqualsValidator that could behave more like == in js).

throws {ValidationError} Thrown if the value does not match provided pattern.

throws {UnknownError} Thrown if the value can't be validated by any of registered validators.

Parameters:

NameTypeDescription
valueanyValue that needs to validated.
expectationExpectationExplicit Pattern instance, instance of Utility or implicit expectation against which value will be validated.
isStrict?booleanFlag indicating that evaluation should be done in strict mode.

Returns: boolean

Returns true if validation is successful, else throws.