Home Reference Source Test
public class | source

Rule

The Rule class validates only one value once a rule is created it can be used multiple times

Static Method Summary

Static Public Methods
public static

addCustom(name: String, rule: Function)

Add custom rule to the Rule class

Constructor Summary

Public Constructor
public

constructor(obj: String | Object, error: String)

Member Summary

Public Members
public

error: *

public
public

rule: {"type": *}

Method Summary

Public Methods
public

getError(path: *, value: *, key: *): [String]

returns a list of errors if they are present

public

test(val: any, obj: Object | String, path: String): boolean

public

Tests the validity of the constructor object thows an error if the object is invalid

public

Tests the validity of the constructor object thows an error if the object is invalid tests if all the keys are valid

Private Methods
private

getRuleOperators(): [String]

Returns a list of the operators when multiple types given its the case for example int|float

private

getTypes(): [String]

converts array from string if multiple types given in type its the case for exemple int|float

private

testOneRule(val: *, obj: Object, type: String, path: String): boolean

Static Public Methods

public static addCustom(name: String, rule: Function) source

Add custom rule to the Rule class

Params:

NameTypeAttributeDescription
name String

the name of the rule

rule Function

the validation function

Public Constructors

public constructor(obj: String | Object, error: String) source

Params:

NameTypeAttributeDescription
obj String | Object

the rule object it describes a the test that are ran by the Rule

error String

the error returned when the tested input is not correct

Public Members

public error: * source

public errorCollector: * source

public rule: {"type": *} source

Public Methods

public getError(path: *, value: *, key: *): [String] source

returns a list of errors if they are present

Params:

NameTypeAttributeDescription
path *
value *
key *

Return:

[String]

public test(val: any, obj: Object | String, path: String): boolean source

Params:

NameTypeAttributeDescription
val any

the value to be tested

obj Object | String

the error object or string thats showed on error

path String

the path to the tested value this is used when using validator to keep track of the prop value ex: obj.min

Return:

boolean

public testEntryObject() source

Tests the validity of the constructor object thows an error if the object is invalid

public testEntryObjectOneType(type: *) source

Tests the validity of the constructor object thows an error if the object is invalid tests if all the keys are valid

Params:

NameTypeAttributeDescription
type *

Private Methods

private getRuleOperators(): [String] source

Returns a list of the operators when multiple types given its the case for example int|float

Return:

[String]

private getTypes(): [String] source

converts array from string if multiple types given in type its the case for exemple int|float

Return:

[String]

private testOneRule(val: *, obj: Object, type: String, path: String): boolean source

Params:

NameTypeAttributeDescription
val *

value to be tested

obj Object

error object

type String

the type from getTypes()

path String

the path to the value if Validator is used

Return:

boolean