- Source:
Namespaces
Members
(static) VERSION
- Source:
ApproveJs version
Methods
(static) _format()
- Source:
A helper function for formatting strings:
Examples
this._format('i can speak {language} since i was {age}', {language:'javascript',age:10});
this._format('i can speak {0} since i was {1}', 'javascript',10});
(static) _formatErrors(errors, title) → {array}
- Source:
Returns an array of formatted error messages returned by tests that return objects instead of booleans.
Example
this._formatErrors(['array', 'of', 'errors'], title);
Parameters:
Name | Type | Description |
---|---|---|
errors |
array | The array of unformatted errors returned by the test's result. |
title |
string | The title to replace the {title} placeholder with. |
Returns:
The formatted errors
- Type
- array
(static) _message(rule, rules, title) → {string}
- Source:
Returns the correctly formatted message representing the current test's failure.
Example
this._message(rule, rules, title);
Parameters:
Name | Type | Description |
---|---|---|
rule |
string | The current rule being processed. |
rules |
object | The rules object for the value being tested. |
title |
string | The title to replace the {title} placeholder with. |
Returns:
The correctly formatted error message
- Type
- string
(static) addTest(obj, name)
- Source:
Used to extend the default tests with custom tests.
Example
var test = {
expects: false,
message: '{title} did not pass the test.',
validate: function(value) {
return this.strength(value);
},
};
approve.addTest(test, 'test_name');
Parameters:
Name | Type | Description |
---|---|---|
obj |
obj | The test object to add. |
name |
string | The name of the test. |
Returns:
void
(static) configure(obj)
- Source:
Used to configure default values, such as default error messages.
Example
approve.configure({
test: {
message: 'New error message'
},
});
Parameters:
Name | Type | Description |
---|---|---|
obj |
obj | The configuration to update. |
Returns:
void
(static) noconflict()
- Source:
Returns the root approve variable back to the previous object
Example
var approveObj = approve.noconflict();
opproveObj.value(...);
Returns:
this
(static) value(value, rules, title) → {object}
- Source:
Executes the tests based on given rules to validate a given value.
Example
approve.value('some value', {test: constraints});
Parameters:
Name | Type | Description |
---|---|---|
value |
string | integer | The value to test against the rules. |
rules |
object | The constraints for the value being tested. |
title |
string | The title to replace the {title} placeholder with. |
Returns:
The object containing the result of the tests performed.
- Type
- object