Comparing version
10
index.js
'use strict'; | ||
var assert = require('assert'); | ||
@@ -11,3 +12,3 @@ | ||
module.exports = function (depth) { | ||
var pst, stack, file, frame; | ||
var pst, stack, file, frame, startIdx; | ||
@@ -21,4 +22,9 @@ pst = Error.prepareStackTrace; | ||
stack = (new Error()).stack; | ||
// Handle case where error object is wrapped by say babel. Try to find current file's index first. | ||
startIdx = 0; | ||
while(startIdx < stack.length && stack[startIdx].getFileName() !== __filename) startIdx++; | ||
assert(startIdx < stack.length, 'Unexpected: unable to find caller/index.js in the stack'); | ||
depth = !depth || isNaN(depth) ? 1 : (depth > stack.length - 2 ? stack.length - 2 : depth); | ||
stack = stack.slice(depth + 1); | ||
stack = stack.slice(startIdx + depth + 1); | ||
@@ -25,0 +31,0 @@ do { |
{ | ||
"name": "caller", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "@substack's caller.js as a module", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
3879
13.92%5
25%28
21.74%1
Infinity%