JSPM

stack-patcher

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q19354F
  • License MIT

Wraps calls in named function to have context in stacktrace

Package Exports

  • stack-patcher
  • stack-patcher/package.json

Readme

Stack Patcher

4KB package wraps any function in function with your custom name to help you catch bugs in error stacktraces

ExampleSource FileRepoWhy??? [RU]

  • Small. Weighs only 4KB;
  • Fast and Secure. Uses JS-native approach of renaming functions instead of eval;
  • Simple. You can just copy source to your project, i wan't be mad.
  • Cross-Platform. Works in node and browser

Example

import { wrapCall } from "stack-patcher";

const call = wrapCall("username=AlexXanderGrib", () => {
  throw new Error();
});

call.async()
  .catch((error) => console.log(error.stack));
// Error
//   at example.ts:4:4
//   at username=AlexXanderGrib
//      ^^^^^^^^^^^^^^^^^^^^^^^

Installation

  • Using npm
    npm i stack-patcher
  • Using Yarn
    yarn add stack-patcher
  • Using pnpm
    pnpm add stack-patcher

Import

  • CommonJS (default for Node JS)

    const { wrapCall } = require("stack-patcher");
  • TypeScript or ES Modules

    import { wrapCall } from "stack-patcher";