Class: QueryValidator

QueryValidator

QueryValidator parses given restrictions on user input and manages user input comparison and validation.

Constructor

new QueryValidator(validationData)

Create QueryValidator.
Parameters:
Name Type Description
validationData string | boolean | RegExp | Array.<string> | Array.<boolean> | Array.<RegExp> Defines basis for user input comparison.
Source:

Members

itemToValidate

Set the itemToValidate value.
Source:

itemToValidate

Get the itemToValidate value.
Source:

Methods

appendBoolean(bool) → {QueryValidator}

Adds a boolean to the list of booleans as well as to the mixture array.
Parameters:
Name Type Description
bool boolean A boolean value to be registered for later comparison.
Source:
Returns:
- This instance.
Type
QueryValidator

appendRegExp(regExp) → {QueryValidator}

Adds a regular expression to the list of regular expressions as well as to the mixture array.
Parameters:
Name Type Description
regExp RegExp A regular espression to be registered for later comparison.
Source:
Returns:
- This instance.
Type
QueryValidator

appendString(string) → {QueryValidator}

Adds a string to the list of strings as well as to the mixture array.
Parameters:
Name Type Description
string string A string to be registered for later comparison.
Source:
Returns:
- This instance.
Type
QueryValidator

booleanStringConversion(value) → {boolean|null}

Convert some known words into booleans
Parameters:
Name Type Description
value string | boolean A word to be potentionally converted into boolean.
Source:
Returns:
- A converted word, passed boolean or null if conversion was not possible/successful.
Type
boolean | null

compareValues(first, second) → {boolean}

Compares two given values, where the first given value is universal for String and RegExp - won't work with Booleans. If a RegExp is passed the comparison is done in the form of a RegExp test on the second value.
Parameters:
Name Type Description
first string | RegExp A first value for comparison.
second string A second value for comparison.
Source:
Returns:
- Returns whether the two given values equal or not.
Type
boolean

hasRule(rule) → {boolean}

Chceck whether such rule has been registered.
Parameters:
Name Type Description
rule string | boolean | RegExp a rule to be searched for in the QueryValidator.
Source:
Returns:
- If a rule was found or not.
Type
boolean

parseRegExpRule(rule) → {RegExp|string|boolean}

Parses a given string into RegExp.
Parameters:
Name Type Description
rule string Takes a string which is in the form of a regular expression like this: "/^[a-zA-Z ]+$/".
Source:
Returns:
- If it could parse the given string returns the final RegExp, otherwise a given string is returned back. In case string was not passed to the method false is returned.
Type
RegExp | string | boolean

parseSingleValidationItem(itemData, depthopt) → {boolean}

Parses a signle validation item designed for a specific QueryItem and assigns it to the apropriete category (String, RegExp, Bool). In addition allows for complex string values separed by commas - dividing them by commas and parsing each item separately.
Parameters:
Name Type Attributes Default Description
itemData string | boolean | RegExp Takes one element for later user input comparison.
depth number <optional>
1 Tells the method how deep in the recursion it is. Default is 1, max depth allowed is 2.
Source:
Returns:
- State of the parse operation, false on error, otherwise true.
Type
boolean

parseValidationData(validationData) → {QueryValidator}

Takes a single expression or an array of expressions designed for a specific QueryItem and pushes them to be registered for later validation comparison.
Parameters:
Name Type Description
validationData string | boolean | RegExp | Array.<string> | Array.<boolean> | Array.<RegExp> Defines basis for user input comparison.
Source:
Returns:
- This instance.
Type
QueryValidator

setMatch(typeopt) → {string}

Sets match type for this QueryValidator to take passed arrays as AND or OR. AND: Each input entry must have a match, OR: At least on given entry must have a match.
Parameters:
Name Type Attributes Description
type string <optional>
Defines given array match type to AND or OR.
Source:
Returns:
- Set validation match option.
Type
string

testValueToAllBooleans(value, indexopt) → {boolean}

Compares given value only to the registered booleans.
Parameters:
Name Type Attributes Description
value boolean A boolean value for comparison.
index number <optional>
If index is given the value is compared only with an item on the specified index.
Source:
Returns:
- Returns whether the given values mathes any of the registered boolean rules or not.
Type
boolean

testValueToAllRegExps(value, indexopt) → {boolean}

Compares given value only to the registered RegExps.
Parameters:
Name Type Attributes Description
value RegExp A RegExp value for comparison.
index number <optional>
If index is given the value is compared only with an item on the specified index.
Source:
Returns:
- Returns whether the given values mathes any of the registered RegExp rules or not.
Type
boolean

testValueToAllStrings(value, indexopt) → {boolean}

Compares given value only to the registered strings.
Parameters:
Name Type Attributes Description
value string A string value for comparison.
index number <optional>
If index is given the value is compared only with an item on the specified index.
Source:
Returns:
- Returns whether the given values mathes any of the registered string rules or not.
Type
boolean

validate(valuesopt) → {boolean}

Validates a preset itemToValidate (InputItem) using the registered rules.
Parameters:
Name Type Attributes Description
values Array.<boolean> | Array.<string> | mixed <optional>
An optional array of booleans, strings or mixed parameter overwiting a value given by InputItem.
Source:
Returns:
- Returns whether the assigned InputItem matches the preset rules.
Type
boolean

validateAnyMixture(values) → {boolean}

Validates any mixture content (array of strings or booleans and any mixture of those) to all inner values.
Parameters:
Name Type Description
values Array.<boolean> | Array.<string> | mixed The itemToValidate value.
Source:
Returns:
- Return true if all values match (AND) or at least one matches (OR).
Type
boolean

validateAnyMixtureInRuleOrder(values) → {boolean}

Validates any mixture content (array of strings or booleans and any mixture of those) to all inner values in rule order.
Parameters:
Name Type Description
values Array.<boolean> | Array.<string> | mixed The itemToValidate value.
Source:
Returns:
- Return true if all values match (AND) or at least one matches (OR).
Type
boolean