1.0.1 • Published 3 years ago

at-line v1.0.1

Weekly downloads
-
License
Unlicense
Repository
-
Last release
3 years ago

at-line

get calling function, filename, line-number from error stack trace

Installation

Requires nodejs.

$ npm install at-line

Usage

const {atLine} = require('at-line')

const f = () => {
  const at = atLine()
  console.log(at)
}

f()
// >
// { func: 'f',
//   file: '/home/user/at-line/examples/test.js',
//   line: '4',
//   col: '14' }

API

atLine([n])

Get calling function, filename, line-number and column from stack trace at the point of calling atLine

NOTE: This is a slow function!

Parameters

parametertypedescription
[n]Numberoptional: get result from n-th line

Returns Object, {func, file, line, col}

atLine.stack(err, [depth], [start])

Get error stack with processable information

Parameters

parametertypedescription
errErrorerror
err.stackStringstacktrace
[depth]Numberoptional: required depth of stacktrace
[start]Numberoptional: start with line

Returns Array, array of processed stack trace lines [{func, file, line, col}]

Tests

$ npm test

LICENSE

Unlicense https://unlicense.org