{"_id":"node-ensurethat","_rev":"326532","name":"node-ensurethat","description":"node-ensurethat makes arguments handling a breeze.","dist-tags":{"latest":"0.1.5"},"maintainers":[{"name":"goloroden","email":"webmaster@goloroden.de"},{"name":"nhummel","email":"hummel@marvelous.systems"},{"name":"thenativeweb-admin","email":"hello@thenativeweb.io"}],"time":{"modified":"2021-06-07T02:44:51.000Z","created":"2013-10-19T19:46:05.163Z","0.1.5":"2014-09-20T20:46:21.605Z","0.1.4":"2014-09-20T19:53:30.310Z","0.1.3":"2014-09-20T17:00:13.098Z","0.1.1":"2014-09-19T04:22:22.601Z","0.1.0":"2014-09-18T04:59:25.569Z","0.0.5":"2014-09-16T06:45:13.992Z","0.0.3":"2013-10-28T18:36:36.576Z","0.0.2":"2013-10-19T21:06:25.849Z","0.0.1":"2013-10-19T19:46:05.163Z"},"users":{},"repository":{"type":"git","url":"git://github.com/thenativeweb/node-ensurethat.git"},"versions":{"0.1.5":{"name":"node-ensurethat","version":"0.1.5","description":"node-ensurethat makes arguments handling a breeze.","contributors":[{"name":"Golo Roden","email":"golo.roden@thenativeweb.io"},{"name":"Matthias Wagler","email":"matthias.wagler@thenativeweb.io"}],"main":"lib/ensure.js","dependencies":{"lodash":"2.4.1","require-all":"0.0.8","verbal-expressions":"0.1.2"},"devDependencies":{"grunt":"0.4.5","node-assertthat":"0.2.0","tourism":"0.7.3"},"repository":{"type":"git","url":"git://github.com/thenativeweb/node-ensurethat.git"},"license":"MIT","gitHead":"203cc32d6013867ea513baa4cd893f3a1aa3ec3f","bugs":{"url":"https://github.com/thenativeweb/node-ensurethat/issues"},"homepage":"https://github.com/thenativeweb/node-ensurethat","_id":"node-ensurethat@0.1.5","scripts":{},"_shasum":"09fdf6f71440e182cc9da56edde03cf47d6123da","_from":".","_npmVersion":"1.4.23","_npmUser":{"name":"thenativeweb","email":"hello@thenativeweb.io"},"maintainers":[{"name":"goloroden","email":"webmaster@goloroden.de"},{"name":"nhummel","email":"hummel@marvelous.systems"},{"name":"thenativeweb-admin","email":"hello@thenativeweb.io"}],"dist":{"shasum":"09fdf6f71440e182cc9da56edde03cf47d6123da","size":5845,"noattachment":false,"key":"/node-ensurethat/-/node-ensurethat-0.1.5.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-ensurethat/download/node-ensurethat-0.1.5.tgz"},"directories":{},"publish_time":1411245981605,"_cnpm_publish_time":1411245981605,"deprecated":"Use ensurethat instead.","_hasShrinkwrap":false},"0.1.4":{"name":"node-ensurethat","version":"0.1.4","description":"node-ensurethat makes arguments handling a breeze.","contributors":[{"name":"Golo Roden","email":"golo.roden@thenativeweb.io"},{"name":"Matthias Wagler","email":"matthias.wagler@thenativeweb.io"}],"main":"lib/ensure.js","dependencies":{"lodash":"2.4.1","require-all":"0.0.8","verbal-expressions":"0.1.2"},"devDependencies":{"grunt":"0.4.5","node-assertthat":"0.2.0","tourism":"0.7.1"},"repository":{"type":"git","url":"git://github.com/thenativeweb/node-ensurethat.git"},"license":"MIT","gitHead":"cf1574c58d1ce44388a9220e9ca83f33be07b771","bugs":{"url":"https://github.com/thenativeweb/node-ensurethat/issues"},"homepage":"https://github.com/thenativeweb/node-ensurethat","_id":"node-ensurethat@0.1.4","scripts":{},"_shasum":"0fb45442faafab44ccb2a43bdde65b82f240572f","_from":".","_npmVersion":"1.4.23","_npmUser":{"name":"thenativeweb","email":"hello@thenativeweb.io"},"maintainers":[{"name":"goloroden","email":"webmaster@goloroden.de"},{"name":"nhummel","email":"hummel@marvelous.systems"},{"name":"thenativeweb-admin","email":"hello@thenativeweb.io"}],"dist":{"shasum":"0fb45442faafab44ccb2a43bdde65b82f240572f","size":5682,"noattachment":false,"key":"/node-ensurethat/-/node-ensurethat-0.1.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-ensurethat/download/node-ensurethat-0.1.4.tgz"},"directories":{},"publish_time":1411242810310,"_cnpm_publish_time":1411242810310,"_hasShrinkwrap":false},"0.1.3":{"name":"node-ensurethat","version":"0.1.3","description":"node-ensurethat makes arguments handling a breeze.","contributors":[{"name":"Golo Roden","email":"golo.roden@thenativeweb.io"},{"name":"Matthias Wagler","email":"matthias.wagler@thenativeweb.io"}],"main":"lib/ensure.js","dependencies":{"lodash":"2.4.1","require-all":"0.0.8","verbal-expressions":"0.1.2"},"devDependencies":{"grunt":"0.4.5","node-assertthat":"0.2.0","tourism":"0.7.1"},"repository":{"type":"git","url":"git://github.com/thenativeweb/node-ensurethat.git"},"license":"MIT","gitHead":"0d55ca4df77aa9010e7a2c28be3b84d7d68895c7","bugs":{"url":"https://github.com/thenativeweb/node-ensurethat/issues"},"homepage":"https://github.com/thenativeweb/node-ensurethat","_id":"node-ensurethat@0.1.3","scripts":{},"_shasum":"086c3bf4b1a483633e5e539975c507873c21e403","_from":".","_npmVersion":"1.4.23","_npmUser":{"name":"thenativeweb","email":"hello@thenativeweb.io"},"maintainers":[{"name":"goloroden","email":"webmaster@goloroden.de"},{"name":"nhummel","email":"hummel@marvelous.systems"},{"name":"thenativeweb-admin","email":"hello@thenativeweb.io"}],"dist":{"shasum":"086c3bf4b1a483633e5e539975c507873c21e403","size":5620,"noattachment":false,"key":"/node-ensurethat/-/node-ensurethat-0.1.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-ensurethat/download/node-ensurethat-0.1.3.tgz"},"directories":{},"publish_time":1411232413098,"_cnpm_publish_time":1411232413098,"_hasShrinkwrap":false},"0.1.1":{"name":"node-ensurethat","version":"0.1.1","description":"node-ensurethat makes arguments handling a breeze.","contributors":[{"name":"Golo Roden","email":"golo.roden@thenativeweb.io"},{"name":"Matthias Wagler","email":"matthias.wagler@thenativeweb.io"}],"main":"lib/ensure.js","dependencies":{"lodash":"2.4.1","require-all":"0.0.8"},"devDependencies":{"grunt":"0.4.5","node-assertthat":"0.2.0","tourism":"0.7.0"},"repository":{"type":"git","url":"git://github.com/thenativeweb/node-ensurethat.git"},"license":"MIT","gitHead":"7f94a9895292e6ae9165e63c7a9da8150b024d79","bugs":{"url":"https://github.com/thenativeweb/node-ensurethat/issues"},"homepage":"https://github.com/thenativeweb/node-ensurethat","_id":"node-ensurethat@0.1.1","scripts":{},"_shasum":"eb442bc6e1dee2dba39651fc73ba14f4ea583681","_from":".","_npmVersion":"1.4.23","_npmUser":{"name":"thenativeweb","email":"hello@thenativeweb.io"},"maintainers":[{"name":"goloroden","email":"webmaster@goloroden.de"},{"name":"nhummel","email":"hummel@marvelous.systems"},{"name":"thenativeweb-admin","email":"hello@thenativeweb.io"}],"dist":{"shasum":"eb442bc6e1dee2dba39651fc73ba14f4ea583681","size":5185,"noattachment":false,"key":"/node-ensurethat/-/node-ensurethat-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-ensurethat/download/node-ensurethat-0.1.1.tgz"},"directories":{},"publish_time":1411100542601,"_cnpm_publish_time":1411100542601,"_hasShrinkwrap":false},"0.1.0":{"name":"node-ensurethat","version":"0.1.0","description":"node-ensurethat makes arguments handling a breeze.","contributors":[{"name":"Golo Roden","email":"golo.roden@thenativeweb.io"},{"name":"Matthias Wagler","email":"matthias.wagler@thenativeweb.io"}],"main":"lib/ensure.js","dependencies":{"lodash":"2.4.1","require-all":"0.0.8"},"devDependencies":{"grunt":"0.4.5","node-assertthat":"0.2.0","tourism":"0.7.0"},"repository":{"type":"git","url":"git://github.com/thenativeweb/node-ensurethat.git"},"license":"MIT","gitHead":"61b9e361f79d93cce92c2e69bb8e6e879c6ae466","bugs":{"url":"https://github.com/thenativeweb/node-ensurethat/issues"},"homepage":"https://github.com/thenativeweb/node-ensurethat","_id":"node-ensurethat@0.1.0","scripts":{},"_shasum":"5a0e8c4abb82c097d4cedfae4bbfc8f1ccdae075","_from":".","_npmVersion":"1.4.23","_npmUser":{"name":"thenativeweb","email":"hello@thenativeweb.io"},"maintainers":[{"name":"goloroden","email":"webmaster@goloroden.de"},{"name":"nhummel","email":"hummel@marvelous.systems"},{"name":"thenativeweb-admin","email":"hello@thenativeweb.io"}],"dist":{"shasum":"5a0e8c4abb82c097d4cedfae4bbfc8f1ccdae075","size":4812,"noattachment":false,"key":"/node-ensurethat/-/node-ensurethat-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-ensurethat/download/node-ensurethat-0.1.0.tgz"},"directories":{},"publish_time":1411016365569,"_cnpm_publish_time":1411016365569,"_hasShrinkwrap":false},"0.0.5":{"name":"node-ensurethat","version":"0.0.5","description":"node-ensurethat makes arguments handling a breeze.","contributors":[{"name":"Golo Roden","email":"golo.roden@thenativeweb.io"},{"name":"Matthias Wagler","email":"matthias.wagler@thenativeweb.io"}],"main":"lib/ensure.js","dependencies":{"underscore":"1.7.0"},"devDependencies":{"cases":"0.1.1","grunt":"0.4.5","node-assertthat":"0.2.0","tourism":"0.6.4"},"repository":{"type":"git","url":"git://github.com/thenativeweb/node-ensurethat.git"},"license":"MIT","gitHead":"510df5e9eb2dbbc2848c8b53938c0572a5bda5c9","bugs":{"url":"https://github.com/thenativeweb/node-ensurethat/issues"},"homepage":"https://github.com/thenativeweb/node-ensurethat","_id":"node-ensurethat@0.0.5","scripts":{},"_shasum":"b31a9dcade2ad262ba7e17cbe48fd6b70494f362","_from":".","_npmVersion":"1.4.23","_npmUser":{"name":"thenativeweb","email":"hello@thenativeweb.io"},"maintainers":[{"name":"goloroden","email":"webmaster@goloroden.de"},{"name":"nhummel","email":"hummel@marvelous.systems"},{"name":"thenativeweb-admin","email":"hello@thenativeweb.io"}],"dist":{"shasum":"b31a9dcade2ad262ba7e17cbe48fd6b70494f362","size":4968,"noattachment":false,"key":"/node-ensurethat/-/node-ensurethat-0.0.5.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-ensurethat/download/node-ensurethat-0.0.5.tgz"},"directories":{},"publish_time":1410849913992,"_cnpm_publish_time":1410849913992,"_hasShrinkwrap":false},"0.0.3":{"name":"node-ensurethat","version":"0.0.3","description":"node-ensurethat makes arguments handling a breeze.","author":{"name":"Golo Roden","email":"golo.roden@thenativeweb.io","url":"http://www.thenativeweb.io"},"contributors":[{"name":"Bernd Hasis","email":"berndhasis@gmail.com"}],"main":"lib/ensure.js","dependencies":{"underscore":"1.5.2"},"devDependencies":{"cases":"0.0.2","grunt":"0.4.0","grunt-contrib-jshint":"0.1.1","grunt-contrib-watch":"0.2.0","grunt-mocha-test":"0.6.3","node-assertthat":"0.0.19"},"scripts":{"test":"mocha"},"repository":{"type":"git","url":"git://github.com/goloroden/node-ensurethat.git"},"readmeFilename":"README.md","bugs":{"url":"https://github.com/goloroden/node-ensurethat/issues"},"_id":"node-ensurethat@0.0.3","dist":{"shasum":"cc979dc04d0611b8b60d9696fb68930a663f5c02","size":5502,"noattachment":false,"key":"/node-ensurethat/-/node-ensurethat-0.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-ensurethat/download/node-ensurethat-0.0.3.tgz"},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"goloroden","email":"webmaster@goloroden.de"},"maintainers":[{"name":"goloroden","email":"webmaster@goloroden.de"},{"name":"nhummel","email":"hummel@marvelous.systems"},{"name":"thenativeweb-admin","email":"hello@thenativeweb.io"}],"directories":{},"publish_time":1382985396576,"_cnpm_publish_time":1382985396576,"_hasShrinkwrap":false},"0.0.2":{"name":"node-ensurethat","version":"0.0.2","description":"node-ensurethat makes arguments handling a breeze.","author":{"name":"Golo Roden","email":"golo.roden@thenativeweb.io","url":"http://www.thenativeweb.io"},"main":"lib/ensure.js","dependencies":{"underscore":"1.5.2"},"devDependencies":{"cases":"0.0.2","grunt":"0.4.0","grunt-contrib-jshint":"0.1.1","grunt-contrib-watch":"0.2.0","grunt-mocha-test":"0.6.3","node-assertthat":"0.0.19"},"scripts":{"test":"mocha"},"repository":{"type":"git","url":"git://github.com/goloroden/node-ensurethat.git"},"readmeFilename":"README.md","bugs":{"url":"https://github.com/goloroden/node-ensurethat/issues"},"_id":"node-ensurethat@0.0.2","dist":{"shasum":"d1f84f2ab60a45e928522652d7fd6b19e15c434d","size":4888,"noattachment":false,"key":"/node-ensurethat/-/node-ensurethat-0.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-ensurethat/download/node-ensurethat-0.0.2.tgz"},"_from":".","_npmVersion":"1.2.30","_npmUser":{"name":"goloroden","email":"webmaster@goloroden.de"},"maintainers":[{"name":"goloroden","email":"webmaster@goloroden.de"},{"name":"nhummel","email":"hummel@marvelous.systems"},{"name":"thenativeweb-admin","email":"hello@thenativeweb.io"}],"directories":{},"publish_time":1382216785849,"_cnpm_publish_time":1382216785849,"_hasShrinkwrap":false},"0.0.1":{"name":"node-ensurethat","version":"0.0.1","description":"node-ensurethat makes arguments handling a breeze.","author":{"name":"Golo Roden","email":"golo.roden@thenativeweb.io","url":"http://www.thenativeweb.io"},"main":"lib/ensure.js","dependencies":{"underscore":"1.5.2"},"devDependencies":{"cases":"0.0.2","grunt":"0.4.0","grunt-contrib-jshint":"0.1.1","grunt-contrib-watch":"0.2.0","grunt-mocha-test":"0.6.3","node-assertthat":"0.0.19"},"scripts":{"test":"mocha"},"repository":{"type":"git","url":"git://github.com/thenativeweb/node-ensurethat.git"},"readmeFilename":"README.md","bugs":{"url":"https://github.com/thenativeweb/node-ensurethat/issues"},"_id":"node-ensurethat@0.0.1","dist":{"shasum":"dc3c9f2c38ceebaf7421b257b187bca0f6882b2a","size":3892,"noattachment":false,"key":"/node-ensurethat/-/node-ensurethat-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-ensurethat/download/node-ensurethat-0.0.1.tgz"},"_from":".","_npmVersion":"1.2.30","_npmUser":{"name":"goloroden","email":"webmaster@goloroden.de"},"maintainers":[{"name":"goloroden","email":"webmaster@goloroden.de"},{"name":"nhummel","email":"hummel@marvelous.systems"},{"name":"thenativeweb-admin","email":"hello@thenativeweb.io"}],"directories":{},"publish_time":1382211965163,"_cnpm_publish_time":1382211965163,"_hasShrinkwrap":false}},"readme":"# node-ensurethat\n\nnode-ensurethat makes handling arguments a breeze.\n\n## Installation\n\n    $ npm install node-ensurethat\n\n## Quick start\n\nFirst you need to add a reference to node-ensurethat to your application.\n\n```javascript\nvar ensure = require('node-ensurethat');\n```\n\nNow you are able to use the `that` function to describe the function's arguments using validators. Currently, the following built-in validators are provided.\n\n- `ensure.boolean()`, aliased as `'boolean'`, default value is `false`\n- `ensure.function()`, aliased as `'function'`, default value is a no-op function\n- `ensure.number()`, aliased as `'number'`, default value is `0`\n- `ensure.object()`, aliased as `'object'`, default value is `null`\n- `ensure.string()`, aliased as `'string'`, default value is `''`\n- `ensure.uuid()`, aliased as `'uuid'`, default value is `'00000000-0000-4000-89ab-000000000000'`\n\n```javascript\nvar add = function () {\n  var args = ensure.that(arguments).are({\n    first: ensure.number(),\n    second: ensure.number()\n  });\n\n  return args.first + args.second;\n};\n```\n\nBasically all validators are functions, but those that do not need configuration come with alias names, so that you can also use them by their name.\n\n```javascript\nvar add = function () {\n  var args = ensure.that(arguments).are({\n    first: 'number',\n    second: 'number'\n  });\n\n  return args.first + args.second;\n};\n```\n\nAnyway, if everything is fine, the `that` function returns an object which contains a property for each argument. Otherwise, it throws an error with an appropriate error message.\n\nAs the arguments are accessed using the `arguments` and `args` variables, you may skip specifying the arguments within the function's signature completely, as shown in the samples above. This also makes sure that you do not get linting errors such as [`no-unused-vars`](http://eslint.org/docs/rules/no-unused-vars.html).\n\n### Handling optional arguments\n\nIf you want to mark an argument as optional, surround its validators with brackets.\n\n```javascript\nvar args = ensure.that(arguments).are({\n  first: 'number',\n  second: [ 'number' ]\n});\n```\n\nFor each validator there is a default value which is used to initialize optional arguments. If you want to override this default value you can specify a default value manually.\n\n```javascript\nvar args = ensure.that(arguments).are({\n  first: 'number',\n  second: [ 'number', 23 ]\n});\n```\n\nYou can also have multiple optional arguments, but within a specific type optional arguments must always come last. Hence, the following sample is fine.\n\n```javascript\nvar args = ensure.that(arguments).are({\n  first: 'number',\n  second: [ 'number', 23 ],\n  third: [ 'number', 42 ],\n  fourth: 'string'\n});\n```\n\n### Using custom validators\n\nFrom time to time there are special requirements for validating arguments. For that you can create a custom validator by providing a function that returns an empty constructor function with a `name` property as well as an `isValid` and a `defaultValue` function attached to its prototype.\n\n```javascript\nvar customValidator = function () {\n  var Validator = function () {};\n\n  Validator.prototype.name = '...';\n\n  Validator.prototype.isValid = function (value) {\n    // ...\n    // Return true or false, depending on whether the value is valid.\n  };\n\n  Validator.prototype.defaultValue = function () {\n    // ...\n    // Return the default value in case this validator is being used\n    // for a missing optional argument without an explicitly given\n    // default value.\n  };\n\n  return Validator;\n};\n```\n\nNow you can use this custom validator by calling it instead of a built-in one when calling `that`.\n\n```javascript\nvar args = ensure.that(arguments).are({\n  first: ensure.number(),\n  second: customValidator()\n});\n```\n\n### Creating configurable validators\n\nIf you want to create a configurable custom validator, add arguments to the validator setup function, and provide them when using the validator.\n\n```javascript\nvar range = function (min, max) {\n  var Validator = function () {};\n\n  Validator.prototype.name = 'range';\n\n  Validator.prototype.isValid = function (value) {\n    return min <= value && value <= max;\n  };\n\n  Validator.prototype.defaultValue = function () {\n    return min;\n  };\n\n  return Validator;\n};\n\nvar args = ensure.that(arguments).are({\n  first: ensure.range(23, 42)\n});\n```\n\n## Running the build\n\nThis module can be built using [Grunt](http://gruntjs.com/). Besides running the tests, this also analyses the code. To run Grunt, go to the folder where you have installed node-ensurethat and run `grunt`. You need to have [grunt-cli](https://github.com/gruntjs/grunt-cli) installed.\n\n    $ grunt\n\n## License\n\nThe MIT License (MIT)\nCopyright (c) 2013-2014 the native web.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_attachments":{},"homepage":"https://github.com/thenativeweb/node-ensurethat","bugs":{"url":"https://github.com/thenativeweb/node-ensurethat/issues"},"license":"MIT"}