Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added parameters to errors #18

Merged
merged 5 commits into from
Mar 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fieldval",
"version": "0.4.0",
"version": "0.4.1",
"main": "fieldval.js",
"ignore": [
"coverage",
Expand Down
76 changes: 38 additions & 38 deletions docs/fieldval.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs_src/BasicVal/BasicVal.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
BasicVal is a set of standard FieldVal [check functions](/docs/fieldval/Check%20Functions). Checks accept [flags](/docs/fieldval/Flags) as arguments and return typical FieldVal [errors](/docs/fieldval/Errors).
BasicVal is a set of standard FieldVal [check functions](/docs/fieldval/Check%20Functions). Checks accept [options](/docs/fieldval/Options) as arguments and return typical FieldVal [errors](/docs/fieldval/Errors).

BasicVal can be found at ```FieldVal.BasicVal```.
4 changes: 2 additions & 2 deletions docs_src/BasicVal/OtherChecks/date/date.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
```BasicVal.date(format, [flags])```
```BasicVal.date(format, [options])```

Checks if the string value is a valid date in a specified format.

Expand All @@ -22,7 +22,7 @@ Valid separators:
- ```/```
- ```:```

Optional flags.emit options
Optional options.emit options
```DateVal.EMIT_COMPONENT_ARRAY``` emits an array with date component values in the right order
```DateVal.EMIT_OBJECT``` emits an object in a following format:
```
Expand Down
2 changes: 1 addition & 1 deletion docs_src/BasicVal/OtherChecks/date_format/date_format.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.date_format([flags])```
```BasicVal.date_format([options])```

Checks whether a specified string value is a valid date format.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.does_not_contain(characters, [flags])```
```BasicVal.does_not_contain(characters, [options])```

Checks if strings does not contain any of the provided characters. ```characters``` can be either one character or a list of characters.
2 changes: 1 addition & 1 deletion docs_src/BasicVal/OtherChecks/each/each.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
```BasicVal.each(on_each, [flags])```
```BasicVal.each(on_each, [options])```

Iterates through the provided array and calls the ```on_each``` function on each array's value.

Expand Down
2 changes: 1 addition & 1 deletion docs_src/BasicVal/OtherChecks/each_async/each_async.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
```BasicVal.each_async(on_each, [flags])```
```BasicVal.each_async(on_each, [options])```

Iterates through the provided array and calls the ```on_each``` function on each array's value. The ```on_each``` function for ```each_async``` uses a callback to provide its response.

Expand Down
2 changes: 1 addition & 1 deletion docs_src/BasicVal/OtherChecks/equal_to/equal_to.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.equal_to(desired_value, [flags])```
```BasicVal.equal_to(desired_value, [options])```

Checks if the value that is being validated is equal to the desired value.
2 changes: 1 addition & 1 deletion docs_src/BasicVal/OtherChecks/length/length.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.length(desired_length, [flags])```
```BasicVal.length(desired_length, [options])```

Checks if the value has desired length.
2 changes: 1 addition & 1 deletion docs_src/BasicVal/OtherChecks/max_length/max_length.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.max_length(max_length, [flags])```
```BasicVal.max_length(max_length, [options])```

Checks if length of the value is less or equal to min_length.
2 changes: 1 addition & 1 deletion docs_src/BasicVal/OtherChecks/maximum/maximum.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.maximum(max_val, [flags])```
```BasicVal.maximum(max_val, [options])```

Checks if the value is less or equal to max_val.
2 changes: 1 addition & 1 deletion docs_src/BasicVal/OtherChecks/min_length/min_length.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.min_length(min_length, [flags])```
```BasicVal.min_length(min_length, [options])```

Checks if length of the value is greater or equal to min_length.
2 changes: 1 addition & 1 deletion docs_src/BasicVal/OtherChecks/minimum/minimum.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.minimum(min_val, [flags])```
```BasicVal.minimum(min_val, [options])```

Checks if the value is greater or equal to min_val.
2 changes: 1 addition & 1 deletion docs_src/BasicVal/OtherChecks/multiple/multiple.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
```BasicVal.multiple(possibles, [flags])```
```BasicVal.multiple(possibles, [options])```

Validates the value with multiple checks. Only one of the checks need to pass for the value to be valid.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
```BasicVal.multiple_async(possibles, [flags])```
```BasicVal.multiple_async(possibles, [options])```

Validates the value with multiple checks, allowing one or more of the checks to be asynchronous. Only one of the checks need to pass for the value to be valid.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.no_whitespace([flags])```
```BasicVal.no_whitespace([options])```

Checks that there is no whitespace in the value.
2 changes: 1 addition & 1 deletion docs_src/BasicVal/OtherChecks/not_empty/not_empty.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.not_empty(trim, [flags])```
```BasicVal.not_empty(trim, [options])```

Checks if the string value is not empty. ```trim``` is a boolean specifying whether the string needs to be trimmed before the check.
2 changes: 1 addition & 1 deletion docs_src/BasicVal/OtherChecks/not_one_of/not_one_of.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.not_one_of(undesired_values, [flags])```
```BasicVal.not_one_of(undesired_values, [options])```

Checks if the value is not equal to one of the undesired_values. ```undesired_values``` is an array.
2 changes: 1 addition & 1 deletion docs_src/BasicVal/OtherChecks/one_of/one_of.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.one_of(desired_values, [flags])```
```BasicVal.one_of(desired_values, [options])```

Checks if the value is equal to one of the desired_values. ```desired_values``` is an array.
2 changes: 1 addition & 1 deletion docs_src/BasicVal/OtherChecks/prefix/prefix.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.each(on_each, [flags])```
```BasicVal.each(on_each, [options])```

Checks if the string value starts with the ```desired_prefix```.
2 changes: 1 addition & 1 deletion docs_src/BasicVal/OtherChecks/range/range.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.range(min_val, max_val, [flags])```
```BasicVal.range(min_val, max_val, [options])```

Combines [minimum](/docs/fieldval/BasicVal/minimum) and [maximum](/docs/fieldval/BasicVal/maximum).
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.start_with_letter([flags])```
```BasicVal.start_with_letter([options])```

Checks if the string value starts with a letter.
2 changes: 1 addition & 1 deletion docs_src/BasicVal/OtherChecks/suffix/suffix.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.suffix(desired_suffix, [flags])```
```BasicVal.suffix(desired_suffix, [options])```

Checks if the string value ends with the ```desired_suffix```.
2 changes: 1 addition & 1 deletion docs_src/BasicVal/TypeChecks/TypeChecks.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ BasicVal's built-in type checks should be used to check that a value is of a par

The first parameter is usually a boolean indicating whether the field is required or not. The default is ```true```.

Whether or not the field is required can also be specified in the flags parameter, which is an object. Such a flags object would look like:
Whether or not the field is required can also be specified in the ```options``` parameter, which is an object. Such an ```options``` object would look like:

```{required: true}```.

Expand Down
2 changes: 1 addition & 1 deletion docs_src/BasicVal/TypeChecks/array/array.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.array([required], [flags])```
```BasicVal.array([required], [options])```

Checks if the value is an array.
4 changes: 2 additions & 2 deletions docs_src/BasicVal/TypeChecks/boolean/boolean.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
```BasicVal.boolean([required], [flags])```
```BasicVal.boolean([required], [options])```

Checks if the value is a boolean.

Set ```{parse: true}``` in the flags object to attempt to parse the value.
Set ```{parse: true}``` in the ```options``` object to attempt to parse the value.

If the value is either "true" or "false" as a string, it will be parsed to the corresponding boolean.
2 changes: 1 addition & 1 deletion docs_src/BasicVal/TypeChecks/email/email.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.email([required], [flags])```
```BasicVal.email([required], [options])```

Checks if the value is first a string, and then an email.
4 changes: 2 additions & 2 deletions docs_src/BasicVal/TypeChecks/integer/integer.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```BasicVal.integer([required], [flags])```
```BasicVal.integer([required], [options])```

Checks if the value is an integer.

Set ```{parse: true}``` in the flags object to attempt to parse the value.
Set ```{parse: true}``` in the ```options``` object to attempt to parse the value.
4 changes: 2 additions & 2 deletions docs_src/BasicVal/TypeChecks/number/number.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```BasicVal.number([required], [flags])```
```BasicVal.number([required], [options])```

Checks if the value is a number, including floats.

Set ```{parse: true}``` in the flags object to attempt to parse the value.
Set ```{parse: true}``` in the ```options``` object to attempt to parse the value.
2 changes: 1 addition & 1 deletion docs_src/BasicVal/TypeChecks/object/object.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.object([required], [flags])```
```BasicVal.object([required], [options])```

Checks if the value is an object.
2 changes: 1 addition & 1 deletion docs_src/BasicVal/TypeChecks/string/string.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.string([required], [flags])```
```BasicVal.string([required], [options])```

Checks if the value is a string.
2 changes: 1 addition & 1 deletion docs_src/BasicVal/TypeChecks/url/url.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```BasicVal.url([required],[flags])```
```BasicVal.url([required],[options])```

Checks if the value is first a string, and then a url.
10 changes: 5 additions & 5 deletions docs_src/Checks/Parameters/Parameters.code
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var minimum = function(min_val, flags) {
var minimum = function(min_val, options) {

var check = function(value) {
if (value < min_val) {
Expand All @@ -9,10 +9,10 @@ var minimum = function(min_val, flags) {
}
}

if(flags){
//The check becomes part of the flag object, which is returned
flags.check = check;
return flags
if(options){
//The check becomes part of the options object, which is returned
options.check = check;
return options
}

return check;
Expand Down
2 changes: 1 addition & 1 deletion docs_src/Checks/Parameters/Parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ The example provided is a function that performs the same action as BasicVal.min

```check``` is now a function that will return an error if the value is less than ```14```. This is because minimum is a wrapper that creates a function with access to the configuration parameters (```14``` as ```min_val``` in this case).

[Flags](/docs/fieldval/Flags) are additional parameters. If ```flags``` is set then the check becomes a property of the ```flags``` object. The FieldVal library can use both an object that contains a ```check``` property and also a function directly.
[Options](/docs/fieldval/Options) are additional parameters. If ```options``` is set then the check becomes a property of the ```options``` object. The FieldVal library can use both an object that contains a ```check``` property and also a function directly.
2 changes: 1 addition & 1 deletion docs_src/Examples/SingleValue/SingleValue.code
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ BasicVal.integer().check(value);

//OUTPUT
{
error_message: 'Incorrect field type. Expected integer.',
error_message: 'Incorrect field type. Expected integer, but received string.',
error: 2,
expected: 'integer',
received: 'string'
Expand Down
14 changes: 7 additions & 7 deletions docs_src/FieldVal.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,25 +291,25 @@
]
},
{
"name": "Flags",
"text": "Flags/flags.md",
"code": "Flags/flags.code",
"name": "Options",
"text": "Options/options.md",
"code": "Options/options.code",
"sections": [
{
"name": "stop_on_error",
"text": "Flags/stop_on_error/stop_on_error.md",
"text": "Options/stop_on_error/stop_on_error.md",
"code": {
"path": "Flags/stop_on_error/stop_on_error.code",
"path": "Options/stop_on_error/stop_on_error.code",
"type": "js",
"runnable": true,
"js_external": "__CURRENT_DOMAIN__/demo_files/fieldval.js"
}
},
{
"name": "error",
"text": "Flags/error/error.md",
"text": "Options/error/error.md",
"code": {
"path": "Flags/error/error.code",
"path": "Options/error/error.code",
"type": "js",
"runnable": true,
"js_external": "__CURRENT_DOMAIN__/demo_files/fieldval.js"
Expand Down
2 changes: 1 addition & 1 deletion docs_src/FieldVal_in_out.code
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var data = {
"error_message": "Invalid email address format."
},
"my_integer": {
"error_message": "Incorrect field type. Expected integer.",
"error_message": "Incorrect field type. Expected number, but received string.",
"error": 2,
"expected": "integer",
"received": "string"
Expand Down
1 change: 0 additions & 1 deletion docs_src/Flags/Flags.md

This file was deleted.

1 change: 0 additions & 1 deletion docs_src/Flags/error/error.md

This file was deleted.

File renamed without changes.
1 change: 1 addition & 0 deletions docs_src/Options/Options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Options are used to both pass values to a check and also to indicate to a FieldVal validator how to use the check.
File renamed without changes.
1 change: 1 addition & 0 deletions docs_src/Options/error/error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The ```error``` option overrides the standard error for [BasicVal](/docs/fieldval/BasicVal) checks.