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 2.0.0 to 3.0.0

13

index.d.ts
/**
Get the path of the parent module.
@param filePath - File path of the module of which to get the parent path.
@param filePath - The file path of the module of which to get the parent path.
Useful if you want it to work [multiple module levels down](https://github.com/sindresorhus/parent-module/tree/master/fixtures/filepath).
Useful if you want it to work [multiple module levels down](https://github.com/sindresorhus/parent-module/tree/main/fixtures/filepath).
Default: [`__filename`](https://nodejs.org/api/globals.html#globals_filename)
@example
```
// bar.ts
const parentModule = require('parent-module');
import parentModule from 'parent-module';

@@ -22,3 +21,3 @@ export default () => {

// foo.ts
import bar from './bar';
import bar from './bar.js';

@@ -28,4 +27,2 @@ bar();

*/
declare function parentModule(filePath?: string): string | undefined;
export = parentModule;
export default function parentModule(filePath?: string): string | undefined;

@@ -1,5 +0,4 @@

'use strict';
const callsites = require('callsites');
import callsites from 'callsites';
module.exports = filePath => {
export default function parentModule(filePath) {
const stacks = callsites();

@@ -37,2 +36,2 @@

}
};
}
{
"name": "parent-module",
"version": "2.0.0",
"version": "3.0.0",
"description": "Get the path of the parent module",
"license": "MIT",
"repository": "sindresorhus/parent-module",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},

@@ -39,10 +42,10 @@ "scripts": {

"dependencies": {
"callsites": "^3.1.0"
"callsites": "^4.0.0"
},
"devDependencies": {
"ava": "^1.4.1",
"execa": "^1.0.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^3.15.0",
"execa": "^5.1.1",
"tsd": "^0.17.0",
"xo": "^0.45.0"
}
}

@@ -1,2 +0,2 @@

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

@@ -7,10 +7,8 @@ > Get the path of the parent module

## Install
```sh
npm install parent-module
```
$ npm install parent-module
```
## Usage

@@ -20,5 +18,5 @@

// bar.js
const parentModule = require('parent-module');
import parentModule from 'parent-module';
module.exports = () => {
export default function bar() {
console.log(parentModule());

@@ -31,3 +29,3 @@ //=> '/Users/sindresorhus/dev/unicorn/foo.js'

// foo.js
const bar = require('./bar');
import bar from './bar.js';

@@ -37,6 +35,5 @@ bar();

## API
### parentModule([filePath])
### parentModule(filePath?)

@@ -47,10 +44,9 @@ By default, it will return the path of the immediate parent.

Type: `string`<br>
Type: `string`\
Default: [`__filename`](https://nodejs.org/api/globals.html#globals_filename)
File path of the module of which to get the parent path.
The file path of the module of which to get the parent path.
Useful if you want it to work [multiple module levels down](https://github.com/sindresorhus/parent-module/tree/master/fixtures/filepath).
Useful if you want it to work [multiple module levels down](fixtures/filepath).
## Tip

@@ -61,13 +57,20 @@

```js
const path = require('path');
const readPkgUp = require('read-pkg-up');
const parentModule = require('parent-module');
import path from 'node:path';
import {readPackageUpSync} from 'read-pkg-up';
import parentModule from 'parent-module';
console.log(readPkgUp.sync({cwd: path.dirname(parentModule())}).pkg);
console.log(readPackageUpSync({cwd: path.dirname(parentModule())}).pkg);
//=> {name: 'chalk', version: '1.0.0', …}
```
---
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)
<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-parent-module?utm_source=npm-parent-module&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>

Sorry, the diff of this file is not supported yet

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