{"_id":"assert-err","_rev":"300436","name":"assert-err","description":"assertion library that throws user-specified error types (accepts error class and message)","dist-tags":{"latest":"1.1.0"},"maintainers":[{"name":"tjmehta","email":"tejesh.mehta@gmail.com"}],"time":{"modified":"2021-06-03T19:05:26.000Z","created":"2016-07-19T01:41:08.742Z","1.1.0":"2016-09-13T07:05:34.595Z","1.0.0":"2016-07-19T01:41:08.742Z"},"users":{},"author":{"name":"Tejesh Mehta"},"repository":{"type":"git","url":"git+https://github.com/tjmehta/assert-err.git"},"versions":{"1.1.0":{"name":"assert-err","version":"1.1.0","description":"assertion library that throws user-specified error types (accepts error class and message)","main":"index.js","scripts":{"test":"istanbul cover _mocha ./test && istanbul --text check-coverage --statements 100 --functions 100 --branches 100 --lines 100","test-watch":"nodemon -x mocha ./test"},"repository":{"type":"git","url":"git+https://github.com/tjmehta/assert-err.git"},"keywords":["assert","error","type","class","custom","user","constructor"],"author":{"name":"Tejesh Mehta"},"license":"MIT","bugs":{"url":"https://github.com/tjmehta/assert-err/issues"},"homepage":"https://github.com/tjmehta/assert-err","devDependencies":{"chai":"^3.5.0","istanbul":"^0.4.4","mocha":"^2.5.3","times-loop":"^1.0.0"},"dependencies":{"escape-string-regexp":"^1.0.5","object-assign":"^4.1.0"},"gitHead":"7bec3b550f0fc195a69d60e6586c25fd03df0ce4","_id":"assert-err@1.1.0","_shasum":"c05062799a1d97d3f5eaa258e3242aab499fc8ef","_from":".","_npmVersion":"3.10.7","_nodeVersion":"6.4.0","_npmUser":{"name":"tjmehta","email":"tejesh.mehta@gmail.com"},"dist":{"shasum":"c05062799a1d97d3f5eaa258e3242aab499fc8ef","size":3505,"noattachment":false,"key":"/assert-err/-/assert-err-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/assert-err/download/assert-err-1.1.0.tgz"},"maintainers":[{"name":"tjmehta","email":"tejesh.mehta@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/assert-err-1.1.0.tgz_1473750332587_0.8478570468723774"},"directories":{},"publish_time":1473750334595,"_cnpm_publish_time":1473750334595,"_hasShrinkwrap":false},"1.0.0":{"name":"assert-err","version":"1.0.0","description":"assertion library that throws user-specified error types (accepts error class and message)","main":"index.js","scripts":{"test":"istanbul cover _mocha ./test && istanbul --text check-coverage --statements 100 --functions 100 --branches 100 --lines 100","test-watch":"nodemon -x mocha ./test"},"repository":{"type":"git","url":"https://github.com/tjmehta/assert-err.git"},"keywords":["assert","error","type","class","custom","user","constructor"],"author":{"name":"Tejesh Mehta"},"license":"MIT","bugs":{"url":"https://github.com/tjmehta/assert-err/issues"},"homepage":"https://github.com/tjmehta/assert-err","devDependencies":{"chai":"^3.5.0","istanbul":"^0.4.4","mocha":"^2.5.3","times-loop":"^1.0.0"},"gitHead":"4d2ef2307d2fed6a50c6d43f30517778c2a855ae","_id":"assert-err@1.0.0","_shasum":"ca1108e24769d6f18d963c9db2db4f032e52a2d2","_from":".","_npmVersion":"3.3.12","_nodeVersion":"5.5.0","_npmUser":{"name":"tjmehta","email":"tejesh.mehta@gmail.com"},"dist":{"shasum":"ca1108e24769d6f18d963c9db2db4f032e52a2d2","size":3200,"noattachment":false,"key":"/assert-err/-/assert-err-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/assert-err/download/assert-err-1.0.0.tgz"},"maintainers":[{"name":"tjmehta","email":"tejesh.mehta@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/assert-err-1.0.0.tgz_1468892466591_0.2154168274719268"},"directories":{},"publish_time":1468892468742,"_cnpm_publish_time":1468892468742,"_hasShrinkwrap":false}},"readme":"# assert-err\nassertion library that throws user-specified error types (accepts error class and message)\n\n# Installation\n```bash\nnpm i --save assert-err\n```\n\n# Usage\n#### Example 1: full example\n```js\n// example-1.js\nvar assertErr = require('assert-err')\n\nfunction add (a, b) {\n  assertErr(typeof a === 'number', TypeError, '\"a\" must be a number')\n  assertErr(typeof b === 'number', TypeError, '\"b\" must be a number') //  line 6\n  return a + b\n}\n\nadd(1, 'no') // line 10\n/*\nTypeError: \"b\" must be a number\n    at add (example-1.js:6:3)\n    at Object.<anonymous> (example-1.js:10:1)\n    at Module._compile (module.js:413:34)\n    at Object.Module._extensions..js (module.js:422:10)\n    at Module.load (module.js:357:32)\n    at Function.Module._load (module.js:314:12)\n    at Function.Module.runMain (module.js:447:10)\n    at startup (node.js:139:18)\n    at node.js:999:3\n*/\n```\n#### Example 2: Error props\nIf using global.Error, assertErr accepts a `props` argument to extend `error`\n```js\nassertErr(false, Error, 'message', { code: 1, status: 'status' }) // 0 args\n// { [Error: boom] code: 1, status: 'status' }\n```\n#### Example 3: args\nassertErr supports up to 5 err constructor args\n```js\nassertErr(false, CustomError) // 0 args\nassertErr(false, CustomError, 'foo') // 1 args\nassertErr(false, CustomError, 'foo', 'bar') // 2 args\nassertErr(false, CustomError, 'foo', 'bar', 'qux') // 3 args\nassertErr(false, CustomError, 'foo', 'bar', 'qux', 'corge') // 4 args\nassertErr(false, CustomError, 'foo', 'bar', 'qux', 'corge', 'yolo') // 5 args\n// error...\nassertErr(false, CustomError, 'foo', 'bar', 'qux', 'corge', 'yolo', 'toomany') // 6 args\n// Error: assertErr does not support more than five Error args\n```\n\n# License\nMIT\n","_attachments":{},"homepage":"https://github.com/tjmehta/assert-err","bugs":{"url":"https://github.com/tjmehta/assert-err/issues"},"license":"MIT"}