{"_id":"contracts","_rev":"34-1dcaa0b56084c8416a3d8b039bf73fac","name":"contracts","description":"Validation library to define and validate JSON Schemas for functions and express handlers. Supports filters.","dist-tags":{"latest":"0.4.0"},"versions":{"0.1.0":{"name":"contracts","version":"0.1.0","description":"Validation library to define and validate JSON Schemas for functions and express handlers. Supports filters.","keywords":["json schema","schema","data","validation","express"],"author":{"name":"Eirikur Nilsson","email":"eirikur@nilsson.is"},"url":"http://github.com/eirikurn/contracts/","dependencies":{"validator":"> 0.2.0"},"main":"index","engines":{"node":">= 0.4.1"},"devDependencies":{},"_id":"contracts@0.1.0","_engineSupported":true,"_npmVersion":"1.0.3","_nodeVersion":"v0.4.2","_defaultsLoaded":true,"dist":{"shasum":"60cf948660c23a5055a0a5317bdd02bcb2c22923","tarball":"https://registry.npmjs.org/contracts/-/contracts-0.1.0.tgz","integrity":"sha512-xl+cYiral+bDZgk9d2ET36+AdmPYafFeS90MF/lEEOWdPjDJ9vocwfdLQ0X2Ai1lqov6FH26QJjBa3NWEaXCeA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBbX15wV08NvYfeSK7KeiCoUB36NEDFy0H/2fy03H9B7AiEA41Ml4zpx32JNA8iTYsFv8QYgkUydV+yKiKO42MNK9FI="}]},"scripts":{},"directories":{}},"0.2.0":{"name":"contracts","version":"0.2.0","description":"Validation library to define and validate JSON Schemas for functions and express handlers. Supports filters.","keywords":["json schema","schema","data","validation","express"],"author":{"name":"Eirikur Nilsson","email":"eirikur@nilsson.is"},"url":"http://github.com/eirikurn/contracts/","dependencies":{"validator":"> 0.2.0"},"main":"index","engines":{"node":">= 0.4.1"},"devDependencies":{},"_id":"contracts@0.2.0","_engineSupported":true,"_npmVersion":"1.0.3","_nodeVersion":"v0.4.2","_defaultsLoaded":true,"dist":{"shasum":"9bedd06c3dbcc82a505fc587a354456c02de383e","tarball":"https://registry.npmjs.org/contracts/-/contracts-0.2.0.tgz","integrity":"sha512-Q5eal/2UbiWXB746nfb/qWELVDM0cY8f/IdtSU7Vawze1UYXkN8ycIyUDCR5BLGxYebw4i0MqW1NzvS1yX6EEg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCT8N11Tm/jA1spA5ZTIpK3EQclX6jq2XL2HkHfUMgghAIhALtA2JwaZ75W/M7HrtfGoMJD1xLHki7jCb7JW/y6auXA"}]},"scripts":{},"directories":{}},"0.2.1":{"name":"contracts","version":"0.2.1","description":"Validation library to define and validate JSON Schemas for functions and express handlers. Supports filters.","keywords":["json schema","schema","data","validation","express"],"author":{"name":"Eirikur Nilsson","email":"eirikur@nilsson.is"},"url":"http://github.com/eirikurn/contracts/","dependencies":{"validator":"> 0.2.0"},"main":"index","engines":{"node":">= 0.4.1"},"devDependencies":{},"_id":"contracts@0.2.1","_engineSupported":true,"_npmVersion":"1.0.3","_nodeVersion":"v0.4.2","_defaultsLoaded":true,"dist":{"shasum":"3b3ef3ac2346aa9cb3788d0f7420e76d83d90897","tarball":"https://registry.npmjs.org/contracts/-/contracts-0.2.1.tgz","integrity":"sha512-ZYlRF+ruWQdo3rX/RplTO7NS3FNB60UQ6Lmie+v+zhLWeilzOVRngHMh/65jXE+je1syCMrN2QIgmlvcXsbDaQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAMhEM2SGUJRFHk0DeY92eCiH+6VXRNRyFHerP+TMuEuAiEA8tAj6r6Up0nPtXC9KR6CYXqhd00ORohAV0UU/wAIdLA="}]},"scripts":{},"directories":{}},"0.3.0":{"name":"contracts","version":"0.3.0","description":"Validation library to define and validate JSON Schemas for functions and express handlers. Supports filters.","keywords":["json schema","schema","data","validation","express"],"author":{"name":"Eirikur Nilsson","email":"eirikur@nilsson.is"},"url":"http://github.com/eirikurn/contracts/","dependencies":{"validator":"> 0.2.0"},"main":"index","engines":{"node":">= 0.4.1"},"devDependencies":{},"_id":"contracts@0.3.0","_engineSupported":true,"_npmVersion":"1.0.3","_nodeVersion":"v0.4.2","_defaultsLoaded":true,"dist":{"shasum":"9184978c0ad91dd05e727f9ce86085e9db7e7954","tarball":"https://registry.npmjs.org/contracts/-/contracts-0.3.0.tgz","integrity":"sha512-TSsqxGyh7n3ZXOfDMs+r+BHG4WOkMd+jxX5MXW/ONBOMGKbLfWlqbglR4hPvEmD0B4tUhxLBrHgDqcG+rgCvQA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICHNWgqvUuY6jivNFNloPJJPzmDvRRjB/um5KDvYVYLbAiBNO8oUOkEPATy6tqDDeiQPZIjVBc5TlcVIRF3eNsbgMQ=="}]},"scripts":{},"directories":{}},"0.3.1":{"name":"contracts","version":"0.3.1","description":"Validation library to define and validate JSON Schemas for functions and express handlers. Supports filters.","keywords":["json schema","schema","data","validation","express"],"author":{"name":"Eirikur Nilsson","email":"eirikur@nilsson.is"},"url":"http://github.com/eirikurn/contracts/","dependencies":{"validator":"0.2.9","JSV":"3.5.0"},"main":"index","engines":{"node":">= 0.4.1"},"_npmUser":{"name":"eirikurn","email":"eirikur@nilsson.is"},"_id":"contracts@0.3.1","devDependencies":{},"_engineSupported":true,"_npmVersion":"1.0.101","_nodeVersion":"v0.4.12","_defaultsLoaded":true,"dist":{"shasum":"705869df3f45357bed002687d8398e6bbe158595","tarball":"https://registry.npmjs.org/contracts/-/contracts-0.3.1.tgz","integrity":"sha512-w3O8jRiLzPM6pErG4EzAcS1YOLd7xRWkNF1dpGPf+uPHh5JS+eZrXAbniDlIvIug6qvnf3126LDhR0ZgCnJ8Jg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCqXv2wbSxfMlhbp7d+xYq8zMD5HyQfBuojEEU7PNKM3gIgbpXfBdLwa/CGKAxWYabI5RXqsFL29Myo0da2jyhY9Z0="}]},"maintainers":[{"name":"eirikurn","email":"eirikur@nilsson.is"}],"directories":{}},"0.3.2":{"name":"contracts","version":"0.3.2","description":"Validation library to define and validate JSON Schemas for functions and express handlers. Supports filters.","keywords":["json schema","schema","data","validation","express"],"author":{"name":"Eirikur Nilsson","email":"eirikur@nilsson.is"},"url":"http://github.com/eirikurn/contracts/","dependencies":{"JSV":"3.5.0","validator":"0.2.9"},"devDependencies":{"expresso":"0.9.x","should":"0.6.x"},"main":"index","engines":{"node":">= 0.6.0"},"_npmUser":{"name":"eirikurn","email":"eirikur@nilsson.is"},"_id":"contracts@0.3.2","_engineSupported":true,"_npmVersion":"1.1.0-beta-4","_nodeVersion":"v0.6.6","_defaultsLoaded":true,"dist":{"shasum":"586ac7ee2f4d9170b843354244543e48273b18dc","tarball":"https://registry.npmjs.org/contracts/-/contracts-0.3.2.tgz","integrity":"sha512-f4AwEJPAGlvW0uGYXTOymXz8VDPu/g2GRwgIbP+/JQLoBM5OOWQ3TzwEk+p+YahRS6CLmme3upCUMQaLuaHDgg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCmJvIfoAtEHs4eLILxUwSJYaC5V2SDUQ03JEDb4kGqywIhALpi2r4X+guu1RCZJbaq3Kpt6LxMOEpx7vIpUi/cVNB3"}]},"readme":"# Contracts\n\nDefine contracts for functions and express handlers to validate and filter parameters. This library bundles the [Json Schema Validator](https://github.com/garycourt/JSV) package with customizable format validation and filter support. It includes some nice filters and formats from the [node-validator](https://github.com/chriso/node-validator) library.\n\n## Defining Schemas\n\n    var contracts = require('contracts')\n      , f = contracts.filters;\n\n    var addSchema = {\n      type: 'array',\n      items: {\n        type: 'number',\n        filter: f.toFloat()\n      }\n    };\n\n    var userSchema = {\n      type: 'object',\n      additionalProperties: false,\n      filters: f.cleanObject(),\n      properties: {\n        email: { type: 'string', required: true, format: 'email' },\n        password: { type: 'string', required: true, minLength: 6 },\n        age: { type: 'integer', required: true, filter: f.toInt() }\n      }\n    };\n\n## Validating to a schema\n\n    var report = contracts.validate([5, '13', 8], addSchema);\n    report.errors;   // []\n    report.instance; // [5, 13, 8]\n\n## Transforming data using a schema\n\n    var new_obj = contracts.transform({email: 'foo@bar.com', password: 'foobar', age: '15', DANGEROUS: '...'}, userSchema);\n    new_obj; // {email: 'foo@bar.com', password: 'foobar', age: 15}\n\n## Wrapping functions for validation and data-fixing\n\n    var add = contracts.wrap(function() {\n      var args = [].slice.call(arguments)\n        , sum = args.reduce(function(a,b) { return a + b; }, 0);\n      return sum;\n    }, addSchema);\n    \n    add('5', '19.5', 3); // 27.5\n    add(1, {});          // throw ValidationError()\n\n## Validating post data in express with a view middleware\n\n    var app = express.createServer();\n    app.use express.bodyParser();\n\n    app.post('/users', contracts.view(userSchema), function(req, res) {\n        req.body; // {email: 'foo@bar.com', password: 'foobar', age: '15', DANGEROUS: '...'}\n        req.data; // {email: 'foo@bar.com', password: 'foobar', age: 15}\n    });\n\n## Built-in filters\n\n* cleanObject\n* cleanArray\n* removeEmpty\n\nFrom node-validator:\n\n* xss\n* entityDecode\n* entityEncode\n* ltrim\n* rtrim\n* trim\n* ifNull\n* toFloat\n* toInt\n* toBoolean\n* toBooleanStrict\n\n## Built-in format validators\n\nFrom node-validator:\n\n* email\n* url\n* ip\n* int\n* decimal\n* float\n* uuid\n\n## Custom filters\n\n    var schema = {\n      type: 'string',\n      filter: function(str) {\n        return str.replace(/-/g, '');\n      }\n    }\n\n    contracts.filters.add('stripSlashes', function(str) { return str.replace(/-/g, ''); });\n    schema = {\n      type: 'string',\n      filter: contracts.filters.stripSlashes().trim()\n    }\n\n## Custom formats\n\n    contracts.formats.add('ssn', function(str) {\n      // TODO: Validate that str is a ssn.\n      return true;\n    });\n\n    var schema = {\n      type: 'string',\n      format: 'ssn'\n    }\n\n## License \n\n(The MIT License)\n\nCopyright (c) 2011 Eirikur Nilsson &lt;eirikur@nilsson.is&gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n","maintainers":[{"name":"eirikurn","email":"eirikur@nilsson.is"}]},"0.4.0":{"name":"contracts","version":"0.4.0","description":"Validation library to define and validate JSON Schemas for functions and express handlers. Supports filters.","keywords":["json schema","schema","data","validation","express"],"author":{"name":"Eirikur Nilsson","email":"eirikur@nilsson.is"},"url":"http://github.com/eirikurn/contracts/","dependencies":{"JSV":"3.5.0","validator":"0.2.9"},"devDependencies":{"expresso":"0.9.x","should":"0.6.x"},"main":"index","engines":{"node":">= 0.6.0"},"_npmUser":{"name":"eirikurn","email":"eirikur@nilsson.is"},"_id":"contracts@0.4.0","_engineSupported":true,"_npmVersion":"1.1.0-beta-4","_nodeVersion":"v0.6.6","_defaultsLoaded":true,"dist":{"shasum":"32788d79ee1ac482e5fa7aa7fc29704b8709060f","tarball":"https://registry.npmjs.org/contracts/-/contracts-0.4.0.tgz","integrity":"sha512-1VdEcGnt4Dk+G/mccfIJYuJZ52uIYMSSBfdQiXXuIhP8e1dNnUima7p9XBzGH+xgX2N88oS3bmeEj2DVTWk/4Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBxjr9VsKeckIfr8saouOAKFCBg5HeWks6Ai840JQFsGAiEA1sRTOkJYYwxRN45IamsBtATltYbTQE/m14ic4wv+orE="}]},"readme":"# Contracts\n\nDefine contracts for functions and express handlers to validate and filter parameters. This library bundles the [Json Schema Validator](https://github.com/garycourt/JSV) package with customizable format validation and filter support. It includes some nice filters and formats from the [node-validator](https://github.com/chriso/node-validator) library.\n\n## Defining Schemas\n\n    var contracts = require('contracts')\n      , f = contracts.filters;\n\n    var addSchema = {\n      type: 'array',\n      items: {\n        type: 'number',\n        filter: f.toFloat()\n      }\n    };\n\n    var userSchema = {\n      type: 'object',\n      additionalProperties: false,\n      filters: f.cleanObject(),\n      properties: {\n        email: { type: 'string', required: true, format: 'email' },\n        password: { type: 'string', required: true, minLength: 6 },\n        age: { type: 'integer', required: true, filter: f.toInt() }\n      }\n    };\n\n## Validating to a schema\n\n    var report = contracts.validate([5, '13', 8], addSchema);\n    report.errors;   // []\n    report.instance; // [5, 13, 8]\n\n## Transforming data using a schema\n\n    var new_obj = contracts.transform({email: 'foo@bar.com', password: 'foobar', age: '15', DANGEROUS: '...'}, userSchema);\n    new_obj; // {email: 'foo@bar.com', password: 'foobar', age: 15}\n\n## Wrapping functions for validation and data-fixing\n\n    var add = contracts.wrap(function() {\n      var args = [].slice.call(arguments)\n        , sum = args.reduce(function(a,b) { return a + b; }, 0);\n      return sum;\n    }, addSchema);\n    \n    add('5', '19.5', 3); // 27.5\n    add(1, {});          // throw ValidationError()\n\n## Validating post data in express with a view middleware\n\n    var app = express.createServer();\n    app.use express.bodyParser();\n\n    app.post('/users', contracts.view(userSchema), function(req, res) {\n        req.body; // {email: 'foo@bar.com', password: 'foobar', age: '15', DANGEROUS: '...'}\n        req.data; // {email: 'foo@bar.com', password: 'foobar', age: 15}\n    });\n\n## Built-in filters\n\n* cleanObject\n* cleanArray\n* removeEmpty\n\nFrom node-validator:\n\n* xss\n* entityDecode\n* entityEncode\n* ltrim\n* rtrim\n* trim\n* ifNull\n* toFloat\n* toInt\n* toBoolean\n* toBooleanStrict\n\n## Built-in format validators\n\nFrom node-validator:\n\n* email\n* url\n* ip\n* int\n* decimal\n* float\n* uuid\n\n## Custom filters\n\n    var schema = {\n      type: 'string',\n      filter: function(str) {\n        return str.replace(/-/g, '');\n      }\n    }\n\n    contracts.filters.add('stripSlashes', function(str) { return str.replace(/-/g, ''); });\n    schema = {\n      type: 'string',\n      filter: contracts.filters.stripSlashes().trim()\n    }\n\n## Custom formats\n\n    contracts.formats.add('ssn', function(str) {\n      // TODO: Validate that str is a ssn.\n      return true;\n    });\n\n    var schema = {\n      type: 'string',\n      format: 'ssn'\n    }\n\n## License \n\n(The MIT License)\n\nCopyright (c) 2011 Eirikur Nilsson &lt;eirikur@nilsson.is&gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n","maintainers":[{"name":"eirikurn","email":"eirikur@nilsson.is"}]}},"maintainers":[{"name":"eirikurn","email":"eirikur@nilsson.is"}],"time":{"modified":"2022-06-13T22:40:44.775Z","created":"2011-05-16T01:24:37.119Z","0.1.0":"2011-05-16T01:24:37.826Z","0.2.0":"2011-05-17T23:02:49.140Z","0.2.1":"2011-07-05T21:59:25.731Z","0.3.0":"2011-07-20T23:50:15.457Z","0.3.1":"2011-10-22T18:33:02.931Z","0.3.2":"2012-03-01T21:54:39.806Z","0.4.0":"2012-03-10T19:14:17.309Z"},"author":{"name":"Eirikur Nilsson","email":"eirikur@nilsson.is"},"users":{"sergiosdlima":true}}