![Black Lives Matter!][badge-blm] ![Maintenance status][badge-maintenance] ![Last commit timestamp][badge-last-commit] ![Open issues][badge-issues] ![Pull requests][badge-pulls] ![codecov][badge-codecov] ![Source license][badge-license] ![NPM version][badge-npm] ![semantic-release][badge-semantic-release]
toss-expression
While
Babel supports throw expressions via plugins,
TypeScript and VS Code do not (yet).
Hence this five line ponyfill takes the place of the currently-unavailable
@babel/plugin-proposal-throw-expressions
syntax.
// Though the following is supported by Babel, VS Code/TypeScript will complain
const userToken = secureRequest() || throw new SecureAccessError('badness occurred');
// No errors
const userToken = secureRequest() || toss(new SecureAccessError('badness occurred'));
Installation and Usage
npm install toss-expression
// ESM
import { toss } from 'toss-expression';
console.log(successMessage() || toss('log operation failed'));
// CJS
const { toss } = require('toss-expression');
console.log(successMessage() || toss('log operation failed'));
Documentation
Further documentation can be found under docs/
.
Contributing and Support
[New issues][choose-new-issue] and pull requests are always welcome and greatly appreciated! 🤩 Just as well, you can star 🌟 this project to let me know you found it useful! ✊🏿 Thank you!
See CONTRIBUTING.md and SUPPORT.md for more information.
[badge-blm]: https://xunn.at/badge-blm 'Join the movement!'
[badge-maintenance]: https://img.shields.io/maintenance/active/2023 'Is this package maintained?'
[badge-last-commit]: https://img.shields.io/github/last-commit/xunnamius/toss-expression 'When was the last commit to the official repo?' [badge-issues]: https://isitmaintained.com/badge/open/Xunnamius/toss-expression.svg 'Number of known issues with this package'
[badge-pulls]: https://img.shields.io/github/issues-pr/xunnamius/toss-expression 'Number of open pull requests'
[badge-codecov]: https://codecov.io/gh/Xunnamius/toss-expression/branch/main/graph/badge.svg?token=HWRIOBAAPW 'Is this package well-tested?'
[badge-license]: https://img.shields.io/npm/l/toss-expression "This package's source license"
[badge-npm]: https://api.ergodark.com/badges/npm-pkg-version/toss-expression 'Install this package using npm or yarn!'
[badge-semantic-release]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg 'This repo practices continuous integration and deployment!'
[choose-new-issue]: https://github.com/Xunnamius/toss-expression/issues/new/choose