index.js
 1  "use strict";
 2  // Call this function in a another function to find out the file from
 3  // which that function was called from. (Inspects the v8 stack trace)
 4  //
 5  // Inspired by http://stackoverflow.com/questions/13227489
 6  module.exports = function getCallerFile(position) {
 7      if (position === void 0) { position = 2; }
 8      if (position >= Error.stackTraceLimit) {
 9          throw new TypeError('getCallerFile(position) requires position be less then Error.stackTraceLimit but position was: `' + position + '` and Error.stackTraceLimit was: `' + Error.stackTraceLimit + '`');
10      }
11      var oldPrepareStackTrace = Error.prepareStackTrace;
12      Error.prepareStackTrace = function (_, stack) { return stack; };
13      var stack = new Error().stack;
14      Error.prepareStackTrace = oldPrepareStackTrace;
15      if (stack !== null && typeof stack === 'object') {
16          // stack[0] holds this file
17          // stack[1] holds where this function was called
18          // stack[2] holds the file we're interested in
19          return stack[position] ? stack[position].getFileName() : undefined;
20      }
21  };
22  //# sourceMappingURL=index.js.map