source: trip-planner-front/node_modules/parent-module/index.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 641 bytes
Line 
1'use strict';
2const callsites = require('callsites');
3
4module.exports = filepath => {
5 const stacks = callsites();
6
7 if (!filepath) {
8 return stacks[2].getFileName();
9 }
10
11 let seenVal = false;
12
13 // Skip the first stack as it's this function
14 stacks.shift();
15
16 for (const stack of stacks) {
17 const parentFilepath = stack.getFileName();
18
19 if (typeof parentFilepath !== 'string') {
20 continue;
21 }
22
23 if (parentFilepath === filepath) {
24 seenVal = true;
25 continue;
26 }
27
28 // Skip native modules
29 if (parentFilepath === 'module.js') {
30 continue;
31 }
32
33 if (seenVal && parentFilepath !== filepath) {
34 return parentFilepath;
35 }
36 }
37};
Note: See TracBrowser for help on using the repository browser.