Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Small modifications in README.

  • Loading branch information...
commit 851f35916077f05705177bac55f353b2e3db5bc7 1 parent 8b811b8
@molnarg authored
Showing with 5 additions and 1 deletion.
  1. +5 −1 README.md
View
6 README.md
@@ -21,16 +21,19 @@ var Duck = schema({ // A duck
});
```
-The resulting function (`Duck`) can be used for checking or validating objects:
+The resulting function (`Duck`) can be used to check objects against the declared schema:
```javascript
+// Some animals
var myDuck = { swim : function() {}, quack : function() {}, age : 2, color : 'yellow' },
myCat = { walk : function() {}, purr : function() {}, age : 3, color : 'black' },
animals = [ myDuck, myCat, {}, /*...*/ ];
+// Simple checks
console.log( Duck(myDuck) ); // true
console.log( Duck(myCat) ); // false
+// Using the schema function with filter
var ducks = animals.filter( Duck ); // every Duck-like animal
var walking = animals.filter( schema({ walk : Function }) ); // every animal that can walk
```
@@ -39,6 +42,7 @@ It is also possible to define self-referencing data structures:
```javascript
var Tree = schema({ left : [ Number, Tree ], right : [ Number, Tree ] });
+
console.log( Tree({ left : 3, right : 3 }) ); // true
console.log( Tree({ left : 3, right : { left: 5, right: 5 } }) ); // true
console.log( Tree({ left : 3, right : { left: 5, right: 's' } }) ); // false
Please sign in to comment.
Something went wrong with that request. Please try again.