{"name":"parent-module","version":"3.2.0","description":"Get the path of the parent module","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/parent-module.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","engines":{"node":"^12.20.0 || ^14.13.1 || >=16.0.0"},"scripts":{"test":"xo && ava && tsd"},"keywords":["parent","module","package","caller","calling","module","path","callsites","callsite","stacktrace","stack","trace","function","file"],"dependencies":{"callsites":"^4.1.0"},"devDependencies":{"ava":"^3.15.0","execa":"^5.1.1","tsd":"^0.17.0","xo":"^0.45.0"},"_id":"parent-module@3.2.0","gitHead":"3e3193aa846d410e79b1f98dc08fa2801b15147e","types":"./index.d.ts","bugs":{"url":"https://github.com/sindresorhus/parent-module/issues"},"homepage":"https://github.com/sindresorhus/parent-module#readme","_nodeVersion":"20.19.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-2Ik9vslIJdx+teObUMPbYd5ONHrTh0EH6o88qNQqU2o+JKPR13V5cmoWmCBn3G7V5pyomexaZixyQoHfzl5E4g==","shasum":"016bea3ac5a71d06f65697708c03dcaaf00ac33b","tarball":"http://registry-npm.ywwl.com/parent-module/download/parent-module-3.2.0.tgz","fileCount":5,"unpackedSize":5049,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIBgQJXpMkvyudyIK4sElVCwW0m9CDaIt688+33B2eHC3AiAFzcfG9T3QXdLeN8N7m3+W7EY75gI5Ln7WkQO2/xPg5w=="}],"size":2251,"noattachment":false,"key":"/parent-module/-/parent-module-3.2.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/parent-module_3.2.0_1757920845163_0.3273513190725885"},"_hasShrinkwrap":false,"readme":"# parent-module\n\n> Get the path of the parent module\n\nThis module provides a reliable way to get the file path of the module that called your code, working correctly with both CommonJS and ESM modules.\n\n## Install\n\n```sh\nnpm install parent-module\n```\n\n## Usage\n\n```js\n// bar.js\nimport parentModule from 'parent-module';\n\nexport default function bar() {\n\tconsole.log(parentModule());\n\t//=> '/Users/sindresorhus/dev/unicorn/foo.js'\n}\n```\n\n```js\n// foo.js\nimport bar from './bar.js';\n\nbar();\n```\n\n## API\n\n### parentModule(filePath?)\n\nReturns: `string | undefined`\n\nReturns the file path of the immediate parent module, or `undefined` if there is no parent module (for example, when called from the top-level of an entry module).\n\n#### filePath\n\nType: `string`\\\nDefault: `import.meta.filename`\n\nThe file path of the module for which to get the parent path.\n\nUseful for getting the parent of a specific module when the call traverses [multiple module levels](fixtures/filepath).\n\n## Tip\n\nCombine it with [`read-package-up`](https://github.com/sindresorhus/read-package-up) to read the package.json of the parent module.\n\n```js\nimport path from 'node:path';\nimport {readPackageUpSync} from 'read-package-up';\nimport parentModule from 'parent-module';\n\nconst parent = parentModule();\nif (parent) {\n\tconsole.log(readPackageUpSync({cwd: path.dirname(parent)}).pkg);\n\t//=> {name: 'chalk', version: '1.0.0', …}\n}\n```\n","publish_time":1757920845338,"_cnpm_publish_time":1757920845338,"dist-tags":{"latest":"3.2.0"}}