1.0.0 • Published 5 months ago
check-for-errors v1.0.0
check-for-errors
A utility function to handle errors in synchronous and asynchronous functions.
Installation
npm install check-for-errors
Usage
import { checkForErrors } from 'check-for-errors';
// Example with synchronous function
const [syncResult, syncError] = checkForErrors(() => {
return someSyncFunction();
});
if (syncError) {
console.error(syncError);
} else {
console.log(syncResult);
}
// Example with asynchronous function
const [asyncResult, asyncError] = await checkForErrors(async () => {
return await someAsyncFunction();
});
if (asyncError) {
console.error(asyncError);
} else {
console.log(asyncResult);
}
License
This project is licensed under the MIT License.
1.0.0
5 months ago