{"_id":"checker","_rev":"23-39ff9491581c529b8b828651a196c7a3","name":"checker","description":"Checker is the collection of common abstract methods for validatiors and setters.","dist-tags":{"latest":"0.5.2"},"versions":{"0.0.0":{"name":"checker","version":"0.0.0","description":"","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"author":"","license":"MIT","readme":"ERROR: No README data found!","_id":"checker@0.0.0","dist":{"shasum":"6a7a3977bbe770560d4fcc86eb3a32a52c9b368d","tarball":"http://registry.npmjs.org/checker/-/checker-0.0.0.tgz"},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"kael","email":"i@kael.me"},"maintainers":[{"name":"kael","email":"i@kael.me"}],"directories":{}},"0.2.1":{"name":"checker","version":"0.2.1","description":"Checker is the collection of common abstract methods for validatiors and setters.","main":"index.js","scripts":{"test":"make test"},"repository":{"type":"git","url":"git://github.com/kaelzhang/node-checker.git"},"keywords":["checker","validator","validate","setter"],"author":{"name":"kael"},"license":"MIT","bugs":{"url":"https://github.com/kaelzhang/node-checker/issues"},"devDependencies":{"mocha":"~1.13.0","chai":"~1.8.0"},"dependencies":{"async":"~0.2.9"},"readme":"[![Build Status](https://travis-ci.org/kaelzhang/node-checker.png?branch=master)](https://travis-ci.org/kaelzhang/node-checker)\u000a\u000a(THIS DOCUMENTAION IS NOT FINISHED YET.)\u000a\u000a# checker\u000a\u000aChecker is the collection of common abstract node.js methods for validatiors and setters.\u000a\u0009\u000a# Usage\u000a```sh\u000anpm install checker --save\u000a```\u000a\u000a```js\u000avar checker = require('checker');\u000a```\u000a\u000a# Synopsis\u000a\u000a```js\u000achecker(schema, options).check(data, callback);\u000a```\u000a\u000a# Validation, Error Messages\u000a\u000a## Simple synchronous validators\u000a\u000a```js\u000avar schema = {\u000a\u0009username: {\u000a\u0009\u0009validator: function(value){\u000a\u0009\u0009\u0009return /^[a-zA-Z0-9]{6,}$/.test(value);\u000a\u0009\u0009},\u000a\u0009\u0009message: 'Username must only contain letters, numbers; Username must contain at least 6 charactors'\u000a\u0009}\u000a};\u000a\u000avar c = checker(schema);\u000a\u000ac.check({\u000a\u0009username: 'a'\u000a}, function(err){\u000a\u0009if(err){\u000a\u0009\u0009console.log(err); // Then, `schema.username.message` will be displayed.\u000a\u0009}\u000a});\u000a```\u000a\u000a## Regular expressions as validators\u000a\u000aThe error hint of the example above is bad, because we want to know the very certain reason why we are wrong.\u000a\u000aThe `schema` below is equivalent to the one of the previous section:\u000a\u000a```js\u000a{\u000a\u0009validator: [\u000a\u0009\u0009function(value){\u000a\u0009\u0009\u0009return value && value.length > 5;\u000a\u0009\u0009}, \u000a\u0009\u0009/^[a-zA-Z0-9]+$/\u000a\u0009],\u000a\u0009message: [\u000a\u0009\u0009'Username must contain at least 6 charactors', \u000a\u0009\u0009'Username must only contain letters and numbers'\u000a\u0009];\u000a}\u000a```\u000a\u000a## Asynchronous validators\u000a\u000a```js\u000a{\u000a\u0009validator: function(value){\u000a\u0009\u0009var done = this.async();\u000a\u0009\u0009// this is an async method, and takes sooooo long...\u000a\u0009\u0009remote_check(value, function(err){\u000a\u0009\u0009\u0009done(err); // `err` will pass to the `callback`\u000a\u0009\u0009});\u000a\u0009}\u000a}\u000a```\u000a\u000a\u000a# Programmatical Details\u000a\u000a## Options\u000a\u000a#### options.default_message `String`\u000a\u000aDefault error message\u000a\u000a#### options.parallel `Boolean=false`\u000a\u000a#### options.limit `Boolean=false`\u000a\u000a#### options.check_all `Boolean=false`\u000a\u000a\u000a\u000a## Schema Structures \u000a\u000a```js\u000a{\u000a\u0009<name>: <rule>\u000a}\u000a```\u000a\u000a\u000aWhere `rule` might contains (all properties are optional):\u000a\u000a#### validator \u000a\u000a- `RegExp` The regular exp that input must matches against\u000a- `Function` Validation function. If `arguments.length === 3`, it will be considered as an async methods\u000a- `Array.<RegExp|Function>` Group of validations. Asks will check each validator one by one. If validation fails, the rest validators will be skipped.\u000a- See sections above for details\u000a\u0009\u000a#### setter `Function|Array.<Function>`\u000a\u000aSee sections above for details.\u000a\u000a#### message `String`\u000a\u000aDefault error message\u000a\u000a#### default: `String`\u000a","_id":"checker@0.2.1","dist":{"shasum":"f25a07a1429cd9cee4a668f19fa99fa7e380deda","tarball":"http://registry.npmjs.org/checker/-/checker-0.2.1.tgz"},"maintainers":[{"name":"kael","email":"i@kael.me"}],"directories":{}},"0.3.1":{"name":"checker","version":"0.3.1","description":"Checker is the collection of common abstract methods for validatiors and setters.","main":"index.js","scripts":{"test":"make test"},"repository":{"type":"git","url":"git://github.com/kaelzhang/node-checker.git"},"keywords":["checker","validator","validate","setter"],"author":{"name":"kael"},"license":"MIT","bugs":{"url":"https://github.com/kaelzhang/node-checker/issues"},"devDependencies":{"mocha":"~1.13.0","chai":"~1.8.0"},"dependencies":{"async":"~0.2.9"},"readme":"[![Build Status](https://travis-ci.org/kaelzhang/node-checker.png?branch=master)](https://travis-ci.org/kaelzhang/node-checker)\u000a\u000a(THIS DOCUMENTAION IS NOT FINISHED YET.)\u000a\u000a# checker\u000a\u000aChecker is the collection of common abstract node.js methods for validatiors and setters.\u000a\u0009\u000a# Usage\u000a```sh\u000anpm install checker --save\u000a```\u000a\u000a```js\u000avar checker = require('checker');\u000a```\u000a\u000a# Synopsis\u000a\u000a```js\u000achecker(schema, options).check(data, callback);\u000a```\u000a\u000a# Validation, Error Messages\u000a\u000a## Simple synchronous validators\u000a\u000a```js\u000avar schema = {\u000a\u0009username: {\u000a\u0009\u0009validator: function(value){\u000a\u0009\u0009\u0009return /^[a-zA-Z0-9]{6,}$/.test(value);\u000a\u0009\u0009},\u000a\u0009\u0009message: 'Username must only contain letters, numbers; Username must contain at least 6 charactors'\u000a\u0009}\u000a};\u000a\u000avar c = checker(schema);\u000a\u000ac.check({\u000a\u0009username: 'a'\u000a}, function(err){\u000a\u0009if(err){\u000a\u0009\u0009console.log(err); // Then, `schema.username.message` will be displayed.\u000a\u0009}\u000a});\u000a```\u000a\u000a## Regular expressions as validators\u000a\u000aThe error hint of the example above is bad, because we want to know the very certain reason why we are wrong.\u000a\u000aThe `schema` below is equivalent to the one of the previous section:\u000a\u000a```js\u000a{\u000a\u0009validator: [\u000a\u0009\u0009function(value){\u000a\u0009\u0009\u0009return value && value.length > 5;\u000a\u0009\u0009}, \u000a\u0009\u0009/^[a-zA-Z0-9]+$/\u000a\u0009],\u000a\u0009message: [\u000a\u0009\u0009'Username must contain at least 6 charactors', \u000a\u0009\u0009'Username must only contain letters and numbers'\u000a\u0009];\u000a}\u000a```\u000a\u000a## Asynchronous validators\u000a\u000a```js\u000a{\u000a\u0009validator: function(value){\u000a\u0009\u0009var done = this.async();\u000a\u0009\u0009// this is an async method, and takes sooooo long...\u000a\u0009\u0009remote_check(value, function(err){\u000a\u0009\u0009\u0009done(err); // `err` will pass to the `callback`\u000a\u0009\u0009});\u000a\u0009}\u000a}\u000a```\u000a\u000a\u000a# Programmatical Details\u000a\u000a## Options\u000a\u000a#### options.default_message `String`\u000a\u000aDefault error message\u000a\u000a#### options.parallel `Boolean=false`\u000a\u000a#### options.limit `Boolean=false`\u000a\u000a#### options.check_all `Boolean=false`\u000a\u000a\u000a\u000a## Schema Structures \u000a\u000a```js\u000a{\u000a\u0009<name>: <rule>\u000a}\u000a```\u000a\u000a\u000aWhere `rule` might contains (all properties are optional):\u000a\u000a#### validator \u000a\u000a- `RegExp` The regular exp that input must matches against\u000a- `Function` Validation function. If `arguments.length === 3`, it will be considered as an async methods\u000a- `Array.<RegExp|Function>` Group of validations. Asks will check each validator one by one. If validation fails, the rest validators will be skipped.\u000a- See sections above for details\u000a\u0009\u000a#### setter `Function|Array.<Function>`\u000a\u000aSee sections above for details.\u000a\u000a#### message `String`\u000a\u000aDefault error message\u000a\u000a#### default: `String`\u000a","_id":"checker@0.3.1","dist":{"shasum":"c285c3f3c29c4186156d9e94945ad3892e64c739","tarball":"http://registry.npmjs.org/checker/-/checker-0.3.1.tgz"},"maintainers":[{"name":"kael","email":"i@kael.me"}],"directories":{}},"0.3.2":{"name":"checker","version":"0.3.2","description":"Checker is the collection of common abstract methods for validatiors and setters.","main":"index.js","scripts":{"test":"make test"},"repository":{"type":"git","url":"git://github.com/kaelzhang/node-checker.git"},"keywords":["checker","validator","validate","setter"],"author":{"name":"kael"},"license":"MIT","bugs":{"url":"https://github.com/kaelzhang/node-checker/issues"},"devDependencies":{"mocha":"~1.13.0","chai":"~1.8.0"},"dependencies":{"async":"~0.2.9"},"readme":"[![Build Status](https://travis-ci.org/kaelzhang/node-checker.png?branch=master)](https://travis-ci.org/kaelzhang/node-checker)\u000a\u000a# checker\u000a\u000aChecker is the collection of common abstract node.js methods for validatiors and setters.\u000a\u0009\u000a# Usage\u000a```sh\u000anpm install checker --save\u000a```\u000a\u000a```js\u000avar checker = require('checker');\u000a```\u000a\u000a# Synopsis\u000a\u000a```js\u000achecker(schema, options).check(data, function(err, value, details){\u000a});\u000a```\u000a\u000a### err `mixed`\u000a\u000a### parsed `Object`\u000a\u000aThe cleaned and parsed `data`.\u000a\u000a### details `Object`\u000a\u000a```\u000a{\u000a\u0009<name>: <detail>\u000a}\u000a```\u000a\u000a- `detail.value` `mixed` the parsed value\u000a- `detail.is_default` `Boolean` if the current property is defined in `schema`, but the input data doesn't have it, then the value will be `true`\u000a- `detail.is_cooked` `Boolean` if there're any setters, it will be `true`\u000a- `detail.origin` the origin value of the property\u000a\u000a\u000a# Validation, Error Messages\u000a\u000a## Simple synchronous validators\u000a\u000a```js\u000avar schema = {\u000a\u0009username: {\u000a\u0009\u0009validator: function(value){\u000a\u0009\u0009\u0009return /^[a-zA-Z0-9]{6,}$/.test(value);\u000a\u0009\u0009},\u000a\u0009\u0009message: 'Username must only contain letters, numbers; ' \u000a\u0009\u0009\u0009+ 'Username must contain at least 6 charactors'\u000a\u0009}\u000a};\u000a\u000avar c = checker(schema);\u000a\u000ac.check({\u000a\u0009username: 'a'\u000a}, function(err){\u000a\u0009if(err){\u000a\u0009\u0009console.log(err); // Then, `schema.username.message` will be displayed.\u000a\u0009}\u000a});\u000a```\u000a\u000a## Regular expressions as validators\u000a\u000aThe error hint of the example above is bad, because we want to know the very certain reason why we are wrong.\u000a\u000aThe `schema` below is equivalent to the one of the previous section:\u000a\u000a```js\u000a{\u000a\u0009validator: [\u000a\u0009\u0009function(value){\u000a\u0009\u0009\u0009return value && value.length > 5;\u000a\u0009\u0009}, \u000a\u0009\u0009/^[a-zA-Z0-9]+$/\u000a\u0009],\u000a\u0009message: [\u000a\u0009\u0009'Username must contain at least 6 charactors', \u000a\u0009\u0009'Username must only contain letters and numbers'\u000a\u0009];\u000a}\u000a```\u000a\u000a## Asynchronous validators\u000a\u000a```js\u000a{\u000a\u0009validator: function(value){\u000a\u0009\u0009var done = this.async();\u000a\u0009\u0009// this is an async method, and takes sooooo long...\u000a\u0009\u0009remote_check(value, function(err){\u000a\u0009\u0009\u0009done(err); // `err` will pass to the `callback`\u000a\u0009\u0009});\u000a\u0009}\u000a}\u000a```\u000a\u000a\u000a# Programmatical Details\u000a\u000a## Options\u000a\u000a#### options.default_message `String`\u000a\u000aDefault error message\u000a\u000a#### options.parallel `Boolean=false`\u000a\u000aBy default, `checker` will check each properties in series, \u000a\u000a#### options.limit `Boolean=false`\u000a\u000aIf `options.limit` is `true` and a certain property of the input data is not defined in the `schema`, the property will be removed.\u000a\u000aDefault to `false`.\u000a\u000a#### options.check_all `Boolean=false`\u000a\u000aNot implemented yet.\u000a\u000a#### options.context `Object`\u000a\u000aSee sections below.\u000a\u000a## Schema Structures \u000a\u000a```js\u000a{\u000a\u0009<name>: <rule>\u000a}\u000a```\u000a\u000a\u000aWhere `rule` might contains (all properties are optional):\u000a\u000a#### validator \u000a\u000a- `RegExp` The regular exp that input must matches against\u000a- `Function` Validation function. If `arguments.length === 3`, it will be considered as an async methods\u000a- `Array.<RegExp|Function>` Group of validations. Asks will check each validator one by one. If validation fails, the rest validators will be skipped.\u000a- See sections above for details\u000a\u0009\u000a#### setter `Function|Array.<Function>`\u000a\u000aSee sections above for details.\u000a\u000a#### message `String`\u000a\u000aDefault error message\u000a\u000a#### default: `String`\u000a\u000a\u000a## `this` object inside validators and setters\u000a\u000aInside validators(`rule.validator`) and setters(`rule.setter`), there're several opaque methods\u000a\u000a### this.async()\u000a\u000aGenerate the `done` function to make the validator or setter become an async method.\u000a\u000a\u0009var done = this.async();\u000a\u0009\u000aFor details, see the demos above.\u000a\u000a### this.get(name)\u000a\u000aThe value of the input object by name\u000a\u000a### this.set(name, value)\u000a\u000aChange the value of the specified property of the input object.\u000a\u000a```\u000a{\u000a\u0009username: {\u000a\u0009},\u000a\u0009\u000a\u0009password: {\u000a\u0009\u0009validator: function(value){\u000a\u0009\u0009\u0009var username = this.get('username');\u000a\u0009\u0009\u0009\u000a\u0009\u0009\u0009// Guests are welcome even without passwords\u000a\u0009\u0009\u0009return value || username === 'guest';\u000a\u0009\u0009}\u000a\u0009}\u000a}\u000a```\u000a\u000aNotice that you'd better use `this.get` and `this.set` with the `options.parallel` setting as `false`(the default value). Otherwise, it might encounter unexpected situations, because the value of the object is ever changing due to the setter.\u000a\u000aSo, use them wisely.\u000a\u000a### this.context `Object`\u000a\u000aThe `options.context` itself.\u000a\u000a\u000a\u000a","_id":"checker@0.3.2","dist":{"shasum":"bc4b84036a5699c609e3c627923cb87d8058a79d","tarball":"http://registry.npmjs.org/checker/-/checker-0.3.2.tgz"},"maintainers":[{"name":"kael","email":"i@kael.me"}],"directories":{}},"0.4.2":{"name":"checker","version":"0.4.2","description":"Checker is the collection of common abstract methods for validatiors and setters.","main":"index.js","scripts":{"test":"make test"},"repository":{"type":"git","url":"git://github.com/kaelzhang/node-checker.git"},"keywords":["checker","validator","validate","setter"],"author":{"name":"kael"},"license":"MIT","bugs":{"url":"https://github.com/kaelzhang/node-checker/issues"},"devDependencies":{"mocha":"~1.13.0","chai":"~1.8.0"},"dependencies":{"async":"~0.2.9"},"readme":"[![Build Status](https://travis-ci.org/kaelzhang/node-checker.png?branch=master)](https://travis-ci.org/kaelzhang/node-checker)\u000a\u000a# checker\u000a\u000aChecker is the collection of common abstract node.js methods for validatiors and setters.\u000a\u0009\u000a# Usage\u000a```sh\u000anpm install checker --save\u000a```\u000a\u000a```js\u000avar checker = require('checker');\u000a```\u000a\u000a# Synopsis\u000a\u000a```js\u000achecker(schema, options).check(data, function(err, value, details){\u000a});\u000a```\u000a\u000a### err `mixed`\u000a\u000a### results `Object`\u000a\u000aThe parsed object.\u000a\u000a### details `Object`\u000a\u000a```\u000a{\u000a\u0009<name>: <detail>\u000a}\u000a```\u000a\u000a- `detail.value` `mixed` the parsed value\u000a- `detail.is_default` `Boolean` if the current property is defined in `schema`, but the input data doesn't have it, then the value will be `true`\u000a- `detail.is_cooked` `Boolean` if there're any setters, it will be `true`\u000a- `detail.origin` the origin value of the property\u000a- `detail.error` the error belongs to the current property. If not exists, it will be `null`\u000a\u000a\u000a# Validation, Error Messages\u000a\u000a## Simple synchronous validators\u000a\u000a```js\u000avar schema = {\u000a\u0009username: {\u000a\u0009\u0009validator: function(value){\u000a\u0009\u0009\u0009return /^[a-zA-Z0-9]{6,}$/.test(value);\u000a\u0009\u0009},\u000a\u0009\u0009message: 'Username must only contain letters, numbers; ' \u000a\u0009\u0009\u0009+ 'Username must contain at least 6 charactors'\u000a\u0009}\u000a};\u000a\u000avar c = checker(schema);\u000a\u000ac.check({\u000a\u0009username: 'a'\u000a}, function(err){\u000a\u0009if(err){\u000a\u0009\u0009console.log(err); // Then, `schema.username.message` will be displayed.\u000a\u0009}\u000a});\u000a```\u000a\u000a## Regular expressions as validators\u000a\u000aThe error hint of the example above is bad, because we want to know the very certain reason why we are wrong.\u000a\u000aThe `schema` below is equivalent to the one of the previous section:\u000a\u000a```js\u000a{\u000a\u0009validator: [\u000a\u0009\u0009function(value){\u000a\u0009\u0009\u0009return value && value.length > 5;\u000a\u0009\u0009}, \u000a\u0009\u0009/^[a-zA-Z0-9]+$/\u000a\u0009],\u000a\u0009message: [\u000a\u0009\u0009'Username must contain at least 6 charactors', \u000a\u0009\u0009'Username must only contain letters and numbers'\u000a\u0009];\u000a}\u000a```\u000a\u000a## Asynchronous validators\u000a\u000a```js\u000a{\u000a\u0009validator: function(value){\u000a\u0009\u0009var done = this.async();\u000a\u0009\u0009// this is an async method, and takes sooooo long...\u000a\u0009\u0009remote_check(value, function(err){\u000a\u0009\u0009\u0009done(err); // `err` will pass to the `callback`\u000a\u0009\u0009});\u000a\u0009}\u000a}\u000a```\u000a\u000a\u000a# Programmatical Details\u000a\u000a## Options\u000a\u000a#### options.default_message `String`\u000a\u000aDefault error message\u000a\u000a#### options.parallel `Boolean=false`\u000a\u000aBy default, `checker` will check each properties in series, \u000a\u000a#### options.limit `Boolean=false`\u000a\u000aIf `options.limit` is `true` and a certain property of the input data is not defined in the `schema`, the property will be removed.\u000a\u000aDefault to `false`.\u000a\u000a#### options.check_all `Boolean=false`\u000a\u000aBy default, `checker` will exit immediately at the first error. But if `options.check_all` is `true`, it will parse all the properties, and collect every possible error.\u000a\u000a#### options.context `Object`\u000a\u000aSee sections below.\u000a\u000a## Schema Structures \u000a\u000a```js\u000a{\u000a\u0009<name>: <rule>\u000a}\u000a```\u000a\u000a\u000aWhere `rule` might contains (all properties are optional):\u000a\u000a#### validator \u000a\u000a- `RegExp` The regular exp that input must matches against\u000a- `Function` Validation function. If `arguments.length === 3`, it will be considered as an async methods\u000a- `Array.<RegExp|Function>` Group of validations. Asks will check each validator one by one. If validation fails, the rest validators will be skipped.\u000a- See sections above for details\u000a\u0009\u000a#### setter `Function|Array.<Function>`\u000a\u000aSee sections above for details.\u000a\u000a#### message `String`\u000a\u000aDefault error message\u000a\u000a#### default: `String`\u000a\u000a\u000a## `this` object inside validators and setters\u000a\u000aInside validators(`rule.validator`) and setters(`rule.setter`), there're several opaque methods\u000a\u000a### this.async()\u000a\u000aGenerate the `done` function to make the validator or setter become an async method.\u000a\u000a\u0009var done = this.async();\u000a\u0009\u000aFor details, see the demos above.\u000a\u000a### this.get(name)\u000a\u000aThe value of the input object by name\u000a\u000a### this.set(name, value)\u000a\u000aChange the value of the specified property of the input object.\u000a\u000a```\u000a{\u000a\u0009username: {\u000a\u0009},\u000a\u0009\u000a\u0009password: {\u000a\u0009\u0009validator: function(value){\u000a\u0009\u0009\u0009var username = this.get('username');\u000a\u0009\u0009\u0009\u000a\u0009\u0009\u0009// Guests are welcome even without passwords\u000a\u0009\u0009\u0009return value || username === 'guest';\u000a\u0009\u0009}\u000a\u0009}\u000a}\u000a```\u000a\u000aNotice that you'd better use `this.get` and `this.set` with the `options.parallel` setting as `false`(the default value). Otherwise, it might encounter unexpected situations, because the value of the object is ever changing due to the setter.\u000a\u000aSo, use them wisely.\u000a\u000a### this.context `Object`\u000a\u000aThe `options.context` itself.\u000a\u000a\u000a\u000a","_id":"checker@0.4.2","dist":{"shasum":"7b033fdad0f000f88302ff1f5a8e59d8f466580e","tarball":"http://registry.npmjs.org/checker/-/checker-0.4.2.tgz"},"maintainers":[{"name":"kael","email":"i@kael.me"}],"directories":{}},"0.5.1":{"name":"checker","version":"0.5.1","description":"Checker is the collection of common abstract methods for validatiors and setters.","main":"index.js","scripts":{"test":"make test"},"repository":{"type":"git","url":"git://github.com/kaelzhang/node-checker.git"},"keywords":["checker","validator","validate","setter"],"author":{"name":"kael"},"license":"MIT","bugs":{"url":"https://github.com/kaelzhang/node-checker/issues"},"devDependencies":{"mocha":"~1.13.0","chai":"~1.8.0"},"dependencies":{"async":"~0.2.9"},"readme":"[![Build Status](https://travis-ci.org/kaelzhang/node-checker.png?branch=master)](https://travis-ci.org/kaelzhang/node-checker)\u000a\u000a# checker\u000a\u000aChecker is the collection of common abstract node.js methods for validatiors and setters.\u000a\u0009\u000a# Usage\u000a```sh\u000anpm install checker --save\u000a```\u000a\u000a```js\u000avar checker = require('checker');\u000a```\u000a\u000a# Synopsis\u000a\u000a```js\u000achecker(schema, options).check(data, function(err, value, details){\u000a});\u000a```\u000a\u000a### err `mixed`\u000a\u000a### results `Object`\u000a\u000aThe parsed object.\u000a\u000a### details `Object`\u000a\u000a```\u000a{\u000a\u0009<name>: <detail>\u000a}\u000a```\u000a\u000a- `detail.value` `mixed` the parsed value\u000a- `detail.is_default` `Boolean` if the current property is defined in `schema`, but the input data doesn't have it, then the value will be `true`\u000a- `detail.is_cooked` `Boolean` if there're any setters, it will be `true`\u000a- `detail.origin` the origin value of the property\u000a- `detail.error` the error belongs to the current property. If not exists, it will be `null`\u000a\u000a\u000a# Validation, Error Messages\u000a\u000a## Simple synchronous validators\u000a\u000a```js\u000avar schema = {\u000a\u0009username: {\u000a\u0009\u0009validator: function(value){\u000a\u0009\u0009\u0009return /^[a-zA-Z0-9]{6,}$/.test(value);\u000a\u0009\u0009},\u000a\u0009\u0009message: 'Username must only contain letters, numbers; ' \u000a\u0009\u0009\u0009+ 'Username must contain at least 6 charactors'\u000a\u0009}\u000a};\u000a\u000avar c = checker(schema);\u000a\u000ac.check({\u000a\u0009username: 'a'\u000a}, function(err){\u000a\u0009if(err){\u000a\u0009\u0009console.log(err); // Then, `schema.username.message` will be displayed.\u000a\u0009}\u000a});\u000a```\u000a\u000a## Regular expressions as validators\u000a\u000aThe error hint of the example above is bad, because we want to know the very certain reason why we are wrong.\u000a\u000aThe `schema` below is equivalent to the one of the previous section:\u000a\u000a```js\u000a{\u000a\u0009validator: [\u000a\u0009\u0009function(value){\u000a\u0009\u0009\u0009return value && value.length > 5;\u000a\u0009\u0009}, \u000a\u0009\u0009/^[a-zA-Z0-9]+$/\u000a\u0009],\u000a\u0009message: [\u000a\u0009\u0009'Username must contain at least 6 charactors', \u000a\u0009\u0009'Username must only contain letters and numbers'\u000a\u0009];\u000a}\u000a```\u000a\u000a## Asynchronous validators\u000a\u000a```js\u000a{\u000a\u0009validator: function(value){\u000a\u0009\u0009var done = this.async();\u000a\u0009\u0009// this is an async method, and takes sooooo long...\u000a\u0009\u0009remote_check(value, function(err){\u000a\u0009\u0009\u0009done(err); // `err` will pass to the `callback`\u000a\u0009\u0009});\u000a\u0009}\u000a}\u000a```\u000a\u000a\u000a# Programmatical Details\u000a\u000a## Options\u000a\u000a#### options.default_message `String`\u000a\u000aDefault error message\u000a\u000a#### options.parallel `Boolean=false`\u000a\u000aBy default, `checker` will check each properties in series, \u000a\u000a#### options.limit `Boolean=false`\u000a\u000aIf `options.limit` is `true` and a certain property of the input data is not defined in the `schema`, the property will be removed.\u000a\u000aDefault to `false`.\u000a\u000a#### options.check_all `Boolean=false`\u000a\u000aBy default, `checker` will exit immediately at the first error. But if `options.check_all` is `true`, it will parse all the properties, and collect every possible error.\u000a\u000a#### options.context `Object`\u000a\u000aSee sections below.\u000a\u000a## Schema Structures \u000a\u000a```js\u000a{\u000a\u0009<name>: <rule>\u000a}\u000a```\u000a\u000a\u000aWhere `rule` might contains (all properties are optional):\u000a\u000a#### validator \u000a\u000a- `RegExp` The regular exp that input must matches against\u000a- `Function` Validation function. If `arguments.length === 3`, it will be considered as an async methods\u000a- `Array.<RegExp|Function>` Group of validations. Asks will check each validator one by one. If validation fails, the rest validators will be skipped.\u000a- See sections above for details\u000a\u0009\u000a#### setter `Function|Array.<Function>`\u000a\u000aSee sections above for details.\u000a\u000a#### message `String`\u000a\u000aDefault error message\u000a\u000a#### default: `String`\u000a\u000a\u000a## `this` object inside validators and setters\u000a\u000aInside validators(`rule.validator`) and setters(`rule.setter`), there're several opaque methods\u000a\u000a### this.async()\u000a\u000aGenerate the `done` function to make the validator or setter become an async method.\u000a\u000a\u0009var done = this.async();\u000a\u0009\u000aFor details, see the demos above.\u000a\u000a### this.get(name)\u000a\u000aThe value of the input object by name\u000a\u000a### this.set(name, value)\u000a\u000aChange the value of the specified property of the input object.\u000a\u000a```\u000a{\u000a\u0009username: {\u000a\u0009},\u000a\u0009\u000a\u0009password: {\u000a\u0009\u0009validator: function(value){\u000a\u0009\u0009\u0009var username = this.get('username');\u000a\u0009\u0009\u0009\u000a\u0009\u0009\u0009// Guests are welcome even without passwords\u000a\u0009\u0009\u0009return value || username === 'guest';\u000a\u0009\u0009}\u000a\u0009}\u000a}\u000a```\u000a\u000aNotice that you'd better use `this.get` and `this.set` with the `options.parallel` setting as `false`(the default value). Otherwise, it might encounter unexpected situations, because the value of the object is ever changing due to the setter.\u000a\u000aSo, use them wisely.\u000a\u000a### this.context `Object`\u000a\u000aThe `options.context` itself.\u000a\u000a\u000a\u000a","readmeFilename":"README.md","_id":"checker@0.5.1","dist":{"shasum":"fef66f63d231ae2910f7dd7df291912a1e95e5d7","tarball":"http://registry.npmjs.org/checker/-/checker-0.5.1.tgz"},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"kael","email":"i@kael.me"},"maintainers":[{"name":"kael","email":"i@kael.me"}],"directories":{}},"0.5.2":{"name":"checker","version":"0.5.2","description":"Checker is the collection of common abstract methods for validatiors and setters.","main":"index.js","scripts":{"test":"make test"},"repository":{"type":"git","url":"git://github.com/kaelzhang/node-checker.git"},"keywords":["checker","validator","validate","setter"],"author":{"name":"kael"},"license":"MIT","bugs":{"url":"https://github.com/kaelzhang/node-checker/issues"},"devDependencies":{"mocha":"~1.13.0","chai":"~1.8.0"},"dependencies":{"async":"~0.2.9"},"readme":"[![NPM version](https://badge.fury.io/js/checker.png)](http://badge.fury.io/js/checker)\u000a[![Build Status](https://travis-ci.org/kaelzhang/node-checker.png?branch=master)](https://travis-ci.org/kaelzhang/node-checker)\u000a[![Dependency Status](https://gemnasium.com/kaelzhang/node-checker.png)](https://gemnasium.com/kaelzhang/node-checker)\u000a\u000a# checker\u000a\u000aChecker is the collection of common abstract node.js methods for validatiors and setters.\u000a\u0009\u000a# Usage\u000a```sh\u000anpm install checker --save\u000a```\u000a\u000a```js\u000avar checker = require('checker');\u000a```\u000a\u000a# Synopsis\u000a\u000a```js\u000achecker(schema, options).check(data, function(err, value, details){\u000a});\u000a```\u000a\u000a### err `mixed`\u000a\u000a### results `Object`\u000a\u000aThe parsed object.\u000a\u000a### details `Object`\u000a\u000a```\u000a{\u000a\u0009<name>: <detail>\u000a}\u000a```\u000a\u000a- `detail.value` `mixed` the parsed value\u000a- `detail.is_default` `Boolean` if the current property is defined in `schema`, but the input data doesn't have it, then the value will be `true`\u000a- `detail.is_cooked` `Boolean` if there're any setters, it will be `true`\u000a- `detail.origin` the origin value of the property\u000a- `detail.error` the error belongs to the current property. If not exists, it will be `null`\u000a\u000a\u000a# Validation, Error Messages\u000a\u000a## Simple synchronous validators\u000a\u000a```js\u000avar schema = {\u000a\u0009username: {\u000a\u0009\u0009validator: function(value){\u000a\u0009\u0009\u0009return /^[a-zA-Z0-9]{6,}$/.test(value);\u000a\u0009\u0009},\u000a\u0009\u0009message: 'Username must only contain letters, numbers; ' \u000a\u0009\u0009\u0009+ 'Username must contain at least 6 charactors'\u000a\u0009}\u000a};\u000a\u000avar c = checker(schema);\u000a\u000ac.check({\u000a\u0009username: 'a'\u000a}, function(err){\u000a\u0009if(err){\u000a\u0009\u0009console.log(err); // Then, `schema.username.message` will be displayed.\u000a\u0009}\u000a});\u000a```\u000a\u000a## Regular expressions as validators\u000a\u000aThe error hint of the example above is bad, because we want to know the very certain reason why we are wrong.\u000a\u000aThe `schema` below is equivalent to the one of the previous section:\u000a\u000a```js\u000a{\u000a\u0009validator: [\u000a\u0009\u0009function(value){\u000a\u0009\u0009\u0009return value && value.length > 5;\u000a\u0009\u0009}, \u000a\u0009\u0009/^[a-zA-Z0-9]+$/\u000a\u0009],\u000a\u0009message: [\u000a\u0009\u0009'Username must contain at least 6 charactors', \u000a\u0009\u0009'Username must only contain letters and numbers'\u000a\u0009];\u000a}\u000a```\u000a\u000a## Asynchronous validators\u000a\u000a```js\u000a{\u000a\u0009validator: function(value){\u000a\u0009\u0009var done = this.async();\u000a\u0009\u0009// this is an async method, and takes sooooo long...\u000a\u0009\u0009remote_check(value, function(err){\u000a\u0009\u0009\u0009done(err); // `err` will pass to the `callback`\u000a\u0009\u0009});\u000a\u0009}\u000a}\u000a```\u000a\u000a\u000a# Programmatical Details\u000a\u000a## Options\u000a\u000a#### options.default_message `String`\u000a\u000aDefault error message\u000a\u000a#### options.parallel `Boolean=false`\u000a\u000aBy default, `checker` will check each properties in series, \u000a\u000a#### options.limit `Boolean=false`\u000a\u000aIf `options.limit` is `true` and a certain property of the input data is not defined in the `schema`, the property will be removed.\u000a\u000aDefault to `false`.\u000a\u000a#### options.check_all `Boolean=false`\u000a\u000aBy default, `checker` will exit immediately at the first error. But if `options.check_all` is `true`, it will parse all the properties, and collect every possible error.\u000a\u000a#### options.context `Object`\u000a\u000aSee sections below.\u000a\u000a## Schema Structures \u000a\u000a```js\u000a{\u000a\u0009<name>: <rule>\u000a}\u000a```\u000a\u000a\u000aWhere `rule` might contains (all properties are optional):\u000a\u000a#### validator \u000a\u000a- `RegExp` The regular exp that input must matches against\u000a- `Function` Validation function. If `arguments.length === 3`, it will be considered as an async methods\u000a- `Array.<RegExp|Function>` Group of validations. Asks will check each validator one by one. If validation fails, the rest validators will be skipped.\u000a- See sections above for details\u000a\u0009\u000a#### setter `Function|Array.<Function>`\u000a\u000aSee sections above for details.\u000a\u000a#### message `String`\u000a\u000aDefault error message\u000a\u000a#### default: `String`\u000a\u000a\u000a## `this` object inside validators and setters\u000a\u000aInside validators(`rule.validator`) and setters(`rule.setter`), there're several opaque methods\u000a\u000a### this.async()\u000a\u000aGenerate the `done` function to make the validator or setter become an async method.\u000a\u000a\u0009var done = this.async();\u000a\u0009\u000aFor details, see the demos above.\u000a\u000a### this.get(name)\u000a\u000aThe value of the input object by name\u000a\u000a### this.set(name, value)\u000a\u000aChange the value of the specified property of the input object.\u000a\u000a```\u000a{\u000a\u0009username: {\u000a\u0009},\u000a\u0009\u000a\u0009password: {\u000a\u0009\u0009validator: function(value){\u000a\u0009\u0009\u0009var username = this.get('username');\u000a\u0009\u0009\u0009\u000a\u0009\u0009\u0009// Guests are welcome even without passwords\u000a\u0009\u0009\u0009return value || username === 'guest';\u000a\u0009\u0009}\u000a\u0009}\u000a}\u000a```\u000a\u000aNotice that you'd better use `this.get` and `this.set` with the `options.parallel` setting as `false`(the default value). Otherwise, it might encounter unexpected situations, because the value of the object is ever changing due to the setter.\u000a\u000aSo, use them wisely.\u000a\u000a### this.context `Object`\u000a\u000aThe `options.context` itself.\u000a\u000a\u000a\u000a","readmeFilename":"README.md","_id":"checker@0.5.2","dist":{"shasum":"c27a36bf00f3a7a3d24a8fbc7853f06fce4e9c86","tarball":"http://registry.npmjs.org/checker/-/checker-0.5.2.tgz"},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"kael","email":"i@kael.me"},"maintainers":[{"name":"kael","email":"i@kael.me"}],"directories":{}}},"readme":"ERROR: No README data found!","maintainers":[{"name":"kael","email":"i@kael.me"}],"time":{"modified":"2013-10-17T03:05:51.738Z","created":"2013-10-07T13:53:26.836Z","0.0.0":"2013-10-07T14:00:18.706Z","0.2.1":"2013-10-08T13:10:06.237Z","0.3.1":"2013-10-08T14:00:33.456Z","0.3.2":"2013-10-08T14:36:07.451Z","0.4.2":"2013-10-09T10:02:48.711Z","0.5.1":"2013-10-09T16:43:25.048Z","0.5.2":"2013-10-17T03:05:51.738Z"},"author":{"name":"kael"},"repository":{"type":"git","url":"git://github.com/kaelzhang/node-checker.git"},"_attachments":{}}