Skip to content

thlorenz/function-origin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@thlorenz/function-origin

Get origin of a function in Node.js

NOTE:

This is a version that fixes the bound function problem and works with latest Node.js versions.

The original module seems to be no longer maintained, i.e. this PR fixing bound function issues hasn't been merged for years.

Installation

npm install @thlorenz/function-origin

Usage

const { functionOrigin } = require('@thlorenz/function-origin')
const origin = functionOrigin(someFn)

origin has the following properties:

  • file — source file name;
  • line — line number (0-based);
  • column — column number (0-based);
  • inferredName.

If a function's origin cannot be resolved (as is the case for native functions like Math.abs), an empty origin is returned which looks as follows:

const { EMPTY_ORIGIN_INFO } = require('./')

console.log(EMPTY_ORIGIN_INFO)
// => { line: -1, column: -1, inferredName: '' }

Note that in that case typeof file === 'undefined' which allows you to detect that case.

License

MIT

About

Get origin of a function in Node.js

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 45.1%
  • C++ 39.0%
  • TypeScript 12.1%
  • Python 3.8%