line-stack

0.1.2 • Public • Published

line-stack

npm npm

Get current line stack information such as line number, method, file, filename, callSites, and more. Can search through callSites for/skip a particular functionName, typeName, or filename.

Typedefs

CallSite : `object`
StackItem : `object`

lineStack

Example

const lineStack = require('line-stack')

LineStack ⏏

Kind: Exported class

lineStack.get([level]) ⇒ StackItem

Returns stack trace which can be console logged

lineStack.get([level]) ⇒ StackItem

Returns a single item at given level

Kind: instance method of LineStack

Param Type Default Description
[level] number 0 Useful to return levels up on the stack. If not informed, the first (0, zero index) element of the stack will be returned

lineStack.findByFilename(rx, fromIndex, stack, returnIndex) ⇒ StackItem | number | void

find the stack using filename that matches the given RegExp or string.

Kind: instance method of LineStack

Param Type Default Description
rx string \ RegExp string or regular expression to use to find the item
fromIndex number 0 the index of the first item to find
stack Array.<CallSite> array of StackItems to search through
returnIndex boolean false if true, return the stack index the item is instead of the item

lineStack.skipByFilename(matcher) ⇒ StackItem | void

find the next stack using filename that doesn't match the given string.

Kind: instance method of LineStack

Param Type
matcher string

lineStack.findByTypeName(rx, fromIndex, stack, returnIndex) ⇒ StackItem | number | void

find the stack using type name that matches the given RegExp or string.

Kind: instance method of LineStack

Param Type Default Description
rx string \ RegExp string or regular expression to use to find the item
fromIndex number 0 the index of the first item to find
stack Array.<CallSite> array of StackItems to search through
returnIndex boolean false if true, return the stack index the item is instead of the item

lineStack.skipByTypeName(matcher) ⇒ StackItem | void

find the next stack using type name that doesn't match the given string.

Kind: instance method of LineStack

Param Type
matcher string

lineStack.findByFunctionName(rx, fromIndex, stack, returnIndex) ⇒ StackItem | number | void

find the stack using function name that matches the given RegExp or string.

Kind: instance method of LineStack

Param Type Default Description
rx string \ RegExp string or regular expression to use to find the item
fromIndex number 0 the index of the first item to find
stack Array.<CallSite> array of StackItems to search through
returnIndex boolean false if true, return the stack index the item is instead of the item

lineStack.skipByFunctionName(matcher) ⇒ StackItem | void

find the next stack using function name that doesn't match the given string.

Kind: instance method of LineStack

Param Type
matcher string

lineStack.all() ⇒ Array.<CallSite>

Returns all stack

Kind: instance method of LineStack

lineStack.parseCallSitesToStack(Array.<CallSite>) ⇒ String

Returns stack trace based off given callSites

Kind: instance method of LineStack

LineStack~getStack() ⇒ Array.<CallSite>

Get the call callSites stack

Kind: inner method of LineStack

LineStack~parse(item, stack) ⇒ StackItem

Parse the given stack item

Kind: inner method of LineStack

Param
item
stack

LineStack~iterateStack(stack, fromIndex, returnIndex, predicate) ⇒ StackItem | number | void

iterate through given stack items and return of first item where predicate returns truthy.

Kind: inner method of LineStack

Param Type Description
stack Array.<CallSite> stack to iterate through
fromIndex number the index to start at
returnIndex boolean if true, return the stack index the item is instead of the item
predicate function predicate function to use. called with arguments (item) - the current stack item

CallSite : object

Kind: global typedef
Properties

Name Type
getThis() object or undefined
getTypeName() string
getFunction() function or undefined
getFunctionName() string
getMethodName() string or null
getFileName() string or undefined
getLineNumber() number
getColumnNumber() number
getEvalOrigin() CallSite or string
isToplevel() boolean
isEval() boolean
isNative() boolean
isConstructor() boolean

StackItem : object

Kind: global typedef
Properties

Name Type Description
method string Name of function on stack
line number Line number on stack
file string /PathOfFile/Source/NameOfFilename.js
filename string NameOfFile
callSites Array.<CallSite> /PathOfFile/Source/NameOfFilename.js

Author

Emmanuel Mahuni

Readme

Keywords

none

Package Sidebar

Install

npm i line-stack

Weekly Downloads

2

Version

0.1.2

License

MIT

Unpacked Size

20.4 kB

Total Files

5

Last publish

Collaborators

  • emahuni