1.0.0 • Published 7 months ago
@andreasnicolaou/safe v1.0.0
@andreasnicolaou/safe — Say Goodbye to Try-Catch Blocks!
Tired of writing try...catch everywhere?
Let @andreasnicolaou/safe handle it for you. This tiny, library automatically wraps your functions and promises in a safe execution environment.
Features
- Catch errors automatically (No more
try...catchspam!) - Works for both synchronous & asynchronous functions
- Customizable error logging
Installation
npm install @andreasnicolaou/safeBasic Usage
import { safe, isSuccess, isFailure } from '@andreasnicolaou/safe';
const [error, result] = safe(() => {
throw new Error('An error Occured!');
});
console.log(error); // An error Occured!
console.log(result); // undefined
console.log(isSuccess([error, result])); // false
console.log(isFailure([error, result])); // trueAdvanced Error Handling
const { safe, safeWithRetries } = createSafeUtils({
logger: (error) => sentry.captureException(error),
logErrors: process.env.NODE_ENV === 'production',
});Architecture Benefits
- Functional Programming Friendly
Compose operations without error handling noise - TypeScript Optimized
Full type inference and guards - Framework Agnostic
Works with React, Node.js, Deno, etc.
Related
Contributing
Contributions are welcome! If you encounter issues or have ideas to enhance the library, feel free to submit an issue or pull request.
1.0.0
7 months ago