Skip to content

stringparser/herro

Repository files navigation

herro

npm version npm downloads CI

Humanized stack traces for the Error class: show <module>@<version> instead of node_modules/<module>, and add a footer with cwd, node version, and ISO date.

Example:

Herror: something broke
    at Context.<anonymous> (./test/Herror.test.ts:9:17)
    at callFn (jest@29.7.0/lib/runnable.js:266:21)
    at Test.Runnable.run (jest@29.7.0/lib/runner.js:259:7)
...
--
cwd /Users/you/code/your-app
node-v20.10.0 2025-02-07T12:00:00.000Z
  • Replaces cwd with . and node_modules/<module> with <module>@<version>
  • Appends cwd, node version, and ISO date to the stack

Install

npm install herro

Requires Node.js ≥20.


API

Built in TypeScript; types are included.

Herror

Error subclass whose instances get humanized stack traces. Use with new only.

import { Herror } from 'herro';

throw new Herror('something broke');

global(flag?)

When flag is truthy or omitted, all stack traces (including plain Error) use the humanized format. When flag is false, restores the default format.

import { global } from 'herro';

global();       // enable humanized stacks globally
global(false);  // revert to default format

Utilities

  • npmize(stack: string): string – transform a stack string to <module>@<version> paths
  • formatStack(stack: string): string – npmize and append cwd / node version / date footer

Scripts

Command Description
npm run dist Build TypeScript to dist/
npm run lint Run ESLint
npm test Run Jest + verify-publish
npm run clean Remove verify-publish artifacts and *.tgz

License

The MIT License (MIT)

Copyright (c) 2017-present Javier Carrillo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

humanized stack traces for the error class

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •