{"_id":"throw-expression","_rev":"6-ed351ca101602fdb3b2e80e84cff1b4b","name":"throw-expression","dist-tags":{"latest":"2.1.0"},"versions":{"1.0.0":{"name":"throw-expression","version":"1.0.0","description":"Allows you, through a simple function, to throw an error inside an expression","main":"index.js","repository":{"type":"git","url":"https://github.com/jindra12/throw-expression.git"},"author":{"name":"Jan Jindráček"},"license":"MIT","man":["./README.md"],"keywords":["throw","expression","throw expression","no dependency","typescript","utility","error","proposal"],"dependencies":{},"devDependencies":{},"_id":"throw-expression@1.0.0","dist":{"shasum":"3fa835639df2495728f3978eb2ac43a1f27c6049","integrity":"sha512-2vIaWQwD8/BtedIVY/1cegBUhH7x3VGbee0TGolayBJq2ObAAPwYhvTOzeDUbgmSzleQleTvRmQwAvZm6I2s+A==","tarball":"https://registry.npmjs.org/throw-expression/-/throw-expression-1.0.0.tgz","fileCount":5,"unpackedSize":4857,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfZnpSCRA9TVsSAnZWagAATRwP/RkQXsqeAuGqT/jFQg1C\nQlDzGqQVPsSUrVvbpIHW0p1yRR88JrH4ajSQgtqEOftxDn6QhQZ8/nFUC1ne\nyaeR4RPxqKzUng2ckPPj3b/8EOlHEQLFdsBpkrhTajZzYObUCuZwlWdsXCbg\n2MOjvu6B1wJ7/11V7YjZa5l5B7jU5SRMg3Xcof4wWmOYV8FMPvZe2WF0dgmb\nnarsFlOEhpL2VpLAcxZva4SYSsY/rjKa0ZjbgbamgG/xeumXYYxRFAipzZ/h\nytkIO+ptCmaBZ/wzYSlle8RDOnaVQy0Mp8btBfUTXrJBb2d6VovMgj4K9dDV\n5QnMW+1tRS5LJ+hszrxkG7vtS7LFn7Q5ombPACXqUptue4Nsrpvz79vw1R7g\nM5FeJ+Mw6boU1bb5RasYicjPEViHp3qgOyOdSIEnbeNvezSV24NjVtXoYE8N\nGwc+RgIXMJcOnPPINuU7RiZzpfxBkFXSZwmUm4KysJCggRBlLDwZN/lPDFV6\neAJT2bw2hVRkx7fQ2VHPrJ46mvNEEPysNL+NGOpDurey50yuKJyT/71hkj3R\nuWS4MTmdaF51A78ffaN5W8GEkAp++OAabWPFUygUm5G9Bf2+xA0YZcs0O3+Q\nqwT+IZlPWqJVnUZVl7uRrvcsyNDm412q+b0pVNueyRQvFK7yuwJlWDM4V3mA\n4hMl\r\n=A5rL\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC8N5GPCapylI9EAExDZEH9+KOohwTbDOw5JkKF98o5WAIhAKDQnthGlq1S4r+/ZBg4qbzS5OT8VEVsb07ZHPWGJnYK"}]},"maintainers":[{"name":"jindra12","email":"jindra12.underdark@gmail.com"}],"_npmUser":{"name":"jindra12","email":"jindra12.underdark@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/throw-expression_1.0.0_1600551506185_0.8260255306011022"},"_hasShrinkwrap":false},"1.0.1":{"name":"throw-expression","version":"1.0.1","description":"Allows you, through a simple function, to throw an error inside an expression","main":"index.js","repository":{"type":"git","url":"https://github.com/jindra12/throw-expression.git"},"author":{"name":"Jan Jindráček"},"license":"MIT","man":["./README.md"],"keywords":["throw","expression","throw expression","no dependency","typescript","utility","error","proposal"],"dependencies":{},"devDependencies":{},"_id":"throw-expression@1.0.1","dist":{"shasum":"f58cdb9fe004c1fb63fbba598a8996cfdf93806d","integrity":"sha512-SrqrYxk76188AcdDKd/5GE9YD5ODWw3KJPxSJj+VvzAhZejpG+oBTUT6WKTBpm+0uh04cvPDEU1YJCsus6dnpw==","tarball":"https://registry.npmjs.org/throw-expression/-/throw-expression-1.0.1.tgz","fileCount":5,"unpackedSize":4862,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfZnrdCRA9TVsSAnZWagAAoRQP/3yUpwHGsVxa+8MRDUBr\neT7/GFon7+Aa5vO3246Da2NPdFdjwc2Agj5H29gBCiOXxEmZUm975ECoYC9T\nxJ1ayzch4HyzjO5ffrVL7tGp+ovHcgmbAbWwDgRowuViZk8rCTk1pfhmzL8X\nnFOBGS5tm3Hv/9aeZBy7jDhkqOgPSWs/VbJ1nnT2BowXXOer6Aspzog5bPuE\nKNbQkvW0c3WHOojkvSAljaVbYDqn9HeC5BaxQJYxVumtk5O8zBs7xoyeOzeL\n3ngAXmgmGAtuuvow+5UiTNHP1/knqpRcxLdnmdSXaLH6yV3StxzELg6tKd/m\nCu3ClInB5nJItlcnfwnyCjcnuceBqriGctOu5eW4WdIToCslgOKPlQ0Tt3Qf\nzTrrquWaperDIV+DarkllhsoXuyZEvDykksGQLXBOCC4wtrhhgoPbON3LSLl\npqhbNwIBfkyCj2ID2Jpv+VBo2bWIIlow6sHX3Wt/O8GaCxb9lhIIZPpGza+L\nlo2wU9hsZVdH5YV91+gYhEudgIBn3z3KCtr6rQNJq4j982E4EGWc7lSiCfyR\ncR8GbYygDuudyBpd6CkvOYgSNoDU0rugS5VELKW3JXVevDOqYjD1lBtgiMT7\nBG++mEAyrRIfsDVzem1ZklHOtzDkh1q5admpB4msWVzhe/9eisMfec1sYp7Q\ntJH3\r\n=yae7\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFyhTks4mRzX3FgMz0aG7CNpER5XuMWuvb2X6lkdAhwDAiA8Pe31/OzqN758IpC2N/OGxghhF8sL5j3FzsxVTmKSVA=="}]},"maintainers":[{"name":"jindra12","email":"jindra12.underdark@gmail.com"}],"_npmUser":{"name":"jindra12","email":"jindra12.underdark@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/throw-expression_1.0.1_1600551645251_0.8413250958175855"},"_hasShrinkwrap":false},"1.0.2":{"name":"throw-expression","version":"1.0.2","description":"Allows you, through a simple function, to throw an error inside an expression","main":"index.js","repository":{"type":"git","url":"https://github.com/jindra12/throw-expression.git"},"author":{"name":"Jan Jindráček"},"license":"MIT","man":["./README.md"],"keywords":["throw","expression","throw expression","no dependency","typescript","utility","error","proposal"],"dependencies":{},"devDependencies":{},"_id":"throw-expression@1.0.2","dist":{"shasum":"8fbfa98525ba603492d4683034200f2745845910","integrity":"sha512-y8cHYZgp0Vj8bRMQSWAA7pfHj1JPift81tZM9i/rHQuJoYEv9kewjEpRu2wRRuXRaClFWWzWQFTG3Q9rDysyNQ==","tarball":"https://registry.npmjs.org/throw-expression/-/throw-expression-1.0.2.tgz","fileCount":5,"unpackedSize":5930,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfZyaaCRA9TVsSAnZWagAAtqQP/iVXlIeHs4biXlJyTFdD\n/ju4PFB6ky2c9akmBdLFmDe70nGA0rW7blsnifjknXjVh0hYqhQXukhYF8Zn\nvGo473evOrtAjmuLC9VfzHmTGENyyBFQJqnhjPhLM9na3QL+kNsppiazm215\ncID1I4a1gRw8/n4MIKSGb2dPK6yFWB9TdDIe7OnQgP8/2tbJb9CX7aYbB7YZ\nDfkBwwmn4B1N7HZpzvQCd5qlkwTEDMr/DVbo4jJtcsufiAJ60xNgqKHQINwG\nyF+9q3XSkHCmMigCCpFRZXcCwu2QO8wuQDtcyDWCMNFcTmJ/wfrxgwls8H1e\n0BSUcoRGrIiT7TNW/J3mybCTtn/C9fIpkwmdmXN5XAD87Nt/ltZgFaVmhtf/\nX6SGRFt4Npu8BTDIxd4rlQEssHXoTPdKTnVZDxCLdHozfO1hm3vp1CXh9mwJ\nT6SUmiwG7YEBIaBY2+QSCb+1U++uGP3Ry+MtutHEMO29xRB1e1RUpbyWDdmm\nSz7lhc7AEjYbbz2RlZyxfat5DOkxk8dh3YF8GzgUUubJYBW/KtzOD0is512X\nX0wsDnOqOwlov2UADLXeVWfMzheqMgbViCqYaV/R9YAATnUtQor5cdh0WvnN\nQrPT/8rAvBhC0DBUOguja9dPOV/lOcWA4Q9qNmLNkUzfwSXHMaMpjjkOK3vo\nIUP7\r\n=Q2yo\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCe11LIsn2AHwkqpcSrxo0cr0+HfqGgip9xJmfRKVlZtgIhAI0AkpJhDD9IRBQGvdAjMKLHwlwcf2531yWmjkL74lXM"}]},"maintainers":[{"name":"jindra12","email":"jindra12.underdark@gmail.com"}],"_npmUser":{"name":"jindra12","email":"jindra12.underdark@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/throw-expression_1.0.2_1600595609924_0.8804229058311681"},"_hasShrinkwrap":false},"2.0.0":{"name":"throw-expression","version":"2.0.0","description":"Allows you, through a simple function, to throw an error inside an expression","main":"index.js","repository":{"type":"git","url":"git+https://github.com/jindra12/throw-expression.git"},"author":{"name":"Jan Jindráček"},"license":"MIT","man":["./README.md"],"keywords":["throw","expression","throw expression","no dependency","typescript","utility","error","proposal"],"dependencies":{},"devDependencies":{},"types":"./index.d.ts","gitHead":"94555d56375614949d8084669efb00c7e4858560","bugs":{"url":"https://github.com/jindra12/throw-expression/issues"},"homepage":"https://github.com/jindra12/throw-expression#readme","_id":"throw-expression@2.0.0","_nodeVersion":"18.12.1","_npmVersion":"8.19.2","dist":{"integrity":"sha512-rRkgmF+6yD1YJSkjzAw4AY0Onhfq31XVXmi//vuUPf/V2rke5dXWVnKzMu51oLnyR9k4qg9Xuo+7uvgrgbye5Q==","shasum":"563a076dda0d89ff54021896752d10819b5a9267","tarball":"https://registry.npmjs.org/throw-expression/-/throw-expression-2.0.0.tgz","fileCount":4,"unpackedSize":7382,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDMAIbfeTrEozLnAZEh8+dd9lV2bIqXqxyvsTeMSS9c2AiBg3X4W310NMCvQcZujKCyMVsO095pivn8S2hfztMnwVg=="}]},"_npmUser":{"name":"jindra12","email":"jindra12.underdark@gmail.com"},"directories":{},"maintainers":[{"name":"jindra12","email":"jindra12.underdark@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/throw-expression_2.0.0_1696696195210_0.4463009347958511"},"_hasShrinkwrap":false},"2.0.1":{"name":"throw-expression","version":"2.0.1","description":"Allows you, through a simple function, to throw an error inside an expression","main":"index.js","repository":{"type":"git","url":"git+https://github.com/jindra12/throw-expression.git"},"author":{"name":"Jan Jindráček"},"license":"MIT","man":["./README.md"],"keywords":["throw","expression","throw expression","no dependency","typescript","utility","error","proposal"],"dependencies":{},"devDependencies":{},"types":"./index.d.ts","gitHead":"94555d56375614949d8084669efb00c7e4858560","bugs":{"url":"https://github.com/jindra12/throw-expression/issues"},"homepage":"https://github.com/jindra12/throw-expression#readme","_id":"throw-expression@2.0.1","_nodeVersion":"18.12.1","_npmVersion":"8.19.2","dist":{"integrity":"sha512-Nw3bc1B3V72iRMt9K/w9RS+KccIcTUt9u9snaO3lngYRM+D6HtefBrrDz1JdoQTEJfVBw5s9LmGfOS5dPo1ffg==","shasum":"163b2337b4bfc07ce6b5e72429dc89815f70c8b3","tarball":"https://registry.npmjs.org/throw-expression/-/throw-expression-2.0.1.tgz","fileCount":4,"unpackedSize":7619,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFnnPXheoC3xSFygr9dpEdaLdtVF02iQQHNxobze3zcRAiBs3E0YqTaEuapuA9Jku3ZMiA0rWLV8jJpaO6X6ikXCgg=="}]},"_npmUser":{"name":"jindra12","email":"jindra12.underdark@gmail.com"},"directories":{},"maintainers":[{"name":"jindra12","email":"jindra12.underdark@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/throw-expression_2.0.1_1696696260343_0.49982529412412324"},"_hasShrinkwrap":false},"2.1.0":{"name":"throw-expression","version":"2.1.0","description":"Allows you, through a simple function, to throw an error inside an expression","main":"index.js","repository":{"type":"git","url":"https://github.com/jindra12/throw-expression.git"},"author":{"name":"Jan Jindráček"},"license":"MIT","man":["./README.md"],"keywords":["throw","expression","throw expression","no dependency","typescript","utility","error","proposal"],"dependencies":{},"devDependencies":{},"_id":"throw-expression@2.1.0","dist":{"shasum":"3f90b089181e9359c6fb868d913457bc816160bd","integrity":"sha512-ZVP9rT4wC596AkWEyYprufvUV+ppfz0xK7H9Ka3WeTKufn5pnfESxicIDnaJyf88pGHaIx2GkwNC4Qjh0OdEwA==","tarball":"https://registry.npmjs.org/throw-expression/-/throw-expression-2.1.0.tgz","fileCount":5,"unpackedSize":7988,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAUvdp7clWBIsbFdPzzLBwhQXq2tQ7ujW4J652J5tZFyAiEAgSZn3G4GPabg+38FE4aRViv6pwpX3A9bMRMkxG9LY7w="}]},"_npmUser":{"name":"jindra12","email":"jindra12.underdark@gmail.com"},"directories":{},"maintainers":[{"name":"jindra12","email":"jindra12.underdark@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/throw-expression_2.1.0_1707349308731_0.015308894327188627"},"_hasShrinkwrap":false}},"time":{"created":"2020-09-19T21:38:26.184Z","1.0.0":"2020-09-19T21:38:26.307Z","modified":"2024-02-07T23:41:49.088Z","1.0.1":"2020-09-19T21:40:45.362Z","1.0.2":"2020-09-20T09:53:30.048Z","2.0.0":"2023-10-07T16:29:55.437Z","2.0.1":"2023-10-07T16:31:00.485Z","2.1.0":"2024-02-07T23:41:48.878Z"},"maintainers":[{"name":"jindra12","email":"jindra12.underdark@gmail.com"}],"description":"Allows you, through a simple function, to throw an error inside an expression","keywords":["throw","expression","throw expression","no dependency","typescript","utility","error","proposal"],"repository":{"type":"git","url":"https://github.com/jindra12/throw-expression.git"},"author":{"name":"Jan Jindráček"},"license":"MIT","readme":"# throw-expression\n\nThis package emulates proposed functionality with inline throwable expression.\n\n## Before:\n\n```typescript\n\nconst length = (value: string) => {\n    if (value === undefined || value === null) {\n        throw new Error('falsy value entered!');\n    }\n    return value.length;\n}\n\n```\n\n## After:\n\n```typescript\n\nconst length = (value: string) => throwIfFalsy(value, 'falsy value entered!').length; // will not throw on empty string, zero etc.\n\n// Or:\n\nconst length = (value: string) => (value || Throw('falsy value entered!')).length; // will throw on any falsy value\n\n```\n\nThe function is named 'Throw' to avoid javascript keyword. Along with this function, several other simple utility functions are exported.\nTyping on these utilities should help you avoid most of the nonsensical TS messages about nullable properties.\n\n## Examples from unit tests\n\n```typescript\n\ndescribe(\"Can use throwable expressions to throw when necessary\", () => {\n    test(\"Can simply throw\", () => {\n        expect(() => Throw('Write your exception message here')).toThrow('Write your exception message here');\n        expect(() => Throw(Error('Write your exception message here'))).toThrow('Write your exception message here');        \n    });\n    test(\"Can throw conditionally\", () => {\n        let value: string | null = null;\n        expect(() => value || Throw('is null')).toThrow('is null');\n        value = 'anything else';\n        expect(value || Throw('is null')).toBe('anything else');\n    });\n    test(\"Can check for null with throwable\", () => {\n        expect(() => throwIfNull(null, 'is null')).toThrow('is null');\n        expect(throwIfNull(undefined, 'is null')).toBe(undefined);\n        expect(throwIfNull(false, 'is null')).toBe(false);\n    });\n    test(\"Can check for undefined with throwable\", () => {\n        expect(throwIfUndefined(null, 'is undefined')).toBe(null);\n        expect(() => throwIfUndefined(undefined, 'is undefined')).toThrow('is undefined');\n        expect(throwIfUndefined(false, 'is undefined')).toBe(false);\n    });\n    test(\"Can check for falsy with throwable\", () => {\n        expect(() => throwIfFalsy(null, 'is falsy')).toThrow('is falsy');\n        expect(() => throwIfFalsy(undefined, 'is falsy')).toThrow('is falsy');\n        expect(() => throwIfFalsy(\"\", 'is falsy')).toThrow('is falsy');\n        expect(() => throwIfFalsy(0, 'is falsy')).toThrow('is falsy');\n        expect(() => throwIfFalsy(NaN, 'is falsy')).toThrow('is falsy');\n        expect(() => throwIfFalsy(false, 'is falsy')).toThrow('is falsy');\n        expect(throwIfFalsy(\"is truthy\", 'is falsy').length).toBe(9);\n    });\n    test(\"Can check for nullish with throwable\", () => {\n        expect(() => throwIfNullish(null, 'is nullish')).toThrow('is nullish');\n        expect(() => throwIfNullish(undefined, 'is nullish')).toThrow('is nullish');\n        expect(throwIfNullish(\"\", 'is nullish')).toBe(\"\");\n        expect(throwIfNullish(false, 'is nullish')).toBe(false);\n    });\n    test(\"Can check for NaN with throwable\", () => {\n        expect(() => throwIfNotANumber(NaN, 'is NaN')).toThrow('is NaN');\n        expect(() => throwIfNotANumber({}, 'is NaN')).toThrow('is NaN');\n        expect(throwIfNotANumber(0, 'is NaN')).toBe(0);\n        expect(throwIfNotANumber(2, 'is NaN')).toBe(2);\n    });\n});\n\n```\n\n## Footer\n\nIf you encounter any bugs, or have ideas for improvement, do not hesitate to add a task or a pull request.\n","readmeFilename":"README.md"}