catchmeoutside
TypeScript icon, indicating that this package has built-in type declarations

1.0.19 • Public • Published

catchmeoutside

catchmeoutside is a utility library designed to simplify asynchronous error handling by capturing errors from asynchronous operations.

Installation

You can install catchmeoutside using npm:

npm install catchmeoutside
import { catchMeOutside, createFloat, Float } from 'catchmeoutside';

// Example asynchronous function
async function exampleAsyncFunction() {
  // Your asynchronous operation goes here
  return new Promise((resolve, reject) => {
    // Simulate an error
    // reject(new Error('Something went wrong'));

    // Simulate a successful operation
    resolve('Data fetched successfully');
  });
}

// Example usage of catchMeOutside
async function exampleUsage() {
  var {err, val} = await catchMeOutside(exampleAsyncFunction)

  if (err) {
    console.error('Error creating Float:', err);
  } else {
    console.log('Valid Float:', val);
  }
  
  var { err, val } = await catchMeOutside(async () => createFloat(34)); // throws error and error is stored in value err

  if (err) {
    console.error('Error creating Float:', err);
  } else {
    console.log('Valid Float:', val);
  }
}
exampleUsage();

API

asyncFunc: A function that returns a promise representing the asynchronous operation.

Returns an object with two properties:

err: The error object if the asynchronous operation fails, or null if successful.

val: The resolved value if the asynchronous operation is successful, or null if an error occurs.

Additional Types For stricter type checking, catchmeoutside provides the following interfaces:

Float: A type representing a floating-point number.

Int8: A type representing an 8-bit integer.

Int16: A type representing a 16-bit integer.

Int32: A type representing a 32-bit integer.

These types are designed to enhance type safety when working with numeric values.

License This project is licensed under the MIT License - see the LICENSE file for details.

Readme

Keywords

Package Sidebar

Install

npm i catchmeoutside

Weekly Downloads

15

Version

1.0.19

License

MIT

Unpacked Size

21.4 kB

Total Files

10

Last publish

Collaborators

  • segvalt