0.1.3 • Published 9 years ago

function-info v0.1.3

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

function-info

Get source info from a function definition in NodeJS.

Introduction

NodeJS does not export methods to get source file name, line and column number from a function reference. function-info is a NodeJS addon that calls the relevant V8 methods to get this information back to js.

Getting Started

Install from npm

npm install function-info

The main export from function-info is a function taking a function reference as its single argument and returns a function-info structure:

{
  sourceFile: "<absolute-path-to-source-file>",
  lineNumber: <line-number-of-function-definition>,
  columnNumber: <column-number-of-function-definition>
}

Example

Create test.js:

module.exports.hello = function() {
  return "Hello";
}

module.exports.world = world;

function world() {
  return "World";
}

Then in node repl:

var test = require("./test");
var functionInfo = require('function-info');

console.log(functionInfo(test.hello)); //{ sourceFile: "<cwd>/test.js", lineNumber: 1, columnNumber: 31 }
console.log(functionInfo(test.world)); //{ sourceFile: "<cwd>/test.js", lineNumber: 7, columnNumber: 14 }
0.1.3

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago