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

@thelinuxlich/csc

v1.0.1

Published

A TypeScript utility library for capturing detailed call site information with source map support. This library provides accurate stack trace information, making it invaluable for debugging, logging, and error reporting in TypeScript/JavaScript applicatio

Readme

CSC (Call Site Capture)

A TypeScript utility library for capturing detailed call site information with source map support. This library provides accurate stack trace information, making it invaluable for debugging, logging, and error reporting in TypeScript/JavaScript applications.

Features

  • 🎯 Precise Call Site Information - Capture exact function names, file paths, and line/column numbers
  • 🗺️ Source Map Support - Get accurate locations in original TypeScript files, not transpiled JavaScript
  • 📚 Full Stack Trace - Access complete stack frame information for deep debugging
  • Lightweight - Minimal dependencies with focused functionality
  • 🔧 Configurable - Customize frame selection and filename formatting
  • 📝 TypeScript Ready - Full TypeScript support with proper type definitions

Installation

pnpm add @thelinuxlich/csc

Usage

Basic Usage

import { callSiteCapture } from 'csc';

function myFunction() {
  const callInfo = callSiteCapture();
  console.log(callInfo.callerInfo);
  // Output: "myFunction (src/example.ts:4:23)"
}

myFunction();

Advanced Usage

import { callSiteCapture } from 'csc';

function deepFunction() {
  // Capture the caller's caller (skip 1 frame)
  const callInfo = callSiteCapture(1);
  
  console.log('Function:', callInfo.functionName);
  console.log('Location:', callInfo.callerInfo);
  console.log('All frames:', callInfo.stackFrames.frame.length);
}

function intermediateFunction() {
  deepFunction();
}

function topLevelFunction() {
  intermediateFunction(); // This will be captured when frameIdx=1
}

topLevelFunction();

Filename Trimming

import { callSiteCapture } from 'csc';

function example() {
  // Skip the first 20 characters of the filename
  const callInfo = callSiteCapture(0, 20);
  console.log(callInfo.callerInfo);
  // Instead of: "example (/very/long/path/to/src/example.ts:5:10)"
  // Shows: "example (src/example.ts:5:10)"
}

API Reference

callSiteCapture(frameIdx?, skipFileNameAt?)

Captures detailed information about a specific call site in the stack trace.

Parameters

  • frameIdx (number, optional): The stack frame index to capture (default: 0)
    • 0: Current function
    • 1: Calling function
    • 2: Caller's caller, etc.
  • skipFileNameAt (number, optional): Number of characters to skip from the beginning of the filename (default: 0)

Returns

An object containing:

{
  callerInfo: string;       // Formatted string: "functionName (file:line:column)"
  functionName: string;     // Raw function name
  stackFrames: {
    frame: Array<{
      functionName: { value: string };
      fileName: { value: string };
      lineNumber: string;
      columnNumber: string;
    }>;
  };
}

Example Return Value

{
  callerInfo: "myFunction (src/example.ts:15:23)",
  functionName: "myFunction",
  stackFrames: {
    frame: [
      {
        functionName: "myFunction",
        fileName: "/project/src/example.ts",
        lineNumber: "15",
        columnNumber: "23"
      },
      {
        functionName: "main",
        fileName: "/project/src/index.ts",
        lineNumber: "8",
        columnNumber: "5"
      }
      // ... more frames
    ]
  }
}

Use Cases

Debugging and Logging

import { callSiteCapture } from 'csc';

function logger(message: string) {
  const callInfo = callSiteCapture(1); // Get caller info
  console.log(`[${callInfo.callerInfo}] ${message}`);
}

function businessLogic() {
  logger("Processing started");
  // Output: [businessLogic (src/business.ts:12:3)] Processing started
}

Error Reporting

import { callSiteCapture } from 'csc';

function reportError(error: Error) {
  const callInfo = callSiteCapture(1);
  
  return {
    error: error.message,
    location: callInfo.callerInfo,
    stackTrace: callInfo.stackFrames.frame.map(frame => ({
      function: frame.functionName,
      file: frame.fileName,
      line: frame.lineNumber,
      column: frame.columnNumber
    }))
  };
}

Development Tools

import { callSiteCapture } from 'csc';

function performanceTracker<T>(fn: () => T): T {
  const callInfo = callSiteCapture(1);
  const start = performance.now();
  
  try {
    return fn();
  } finally {
    const duration = performance.now() - start;
    console.log(`${callInfo.functionName} took ${duration.toFixed(2)}ms`);
  }
}

Requirements

  • Node.js 12+ or modern browser environment
  • TypeScript 4.0+ (for TypeScript projects)

Dependencies

How It Works

The library uses Node.js's Error.prepareStackTrace API to capture raw call site information, then enhances it with source map support to provide accurate locations in your original TypeScript files rather than the transpiled JavaScript output.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License

Related Projects