Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Indent the code blocks with " " so that github knows they're code.

  • Loading branch information...
commit 24478cde89797470031b23a273aa6f9f4a85d624 1 parent 7372b45
@isaacs authored
Showing with 18 additions and 18 deletions.
  1. +18 −18 README.md
View
36 README.md
@@ -9,21 +9,21 @@
### Declarative
- var inRange = Valid.min(4).max(9)
- inRange(12) // throws an error
- var stringInRange = inRange.typeof('string').errorHandler(Valid.TrueFalse)
- if(stringInRange.validate("not in range")) { /\* not executed \*/ }
+ var inRange = Valid.min(4).max(9)
+ inRange(12) // throws an error
+ var stringInRange = inRange.typeof('string').errorHandler(Valid.TrueFalse)
+ if(stringInRange.validate("not in range")) { /\* not executed \*/ }
### Immediate
- var check = Valid.checker(TrueFalse); // uses Throw by default
- if(check(12).inRange(4,9)) { /\* not executed \*/ }
+ var check = Valid.checker(TrueFalse); // uses Throw by default
+ if(check(12).inRange(4,9)) { /\* not executed \*/ }
what about going insane?
- Object.prototype.assert = Valid.checker().errorHandler(Valid.Throw);
- 12.assert().min(4).max(9); // throws an error
+ Object.prototype.assert = Valid.checker().errorHandler(Valid.Throw);
+ 12.assert().min(4).max(9); // throws an error
# Handling Validation Errors
@@ -31,7 +31,7 @@ what about going insane?
By default the validator raises an error when it finds invalid data
(using the Valid.Throw handler). To make it return a boolean result:
- Valid.errorHandler(Valid.TrueFalse).validate(false);
+ Valid.errorHandler(Valid.TrueFalse).validate(false);
### Throw
@@ -41,11 +41,11 @@ By default the validator raises an error when it finds invalid data
### ErrorObject (included with json-valid)
- errors: an error object
- .add([field], msg) -- adds a message for the field. A field of "." refers to the entire object.
- .clear() -- clears all error messages
- .count([field]) -- tells how many total errors or just for the given field
- .messages([field]) -- returns an array of all error messages concated with field name
+ errors: an error object
+ .add([field], msg) -- adds a message for the field. A field of "." refers to the entire object.
+ .clear() -- clears all error messages
+ .count([field]) -- tells how many total errors or just for the given field
+ .messages([field]) -- returns an array of all error messages concated with field name
# Built-In Validations
@@ -91,8 +91,8 @@ We don't offer inverses because not() is usually clearer. If you'd
rather write Valid.notIn(arr) instead of Valid.not(Valid.in(arr)),
just do this:
-Valid.notIn = function(arr) { return Valid.not(Valid.in(arr)) }
-Valid.notIn = Valid.not(Valid.in) // could this work?
+ Valid.notIn = function(arr) { return Valid.not(Valid.in(arr)) }
+ Valid.notIn = Valid.not(Valid.in) // could this work?
# Extending Valid
@@ -103,8 +103,8 @@ Valid.notIn = Valid.not(Valid.in) // could this work?
## Error Handlers
- // this.field tells what field we're operating on
- Valid.errorHandler(function(message) {
+ // this.field tells what field we're operating on
+ Valid.errorHandler(function(message) {
# Alternatives
Please sign in to comment.
Something went wrong with that request. Please try again.