{"_id":"joi-assert","_rev":"4579187","name":"joi-assert","description":"Assert values using Joi schemas","dist-tags":{"latest":"0.0.3"},"maintainers":[{"name":"bartvds","email":"bartvanderschoor@gmail.com"}],"time":{"modified":"2026-04-10T15:53:25.000Z","created":"2014-04-26T21:58:08.574Z","0.0.3":"2014-04-26T23:03:02.178Z","0.0.2":"2014-04-26T21:58:08.574Z"},"users":{},"author":{"name":"Bart van der Schoor","url":"https://github.com/Bartvds"},"repository":{"type":"git","url":"git://github.com/Bartvds/joi-assert.git"},"versions":{"0.0.3":{"name":"joi-assert","version":"0.0.3","description":"Assert values using Joi schemas","keywords":["joi","schema","validation","assert","assertion","error","filter","sanitize"],"homepage":"https://github.com/Bartvds/joi-assert","repository":{"type":"git","url":"git://github.com/Bartvds/joi-assert.git"},"author":{"name":"Bart van der Schoor","url":"https://github.com/Bartvds"},"licenses":[{"type":"MIT","url":"https://raw.github.com/Bartvds/joi-assert/master/LICENSE-MIT.txt"}],"bugs":{"url":"https://github.com/Bartvds/joi-assert/issues"},"engines":{"node":">= 0.10.0 <= 0.11.0"},"main":"./index.js","scripts":{"test":"grunt test"},"dependencies":{"assertion-error":"^1.0.0"},"devDependencies":{"joi":"^4.0.0","grunt":"~0.4.2","mocha-unfunk-reporter":"^0.4.0","grunt-contrib-jshint":"^0.10.0","grunt-mocha-test":"^0.10.2","jshint-path-reporter":"^0.1.3","chai":"^1.9.1"},"_id":"joi-assert@0.0.3","dist":{"shasum":"77291376ac3f0b124f433f98db74b4f20f686fd6","size":3449,"noattachment":false,"key":"/joi-assert/-/joi-assert-0.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/joi-assert/download/joi-assert-0.0.3.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"bartvds","email":"bartvanderschoor@gmail.com"},"maintainers":[{"name":"bartvds","email":"bartvanderschoor@gmail.com"}],"directories":{},"publish_time":1398553382178,"_hasShrinkwrap":false,"_cnpm_publish_time":1398553382178,"_cnpmcore_publish_time":"2021-12-16T21:35:44.911Z"},"0.0.2":{"name":"joi-assert","version":"0.0.2","description":"Assert values using Joi schemas","keywords":["schema","validation","assertion","assert","error","filter","strip"],"homepage":"https://github.com/Bartvds/joi-assert","repository":{"type":"git","url":"git://github.com/Bartvds/joi-assert.git"},"author":{"name":"Bart van der Schoor","url":"https://github.com/Bartvds"},"licenses":[{"type":"MIT","url":"https://raw.github.com/Bartvds/joi-assert/master/LICENSE-MIT.txt"}],"bugs":{"url":"https://github.com/Bartvds/joi-assert/issues"},"engines":{"node":">= 0.10.0 <= 0.11.0"},"main":"./dist/index.js","scripts":{"test":"grunt test"},"dependencies":{"joi":"^4.0.0","assertion-error":"^1.0.0"},"devDependencies":{"grunt":"~0.4.2","mocha-unfunk-reporter":"^0.4.0","grunt-contrib-jshint":"^0.10.0","grunt-mocha-test":"^0.10.2","jshint-path-reporter":"^0.1.3","chai":"^1.9.1"},"_id":"joi-assert@0.0.2","dist":{"shasum":"bf8ddd42341c11c7e1bd29d8034d77ab50f546bb","size":3136,"noattachment":false,"key":"/joi-assert/-/joi-assert-0.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/joi-assert/download/joi-assert-0.0.2.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"bartvds","email":"bartvanderschoor@gmail.com"},"maintainers":[{"name":"bartvds","email":"bartvanderschoor@gmail.com"}],"directories":{},"publish_time":1398549488574,"_hasShrinkwrap":false,"_cnpm_publish_time":1398549488574,"_cnpmcore_publish_time":"2021-12-16T21:35:45.172Z"}},"readme":"# joi-assert\n\n[![Build Status](https://secure.travis-ci.org/Bartvds/joi-assert.png?branch=master)](http://travis-ci.org/Bartvds/joi-assert) [![NPM version](https://badge.fury.io/js/joi-assert.png)](http://badge.fury.io/js/joi-assert) [![Dependency Status](https://david-dm.org/Bartvds/joi-assert.png)](https://david-dm.org/Bartvds/joi-assert) [![devDependency Status](https://david-dm.org/Bartvds/joi-assert/dev-status.png)](https://david-dm.org/Bartvds/joi-assert#info=devDependencies)\n\n> Assert values using Joi schemas\n\nUse Spumko's [Joi](https://github.com/spumko/joi) in assertion statements that validate and sanitize values.\n\nAssertions throw an [AssertionError](https://github.com/chaijs/assertion-error) with a compact, readable message if validation fails. This makes Joi schemas usable in assertions for use with frameworks like [mocha](https://visionmedia.github.io/mocha/). \n\nIf validation succeeds the sanitized value returned, via Joi's support for default values and unknown property stripping etc. This makes Joi schemas usable as input-assertions in the methods of user facing methods of your modules and APIs.\n\n:warning: Early phase so users beware.\n\n## Usage\n\nGet it from npm:\n\n````bash\n$ npm install joi\n$ npm install joi-assert\n````\n\n### Basic assertion\n\n````js\n// import plain Joi\nvar Joi = require('joi');\n\n// import the module\nvar joiAssert = require('joi-assert');\n\n// get a Joi schema\nvar schema = Joi.string().min(5);\n\n// validate data and throw AssertionError on failure\njoiAssert(raw, schema);\n\n// assertion returns valid data as oneliner\nvar valid = joiAssert(raw, schema);\n````\n\n### Error message\n\n````js\n// add schema description to error message\nvar schema = Joi.string().min(5).description('lower bound');\n\n// additonal message per call\ninput = joiAssert(imput, schema, 'input check');\n````\n\n### Validate *and* sanitize input\n\n````js\n// get a schema using default(), .stripUnknown etc\nvar schema = Joi.object({\n\tfoo: Joi.string().required(),\n\tbar: Joi.string().optional().default('hoge')\n}).object({\n\tstripUnknown: true\n});\n\n// get valid but dirty input data\nvar raw = {\n\tfoo: 'abc',\n\tnope: null\n}\n// pass through assertion\nvar data = joiAssert(raw, schema);\n\n// data is now clean\n{\n\tfoo: 'abc',\n\tbar: 'hoge'\n}\n````\n\n### Bake assertion function\n\n````js\n// get a schema\nvar schema = Joi.string().min(5).max(10);\n\n// get assertion closure\nvar fiveTen = joiAssert.bake(schema, 'five to ten');\n\n// nice\nfiveTen(10);\nfiveTen(5);\n\n// clean\ninput = fiveTen(input);\n\n// kablam!\nfiveTen(20);\n\n// get fancy\nvar clean = [5, 6, 7, 8].map(fiveTen);\n````\n\n## Todo\n\n* Improve vars argument\n\t* Support argument as Object, Array and String\n\t* Consider sprintf style smart args (order etc)\n\t* Test it \n* Add options to customise error message:\n\t* Amount of concatenated reports\n\t* Multiline message\n\n## Build\n\nInstall development dependencies:\n\n````bash\n$ npm install\n$ npm install -g grunt-cli\n````\n\nBuild and run tests using [grunt](http://gruntjs.com):\n\n````bash\n$ grunt test\n````\n\nSee the `Gruntfile.js` for additional commands.\n\n## Contributions\n\nPull requests with fixes are very welcome, for new features best ask via a [issue](https://github.com/Bartvds/joi-assert/issues) first.\n\n## License\n\nCopyright (c) 2014 Bart van der Schoor\n\nLicensed under the MIT license.\n","_attachments":{},"homepage":"https://github.com/Bartvds/joi-assert","bugs":{"url":"https://github.com/Bartvds/joi-assert/issues"}}