Socket
Socket
Sign inDemoInstall

parent-module

Package Overview
Dependencies
1
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 2.0.0

index.d.ts

20

index.js
'use strict';
const callsites = require('callsites');
module.exports = filepath => {
module.exports = filePath => {
const stacks = callsites();
if (!filepath) {
if (!filePath) {
return stacks[2].getFileName();
}
let seenVal = false;
let hasSeenValue = false;

@@ -17,10 +17,10 @@ // Skip the first stack as it's this function

for (const stack of stacks) {
const parentFilepath = stack.getFileName();
const parentFilePath = stack.getFileName();
if (typeof parentFilepath !== 'string') {
if (typeof parentFilePath !== 'string') {
continue;
}
if (parentFilepath === filepath) {
seenVal = true;
if (parentFilePath === filePath) {
hasSeenValue = true;
continue;

@@ -30,10 +30,10 @@ }

// Skip native modules
if (parentFilepath === 'module.js') {
if (parentFilePath === 'module.js') {
continue;
}
if (seenVal && parentFilepath !== filepath) {
return parentFilepath;
if (hasSeenValue && parentFilePath !== filePath) {
return parentFilePath;
}
}
};
{
"name": "parent-module",
"version": "1.0.1",
"version": "2.0.0",
"description": "Get the path of the parent module",

@@ -13,9 +13,10 @@ "license": "MIT",

"engines": {
"node": ">=6"
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],

@@ -26,3 +27,2 @@ "keywords": [

"package",
"pkg",
"caller",

@@ -41,3 +41,3 @@ "calling",

"dependencies": {
"callsites": "^3.0.0"
"callsites": "^3.1.0"
},

@@ -47,4 +47,5 @@ "devDependencies": {

"execa": "^1.0.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}

@@ -37,7 +37,7 @@ # parent-module [![Build Status](https://travis-ci.org/sindresorhus/parent-module.svg?branch=master)](https://travis-ci.org/sindresorhus/parent-module)

### parentModule([filepath])
### parentModule([filePath])
By default, it will return the path of the immediate parent.
#### filepath
#### filePath

@@ -47,3 +47,3 @@ Type: `string`<br>

Filepath of the module of which to get the parent path.
File path of the module of which to get the parent path.

@@ -50,0 +50,0 @@ Useful if you want it to work [multiple module levels down](https://github.com/sindresorhus/parent-module/tree/master/fixtures/filepath).

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc