2.0.1 • Published 7 months ago

@manuth/caller-module v2.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

CallerModule

Provides information about the caller of a method and its module

status-badge

This module provides the ability to determine what module performed the most recent function call. It additionally provides information about the module such as:

Installation

You can install this package using npm:

npm install --save @manuth/caller-module

Usage

TypeScript-example:

import { GetCallerModule } from "@manuth/caller-module";

console.log(GetCallerModule().name); // Logs the name of your module. 
const { GetCallerModule } = require("@manuth/caller-module");
console.log(GetCallerModule().name);

Documentation

GetCallerModule([method: function], [level: number])

  • method:
    The method whose caller is to be determined.
    Defaults to the GetCallerModule-method.
  • level: The number of levels above the method whose caller is to be determined.

Example

import { GetCallerModule } from "@manuth/caller-module";

function test
{
    test1();
}

function test1()
{
    test2();
}

function test2()
{
    last();
}

function last()
{
    console.log(GetCallerModule().name); // Your module's name.
    console.log(GetCallerModule().callSite.getFunctionName()); // last
    console.log(GetCallerModule(2).callSite.getFunctionName()); // test2
    console.log(GetCallerModule(last).callSite.getFunctionName()); // test2
    console.log(GetCallerModule(last, 2).callSite.getFunctionName()); // test1
}
2.0.1

7 months ago

1.0.14

2 years ago

2.0.0

2 years ago

1.0.13

2 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

4 years ago