{"_id":"precond","_rev":"435302","name":"precond","description":"Precondition checking utilities.","dist-tags":{"latest":"0.2.3"},"maintainers":[{"name":"mathieu","email":"turcotte.mat@gmail.com"}],"time":{"modified":"2021-08-05T06:10:50.000Z","created":"2012-11-15T01:33:15.122Z","0.2.3":"2014-06-21T13:37:39.556Z","0.2.2":"2013-06-15T14:53:50.913Z","0.2.1":"2013-05-26T16:45:32.480Z","0.2.0":"2013-05-26T15:00:02.377Z","0.1.1":"2012-11-16T03:46:33.767Z","0.1.0":"2012-11-15T01:33:15.122Z"},"users":{"muroc":true},"author":{"name":"Mathieu Turcotte","email":"turcotte.mat@gmail.com"},"repository":{"type":"git","url":"https://github.com/MathieuTurcotte/node-precond.git"},"versions":{"0.2.3":{"name":"precond","description":"Precondition checking utilities.","version":"0.2.3","author":{"name":"Mathieu Turcotte","email":"turcotte.mat@gmail.com"},"keywords":["precondition","assert","invariant","contract","condition"],"repository":{"type":"git","url":"https://github.com/MathieuTurcotte/node-precond.git"},"devDependencies":{"nodeunit":"0.9","jshint":"2.5"},"scripts":{"pretest":"node_modules/.bin/jshint lib/ examples/ index.js","test":"node_modules/.bin/nodeunit tests/"},"engines":{"node":">= 0.6"},"files":["index.js","lib"],"bugs":{"url":"https://github.com/MathieuTurcotte/node-precond/issues"},"_id":"precond@0.2.3","dist":{"shasum":"aa9591bcaa24923f1e0f4849d240f47efc1075ac","size":2538,"noattachment":false,"key":"/precond/-/precond-0.2.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/precond/download/precond-0.2.3.tgz"},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"mathieu","email":"turcotte.mat@gmail.com"},"maintainers":[{"name":"mathieu","email":"turcotte.mat@gmail.com"}],"directories":{},"publish_time":1403357859556,"_cnpm_publish_time":1403357859556,"_hasShrinkwrap":false},"0.2.2":{"name":"precond","description":"Precondition checking utilities.","version":"0.2.2","author":{"name":"Mathieu Turcotte","email":"turcotte.mat@gmail.com"},"keywords":["precondition","assert","invariant","contract","condition"],"repository":{"type":"git","url":"https://github.com/MathieuTurcotte/node-precond.git"},"devDependencies":{"nodeunit":"0.8","jshint":"2.1"},"scripts":{"pretest":"node_modules/.bin/jshint lib/ examples/ index.js","test":"node_modules/.bin/nodeunit tests/"},"engines":{"node":">= 0.6"},"readmeFilename":"README.md","_id":"precond@0.2.2","dist":{"shasum":"c6ce717f909e7dd0a08d515f9fb428041d6f992e","size":6029,"noattachment":false,"key":"/precond/-/precond-0.2.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/precond/download/precond-0.2.2.tgz"},"_from":".","_npmVersion":"1.2.14","_npmUser":{"name":"mathieu","email":"turcotte.mat@gmail.com"},"maintainers":[{"name":"mathieu","email":"turcotte.mat@gmail.com"}],"directories":{},"publish_time":1371308030913,"_cnpm_publish_time":1371308030913,"_hasShrinkwrap":false},"0.2.1":{"name":"precond","description":"Precondition checking utilities.","version":"0.2.1","author":{"name":"Mathieu Turcotte","email":"turcotte.mat@gmail.com"},"keywords":["precondition","assert","invariant","contract","condition"],"repository":{"type":"git","url":"https://github.com/MathieuTurcotte/node-precond.git"},"devDependencies":{"nodeunit":"0.8","jshint":"2.1"},"scripts":{"pretest":"node_modules/.bin/jshint lib/ examples/ index.js","test":"node_modules/.bin/nodeunit tests/"},"engines":{"node":">= 0.6"},"readmeFilename":"README.md","_id":"precond@0.2.1","dist":{"shasum":"214895838fb1a35d0a17f8523e758b43bb57ba55","size":5794,"noattachment":false,"key":"/precond/-/precond-0.2.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/precond/download/precond-0.2.1.tgz"},"_from":".","_npmVersion":"1.2.14","_npmUser":{"name":"mathieu","email":"turcotte.mat@gmail.com"},"maintainers":[{"name":"mathieu","email":"turcotte.mat@gmail.com"}],"directories":{},"publish_time":1369586732480,"_cnpm_publish_time":1369586732480,"_hasShrinkwrap":false},"0.2.0":{"name":"precond","description":"Precondition checking utilities.","version":"0.2.0","author":{"name":"Mathieu Turcotte","email":"turcotte.mat@gmail.com"},"keywords":["precondition","assert","invariant","contract","condition"],"repository":{"type":"git","url":"https://github.com/MathieuTurcotte/node-precond.git"},"devDependencies":{"nodeunit":"0.8","jshint":"2.1"},"scripts":{"pretest":"node_modules/.bin/jshint lib/ tests/ examples/ index.js","test":"node_modules/.bin/nodeunit tests/"},"engines":{"node":">= 0.6"},"readmeFilename":"README.md","_id":"precond@0.2.0","dist":{"shasum":"9c72fb8655611c87bd122f4cad60f43829b3e2b7","size":5584,"noattachment":false,"key":"/precond/-/precond-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/precond/download/precond-0.2.0.tgz"},"_from":".","_npmVersion":"1.2.14","_npmUser":{"name":"mathieu","email":"turcotte.mat@gmail.com"},"maintainers":[{"name":"mathieu","email":"turcotte.mat@gmail.com"}],"directories":{},"publish_time":1369580402377,"_cnpm_publish_time":1369580402377,"_hasShrinkwrap":false},"0.1.1":{"name":"precond","description":"Preconditions checking utilities.","version":"0.1.1","author":{"name":"Mathieu Turcotte","email":"turcotte.mat@gmail.com"},"keywords":["preconditions","asserts","invariants"],"repository":{"type":"git","url":"https://github.com/MathieuTurcotte/node-precond.git"},"devDependencies":{"nodeunit":"0.7","jshint":"0.9.0"},"scripts":{"pretest":"node_modules/jshint/bin/hint lib/ tests/ examples/ index.js","test":"node_modules/nodeunit/bin/nodeunit tests/"},"engines":{"node":">= 0.6"},"_id":"precond@0.1.1","dist":{"shasum":"6d44c7f8d3dc76bb43824bef494177771718b8e7","size":5341,"noattachment":false,"key":"/precond/-/precond-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/precond/download/precond-0.1.1.tgz"},"_npmVersion":"1.1.62","_npmUser":{"name":"mathieu","email":"turcotte.mat@gmail.com"},"maintainers":[{"name":"mathieu","email":"turcotte.mat@gmail.com"}],"directories":{},"publish_time":1353037593767,"_cnpm_publish_time":1353037593767,"_hasShrinkwrap":false},"0.1.0":{"name":"precond","description":"Preconditions checking utilities.","version":"0.1.0","author":{"name":"Mathieu Turcotte","email":"turcotte.mat@gmail.com"},"keywords":["preconditions","asserts","invariants"],"repository":{"type":"git","url":"https://github.com/MathieuTurcotte/node-precond.git"},"devDependencies":{"nodeunit":"0.7","jshint":"0.9.0"},"scripts":{"pretest":"node_modules/jshint/bin/hint lib/ tests/ examples/ index.js","test":"node_modules/nodeunit/bin/nodeunit tests/"},"engines":{"node":">= 0.6"},"_id":"precond@0.1.0","dist":{"shasum":"6c5fd283b3c6f46d342261686378f1fdac04cd3c","size":5309,"noattachment":false,"key":"/precond/-/precond-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/precond/download/precond-0.1.0.tgz"},"_npmVersion":"1.1.62","_npmUser":{"name":"mathieu","email":"turcotte.mat@gmail.com"},"maintainers":[{"name":"mathieu","email":"turcotte.mat@gmail.com"}],"directories":{},"publish_time":1352943195122,"_cnpm_publish_time":1352943195122,"_hasShrinkwrap":false}},"readme":"# Preconditions for Node.js\n[![Build Status](https://secure.travis-ci.org/MathieuTurcotte/node-precond.png?branch=master)](https://travis-ci.org/MathieuTurcotte/node-precond)\n[![NPM version](https://badge.fury.io/js/precond.png)](http://badge.fury.io/js/precond)\n\nPrecondition checks for Node.js inspired by [Guava's precondition checking\nutilities](https://code.google.com/p/guava-libraries/wiki/PreconditionsExplained).\n\n## Installation\n\n```\nnpm install precond\n```\n\n## Unit tests\n\n```\nnpm test\n```\n\n## Overview\n\nPrecond provides a set of functions to verify arguments and state correctness\n\nIt lets you rewrite constructs like the following\n\n```js\nif (!this.isConnected) {\n    throw new Error('Client should be connected before calling X.');\n}\n```\n\ninto a more compact and declarative check bellow.\n\n```js\nprecond.checkState(this.isConnected, 'Client should be ...');\n```\n\n**Note that even though the throw statement is wrapped in a function, the call\nstack will still start from the calling function. So the previous examples would\nboth produce the same stack trace.**\n\nAll arguments after the message will be used to format the actual error\nmessage that will be thrown.\n\nThe following precondition checks are provded:\n\n- checkArgument(value, [messageFormat, [formatArgs, ...]])\n- checkState(value, [messageFormat, [formatArgs, ...]])\n- checkIsDef(value, [messageFormat, [formatArgs, ...]]) -> value\n- checkIsDefAndNotNull(value, [messageFormat, [formatArgs, ...]]) -> value\n- checkIsString(value, [messageFormat, [formatArgs, ...]]) -> value\n- checkIsArray(value, [messageFormat, [formatArgs, ...]]) -> value\n- checkIsNumber(value, [messageFormat, [formatArgs, ...]]) -> value\n- checkIsBoolean(value, [messageFormat, [formatArgs, ...]]) -> value\n- checkIsFunction(value, [messageFormat, [formatArgs, ...]]) -> value\n- checkIsObject(value, [messageFormat, [formatArgs, ...]]) -> value\n\n## API\n\n### Static functions\n\n#### precond.checkArgument(value, [messageFormat, [formatArgs, ...]])\n\n- value: the value that is required to be truthy\n- messageFormat: error message format template\n- formatArgs: arguments to be substituted into the message template\n\nEnsures that value is true. Throws an `IllegalArgumentError` if value\nis false.\n\n#### precond.checkState(value, [messageFormat, [formatArgs, ...]])\n\n- value: the value that is required to be truthy\n- messageFormat: error message format template\n- formatArgs: arguments to be substituted into the message template\n\nEnsures that value is true. Throws an `IllegalStateError` if value\nis false.\n\n#### precond.checkIsDef(value, [messageFormat, [formatArgs, ...]])\n\n- value: the value that is required to be defined\n- messageFormat: error message format template\n- formatArgs: arguments to be substituted into the message template\n\nEnsures that value is defined (could be null). Throws an\n`IllegalArgumentError` if value is undefined. Returns the value of\nthe value that was validated.\n\n#### precond.checkIsDefAndNotNull(value, [messageFormat, [formatArgs, ...]])\n\n- value: the value that is required to be defined and not null\n- messageFormat: error message format template\n- formatArgs: arguments to be substituted into the message template\n\nEnsures that value is defined and not null. Throws an\n`IllegalArgumentError` if value is undefined or null. Returns the value of\nthe value that was validated.\n\n#### precond.checkIsString(value, [messageFormat, [formatArgs, ...]])\n\n- value: the value that is required to be a string\n- messageFormat: error message format template\n- formatArgs: arguments to be substituted into the message template\n\nEnsures that value is a string or a String object. Throws an\n`IllegalArgumentError` if value isn't a string. Returns the value of\nthe value that was validated.\n\n#### precond.checkIsArray(value, [messageFormat, [formatArgs, ...]])\n\n- value: the value that is required to be an array\n- messageFormat: error message format template\n- formatArgs: arguments to be substituted into the message template\n\nEnsures that value is an array. Throws an `IllegalArgumentError` if\nvalue isn't an array. Returns the value of the value that was\nvalidated.\n\n#### precond.checkIsNumber(value, [messageFormat, [formatArgs, ...]])\n\n- value: the value that is required to be a number\n- messageFormat: error message format template\n- formatArgs: arguments to be substituted into the message template\n\nEnsures that value is a number. Throws an `IllegalArgumentError` if\nvalue isn't a number. Returns the value of the value that was\nvalidated.\n\n#### precond.checkIsBoolean(value, [messageFormat, [formatArgs, ...]])\n\n- value: the value that is required to be a boolean\n- messageFormat: error message format template\n- formatArgs: arguments to be substituted into the message template\n\nEnsures that value is a boolean. Throws an `IllegalArgumentError` if\nvalue isn't a boolean. Returns the value of the value that was\nvalidated.\n\n#### precond.checkIsFunction(value, [messageFormat, [formatArgs, ...]])\n\n- value: the value that is required to be a function\n- messageFormat: error message format template\n- formatArgs: arguments to be substituted into the message template\n\nEnsures that value is a function. Throws an `IllegalArgumentError` if\nvalue isn't a function. Returns the value of the value that was\nvalidated.\n\n#### precond.checkIsObject(value, [messageFormat, [formatArgs, ...]])\n\n- value: the value that is required to be an object\n- messageFormat: error message format template\n- formatArgs: arguments to be substituted into the message template\n\nEnsures that value is an object. Throws an `IllegalArgumentError` if\nvalue isn't an object. Returns the value of the value that was\nvalidated.\n\n### Class precond.IllegalArgumentError\n\nExtends `Error` and is thrown to signal illegal arguments.\n\n### Class precond.IllegalStateError\n\nExtends `Error` and is thrown to signal that the program or object has reached\nan illegal state.\n\n## License\n\nThis code is free to use under the terms of the [MIT license](http://mturcotte.mit-license.org/).\n","_attachments":{},"bugs":{"url":"https://github.com/MathieuTurcotte/node-precond/issues"}}