# caller-id

> A utility for getting information on the caller of a function in node.js

Latest version **0.1.0** (published 2013-11-05) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install caller-id
pnpm add caller-id
yarn add caller-id
bun add caller-id
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2013-11-05 |
| First published | 2013-11-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.8 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 41 |
| Author | Pixels & Bytes |
| Maintainers | pixelsandbytes |
| Keywords | function, method, call, caller, stack, trace, stacktrace, caller-id |

## Links

- npm: https://www.npmjs.com/package/caller-id
- Repository: https://github.com/pixelsandbytes/caller-id
- Issues: https://github.com/pixelsandbytes/caller-id/issues
- npm.io page: https://npm.io/package/caller-id

## Dependencies (1)

- [stack-trace](https://npm.io/package/stack-trace.md) ~0.0.7

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2013-11-05

## README

# caller-id

A utility for getting information on the caller of a function in node.js

[![Build Status](https://travis-ci.org/pixelsandbytes/caller-id.png?branch=master)](https://travis-ci.org/pixelsandbytes/caller-id)

## Installation
1. Add `caller-id` as a dependency to your project’s `package.json`
2. Run `npm install`

## Usage Examples

### `getData`

`getData()` can be used to get raw data about a function's caller

    var callerId = require('caller-id');

    // 1. Function calling another function
    function foo() {
        bar();
    }
    function bar() {
        var caller = callerId.getData();
        /*
        caller = {
            typeName: 'Object',
            functionName: 'foo',
            filePath: '/path/of/this/file.js',
            lineNumber: 5,
            topLevelFlag: true,
            nativeFlag: false,
            evalFlag: false
        }
        */
    }

    // 2. Method in a class calling a function
    function Lorem() {}
    Lorem.prototype.ipsum = function() {
        baz();
    }
    function baz() {
        var caller = callerId.getData();
        /*
        caller = {
            typeName: 'Lorem',
            functionName: 'Lorem.ipsum',
            methodName: 'ipsum',
            filePath: '/path/of/this/file.js',
            lineNumber: 25,
            topLevelFlag: false,
            nativeFlag: false,
            evalFlag: false
        }
        */
    }

    // 3. Function in an eval calling another function
    function func() {
        var caller = callerId.getData();
        /*
        caller = {
            typeName: 'Object',
            functionName: 'evil',
            lineNumber: 2,
            topLevelFlag: true,
            nativeFlag: false,
            evalFlag: true,
            evalOrigin: 'eval at <anonymous> (/path/of/this/file.js:58:7)'
        }
        */
    }
    eval('(function evil() {' + '\\n' +
        'func();' + '\\n' +
        '})();');

### `getString`

`getString()` returns a brief string representing a function's caller

    var callerId = require('caller-id');

    function myFunction() {
        var callerString = callerId.getString();
    }

Using the same examples as above, `getString()` returns the following:

1.  foo
2.  Lorem.ipsum
3.  (eval)evil

### `getDetailedString`

`getDetailedString()` returns a more detailed string representing a function's caller

    var callerId = require('caller-id');

    function myFunction() {
        var detailedCallerString = callerId.getDetailedString();
    }

Using the same examples as above, `getDetailedString()` returns the following:

1.  foo at /path/of/this/file.js:5
2.  Lorem.ipsum at /path/of/this/file.js:25
3.  eval at <anonymous> (/path/of/this/file.js:58:7)

---
_Source: https://npm.io/package/caller-id · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
