{"_id":"if-else-throw","_rev":"5-27f6fc34185d22d580baea62746595be","name":"if-else-throw","description":"If X, return Y, else throw Z.","dist-tags":{"latest":"2.0.0"},"versions":{"1.0.0":{"name":"if-else-throw","version":"1.0.0","description":"If X, return Y, else throw Z.","keywords":["error","throw","test","check","passthrough"],"author":{"name":"John Lamansky"},"license":"MIT","homepage":"https://github.com/lamansky/if-else-throw","repository":{"type":"git","url":"git+https://github.com/lamansky/if-else-throw.git"},"main":"index.js","files":[],"engines":{"node":">=5.0.0"},"dependencies":{"possible-function":"^1.0.1"},"devDependencies":{"eslint-config-lamansky":"^1.0.0","mocha":"^3.2.0"},"scripts":{"test":"mocha"},"eslintConfig":{"extends":"lamansky","env":{"mocha":true}},"gitHead":"c0586d403d6cb24ac16dc66f9ae78ec1f194bb78","bugs":{"url":"https://github.com/lamansky/if-else-throw/issues"},"_id":"if-else-throw@1.0.0","_shasum":"c0bebda2b6db65a73334862641d53692f6c6c8fa","_from":".","_npmVersion":"4.2.0","_nodeVersion":"7.10.0","_npmUser":{"name":"lamansky","email":"johnlamansky@gmail.com"},"dist":{"shasum":"c0bebda2b6db65a73334862641d53692f6c6c8fa","tarball":"https://registry.npmjs.org/if-else-throw/-/if-else-throw-1.0.0.tgz","integrity":"sha512-LzTMNkDgHdayblt+7hXKcY0TSk6G5+8kQjOHZyvH/d0zzUuPptgaPAQbucd1ZQqUfOLv9VdlfLrnjJcTsklIlA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCmtC86sMYMp2Qelc2NpJGw5LUFgHxk2sg7/1CWn1518wIhANMt5chModHr6XOpJmP6Bxe9x+l7nhrWwV0GPeBD8Jzm"}]},"maintainers":[{"name":"lamansky","email":"johnlamansky@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/if-else-throw-1.0.0.tgz_1511878240655_0.48726496170274913"},"directories":{}},"2.0.0":{"name":"if-else-throw","version":"2.0.0","description":"If X, return Y, else throw Z.","keywords":["error","throw","test","check","passthrough"],"author":{"name":"John Lamansky"},"license":"MIT","homepage":"https://github.com/lamansky/if-else-throw","repository":{"type":"git","url":"git+https://github.com/lamansky/if-else-throw.git"},"main":"index.js","files":[],"engines":{"node":">=6.0.0"},"dependencies":{"errate":"^1.0.0","ofn":"^1.0.0","pfn":"^1.0.0"},"devDependencies":{"eslint-config-lamansky":"^1.0.0","mocha":"^5.0.5"},"scripts":{"test":"mocha"},"eslintConfig":{"extends":"lamansky","env":{"mocha":true}},"gitHead":"3c325e8af14c35be306fa0f15a0df7fedd2f6a6c","bugs":{"url":"https://github.com/lamansky/if-else-throw/issues"},"_id":"if-else-throw@2.0.0","_npmVersion":"5.5.1","_nodeVersion":"9.2.1","_npmUser":{"name":"lamansky","email":"johnlamansky@gmail.com"},"dist":{"integrity":"sha512-MrsbDb4GG+gVUE2LfR6wwOSvlcqXOW12W7tiu5rDBIMtA4BZ5WZsG84fFCZ+Vgg0dakN8apTdykrMzZjCNSiRg==","shasum":"19343f8b756575b2e2572bfc4751b95b85543b21","tarball":"https://registry.npmjs.org/if-else-throw/-/if-else-throw-2.0.0.tgz","fileCount":4,"unpackedSize":3670,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD8hLrGV7mD1Sp+F+dQ5jWmD6FIxFVtfaxI2ajTSOMpVQIgZY+oFJKrtdqQO9BzYpZcO5f1N/Ba2t3r37ZsNYY9Jic="}]},"maintainers":[{"name":"lamansky","email":"johnlamansky@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/if-else-throw_2.0.0_1523426756102_0.5900456333981607"},"_hasShrinkwrap":false}},"readme":"# if-else-throw\n\nIf X, return Y, else throw Z.\n\nX can be a boolean or a function.\n\n## Installation\n\nRequires [Node.js](https://nodejs.org/) 6.0.0 or above.\n\n```bash\nnpm i if-else-throw\n```\n\n## API\n\nThe module exports a single function.\n\n### Parameters\n\n1. `test` (any): The “if” condition, evaluated for truthiness. If a function is provided, it is called with `val` as its only argument and its return value is used.\n2. Optional: `val` (any): The “then” value to return if `test` is truthy. If omitted, `test` is returned.\n3. Optional: `error` (Error or string): The Error to throw if `test` is falsely. If a string is provided, it is wrapped in a `new Error`. If omitted, defaults to `new Error()`.\n\n### Return Value\n\nIf `test` is truthy, returns `val` (or returns `test` if `val` is omitted). If `test` is falsey, there is no return value because an error is thrown.\n\n## Examples\n\n```javascript\nconst ifElseThrow = require('if-else-throw')\n\nconst value = []\nifElseThrow(\n  Array.isArray(value), // The boolean condition (in this case, true)\n  value, // The value returned if true\n  new TypeError('Not an array') // The error thrown if false\n) // []\n\nifElseThrow(\n  x => Array.isArray(x), // x will be the second argument ('this is a string')\n  'this is a string', // Given to the function and returned if the function returns true\n  new TypeError('Not an array') // The error thrown if false\n) // Uncaught TypeError: Not an array\n\nifElseThrow(\n  'this is truthy',\n  'Must be truthy'\n) // 'this is truthy'\n\nifElseThrow(\n  null,\n  'Must be truthy'\n) // Uncaught Error: Must be truthy\n```\n","maintainers":[{"name":"lamansky","email":"johnlamansky@gmail.com"}],"time":{"modified":"2022-06-19T00:15:06.459Z","created":"2017-11-28T14:10:41.746Z","1.0.0":"2017-11-28T14:10:41.746Z","2.0.0":"2018-04-11T06:05:56.151Z"},"homepage":"https://github.com/lamansky/if-else-throw","keywords":["error","throw","test","check","passthrough"],"repository":{"type":"git","url":"git+https://github.com/lamansky/if-else-throw.git"},"author":{"name":"John Lamansky"},"bugs":{"url":"https://github.com/lamansky/if-else-throw/issues"},"license":"MIT","readmeFilename":"readme.md"}