Giter Site home page Giter Site logo

mnrendra / stack-trace Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 308 KB

A utility that enables stack tracing of the NodeJs.CallSite object, allowing dynamic tracing of invocations.

Home Page: https://www.npmjs.com/package/@mnrendra/stack-trace

License: MIT License

TypeScript 97.14% JavaScript 2.86%
callsite callsites stack-trace stack-trace-v8 stack-traces

stack-trace's Introduction

@mnrendra/stack-trace

A utility that enables stack tracing of the NodeJs.CallSite object, allowing dynamic tracing of invocations.

Install

npm i @mnrendra/stack-trace

Usage

Using CommonJS:

const { stackTrace } = require('@mnrendra/stack-trace')
const [trace] = stackTrace()
console.log(trace.getFileName() === __filename) // Output: true

Using ES Module:

import { stackTrace } from '@mnrendra/stack-trace'
import { fileURLToPath } from 'node:url'
const [trace] = stackTrace()
console.log(new URL(trace.getFileName()).pathname === fileURLToPath(import.meta.url)) // Output: true

Examples

  1. Call from your development project /foo/project-name/src/index.mjs:
import { stackTrace } from '@mnrendra/stack-trace'
const [trace] = stackTrace()
console.log(trace.getFileName()) // Output: file:///foo/project-name/src/index.mjs
  1. Call from your production module /foo/project-name/node_modules/module-name/dist/index.js:
"use strict";
const { stackTrace } = require('@mnrendra/stack-trace');
const [trace] = stackTrace();
console.log(trace.getFileName()); // Output: /foo/project-name/node_modules/module-name/dist/index.js

Note: When calling getFileName from an ESM module, it will return the file name as a URL instead of a file path.

Types

import type {
  CallSite, // NodeJS.CallSite
  StackTrace, // (targetFunction?: TargetFunction, options?: Options) => CallSite[]
  TargetFunction, // (...args: any[]) => any | Promise<TargetFunction>
  Options // { limit?: number }
} from '@mnrendra/stack-trace'

License

MIT

Author

@mnrendra

stack-trace's People

Contributors

gitops-init avatar gitops-merge avatar gitops-release avatar mnrendra avatar

Watchers

 avatar

stack-trace's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.