npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@monitext/nstack

v0.1.0

Published

nstack is minimal utilitie to read the error stack

Readme

nstack

The missing toolkit for parsing, normalizing, and manipulating JavaScript stack traces across all runtimes.

nstack provides utilities to read error stacks, extract method and file information, perform adaptive lookups, and normalize stack traces in Node.js, browsers, Deno, or Bun.


Features

  • Parse raw error stacks into structured StackFrame objects.
  • Extract method names, file paths, line numbers, and columns from stack traces.
  • Lookup methods in stacks with optional offsets and predicates.
  • Adaptive lookups based on the current runtime.
  • Provides both raw TypeScript and bundled JS versions (lib.js, lib.min.js, lib.full.js).
  • Compatible with ESM, CJS, and TypeScript projects.

Installation

npm install "@monitext/nstack"

or using yarn:

yarn add "@monitext/nstack"

Basic Usage

import nstack, { lookUp, adaptiveLookUp, StackUtils, StackLine } from "@monitext/nstack";

try {
    // Some code that throws
    throw new Error("Oops!");
} catch (err) {
    // Parse stack
    const stack = StackUtils.processError(err);
    
    // Find a method in the stack
    const result = lookUp({ err, method: /myFunction/, offset: 0 });
    
    console.log(result);
    
    // Adaptive lookup across runtime
    const adaptive = adaptiveLookUp([
        { mode: "method", err, method: /myFunction/, offset: 0, runtime: "node" },
        { mode: "index", err, index: 1, runtime: "browser" }
    ]);
    
    console.log(adaptive);
}

API

StackLine

Represents a single line/frame in a stack trace.

const line = new StackLine("at myFunction (file.ts:10:5)");
console.log(line.method); // "myFunction"
console.log(line.file);   // "file.ts"
console.log(line.line);   // 10
console.log(line.column); // 5

StackUtils

Utilities for processing stacks.

  • StackUtils.processError(error: Error): StackTrace | null Converts an error’s stack into an array of StackLine.

  • StackUtils.findMethodInStack(param: StackReadParameter): StackResult | null Finds a method in a stack trace with an optional offset.


lookUp

lookUp({ err: Error, method: string | RegExp, offset: number }): StackResult | null

Search for a method in a stack trace. Returns [index, StackLine] or null.


adaptiveLookUp

adaptiveLookUp(lookups: AdaptiveLookUp): StackResult | null

Iterates over multiple lookups, detects the current runtime, and returns the first successful match.

Supports optional predicates to validate results before returning.


Types

  • StackFrame – Single stack frame (instance of StackLine).
  • StackTrace – Array of StackFrame.
  • StackResult[index: number, StackFrame].
  • LookUpParameter, StackReadParameter – Parameters for lookups.
  • LookUp, AdaptiveLookUp – Lookup configurations.

Supported Runtimes

  • Node.js
  • Browser
  • Deno
  • Bun

adaptiveLookUp automatically selects the proper runtime.


Bundles

  • TypeScript: dist/src (raw .ts)
  • JS Bundles: dist/src-js

| File | Description | | ------------- | --------------------------------- | | lib.js | Standard ESM bundle | | lib.full.js | Full bundle with all dependencies | | lib-min.js | Minified production bundle |


License

Apache 2.0