Validator
Hierarchy
- Validator
Implements
- Validator
- Validator
Index
Constructors
Methods
- getAllValidators
- getOrder
- getValidator
- getValidatorOrThrow
- getValidators
- hasValidator
- isInstanceOf
- isValid
- overrideValidator
- registerValidator
- removeValidator
- setOrder
- setValidators
- validate
Constructors
constructor
+ new Validator(validators?
: Map‹string, PatternValidator›): Validator
Creates an instance of Validator. Creates an instance of Validator.
Parameters:
Name | Type | Description |
---|---|---|
validators? | Map‹string, PatternValidator› | Optional 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:
Name | Type | Description |
---|---|---|
kind | string | Identifier 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:
Name | Type | Description |
---|---|---|
kind | string | Identifier 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:
Name | Type | Description |
---|---|---|
kind | string | Identifier 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:
Name | Type | Description |
---|---|---|
value | any | Value that needs to validated. |
expectation | Expectation | Expectation 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:
Name | Type | Description |
---|---|---|
value | any | Value that needs to validated. |
expectation | Expectation | Explicit Pattern instance, instance of Utility or implicit expectation against which value will be validated. |
isStrict? | boolean | Optional 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:
Name | Type | Description |
---|---|---|
kind | string | Identifier for which type, PatternValidator instance is mapped. |
validator | PatternValidator | Validator 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:
Name | Type | Description |
---|---|---|
kind | string | Id for which mapping will be created. |
validator | PatternValidator | Validator for registration. |
shouldOverride? | boolean | Optional 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:
Name | Type | Description |
---|---|---|
kind | string | Identifier 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:
Name | Type | Description |
---|---|---|
order | string[] | 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:
Name | Type | Description |
---|---|---|
validators | Map‹string, PatternValidator› | Map 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:
Name | Type | Description |
---|---|---|
value | any | Value that needs to validated. |
expectation | Expectation | Explicit Pattern instance, instance of Utility or implicit expectation against which value will be validated. |
isStrict? | boolean | Flag indicating that evaluation should be done in strict mode. |
Returns: boolean
Returns true
if validation is successful, else throws.