new Isntit(rulesopt, optionsopt)
A simple javascript validation library
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
rules |
Rules |
<optional> |
{} | Validation rules |
options |
Options |
<optional> |
{} | Runtime options |
Methods
(static) getCheckers() → {Checkers}
Get the collection of steps and checkers currently in use.
Returns:
The current Checkers.
- Type
- Checkers
(static) isEmpty(obj) → {boolean}
Check if an object is considered as empty.
Parameters:
Name | Type | Description |
---|---|---|
obj |
* | Any javascript object |
Returns:
Return if given object is empty or not.
- Type
- boolean
(static) printf(str, replacements) → {string}
Parse a string to replace placeholders.
Parameters:
Name | Type | Description |
---|---|---|
str |
string | The string to parse for `%{placeholder}`. |
replacements |
Object.<string, string> | A collection of placeholder: value. |
Returns:
The string with
placeholders replaced with
corresponding values.
If there is no match for
placeholder: value in
replacements, then `%{placeholder}`
will remain in the string.
- Type
- string
(static) registerChecker(checker, name, step, checkersSteps)
Register a checker. You may add a checker to a new or existing step or override an existing checker.
Parameters:
Name | Type | Description |
---|---|---|
checker |
Checker | The checker to register. |
name |
string | The name to use. |
step |
string | The step to register this checker to |
checkersSteps |
Array.<string> | A list of steps to use dureing validation. Note that the order matters. |
checkRules(rules) → {boolean}
Check that the format of given rules comply with the
registered checkers's TypeRule definitions.
Note : this method is only enabled when the source code is build with `config.env !== 'production'`
Note : this method is only enabled when the source code is build with `config.env !== 'production'`
Parameters:
Name | Type | Description |
---|---|---|
rules |
Rules | The Rules set to check |
- Source:
Returns:
Whether given Rules set comply with the Checkers type definitions.
- Type
- boolean
validate(data, rulesopt) → {boolean|Object.<string, string>}
Validate given data.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
data |
Object.<string, *> | The data to validate. | ||
rules |
Rules |
<optional> |
this.rules | The rules to validate aginst. If omited, the rules passed to the constructor are used. |
Returns:
Returns true if all data validates or a collection of fieldName-errorMessage pairs.
- Type
- boolean | Object.<string, string>