pax_global_header 0000666 0000000 0000000 00000000064 14420517672 0014522 g ustar 00root root 0000000 0000000 52 comment=9dcb8cc3d4c46e97209894a6c36ee7a352d6f97e
nexdrew-which-module-aec6457/ 0000775 0000000 0000000 00000000000 14420517672 0016201 5 ustar 00root root 0000000 0000000 nexdrew-which-module-aec6457/.gitignore 0000664 0000000 0000000 00000000055 14420517672 0020171 0 ustar 00root root 0000000 0000000 node_modules/
.nyc_output/
package-lock.json
nexdrew-which-module-aec6457/.npmrc 0000664 0000000 0000000 00000000023 14420517672 0017314 0 ustar 00root root 0000000 0000000 package-lock=false
nexdrew-which-module-aec6457/.travis.yml 0000664 0000000 0000000 00000000143 14420517672 0020310 0 ustar 00root root 0000000 0000000 sudo: false
language: node_js
node_js:
- '8'
- '10'
- 'node'
after_success: npm run coverage
nexdrew-which-module-aec6457/CHANGELOG.md 0000664 0000000 0000000 00000001510 14420517672 0020007 0 ustar 00root root 0000000 0000000 # Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [2.0.1](https://github.com/nexdrew/which-module/compare/v2.0.0...v2.0.1) (2023-04-21)
# [2.0.0](https://github.com/nexdrew/which-module/compare/v1.0.0...v2.0.0) (2017-05-01)
### Features
* remove Node < 4 from official testing/support ([#22](https://github.com/nexdrew/which-module/issues/22)) ([ee7aff4](https://github.com/nexdrew/which-module/commit/ee7aff4))
### BREAKING CHANGES
* Node 0.10 or 0.12 no longer supported, please update to Node 4+ or use which-module@1.0.0
# 1.0.0 (2016-06-06)
### Features
* initial code ([08074cd](https://github.com/nexdrew/which-module/commit/08074cd))
nexdrew-which-module-aec6457/LICENSE 0000664 0000000 0000000 00000001333 14420517672 0017206 0 ustar 00root root 0000000 0000000 Copyright (c) 2016, Contributors
Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
nexdrew-which-module-aec6457/README.md 0000664 0000000 0000000 00000004134 14420517672 0017462 0 ustar 00root root 0000000 0000000 # which-module
> Find the module object for something that was require()d
[](https://travis-ci.org/nexdrew/which-module)
[](https://coveralls.io/github/nexdrew/which-module?branch=master)
[](https://github.com/conventional-changelog/standard-version)
[](https://greenkeeper.io/)
Find the `module` object in `require.cache` for something that was `require()`d
or `import`ed - essentially a reverse `require()` lookup.
Useful for libs that want to e.g. lookup a filename for a module or submodule
that it did not `require()` itself.
## Install and Usage
```
npm install --save which-module
```
```js
const whichModule = require('which-module')
console.log(whichModule(require('something')))
// Module {
// id: '/path/to/project/node_modules/something/index.js',
// exports: [Function],
// parent: ...,
// filename: '/path/to/project/node_modules/something/index.js',
// loaded: true,
// children: [],
// paths: [ '/path/to/project/node_modules/something/node_modules',
// '/path/to/project/node_modules',
// '/path/to/node_modules',
// '/path/node_modules',
// '/node_modules' ] }
```
## API
### `whichModule(exported)`
Return the [`module` object](https://nodejs.org/api/modules.html#modules_the_module_object),
if any, that represents the given argument in the `require.cache`.
`exported` can be anything that was previously `require()`d or `import`ed as a
module, submodule, or dependency - which means `exported` is identical to the
`module.exports` returned by this method.
If `exported` did not come from the `exports` of a `module` in `require.cache`,
then this method returns `null`.
## License
ISC © Contributors
[opensourceregistry_package_id]: # (458260416784685e5ef3091fee54001785dd4360406aa3000315ff256eef6878)
nexdrew-which-module-aec6457/index.js 0000664 0000000 0000000 00000000370 14420517672 0017646 0 ustar 00root root 0000000 0000000 'use strict'
module.exports = function whichModule (exported) {
for (var i = 0, files = Object.keys(require.cache), mod; i < files.length; i++) {
mod = require.cache[files[i]]
if (mod.exports === exported) return mod
}
return null
}
nexdrew-which-module-aec6457/package.json 0000664 0000000 0000000 00000001625 14420517672 0020473 0 ustar 00root root 0000000 0000000 {
"name": "which-module",
"version": "2.0.1",
"description": "Find the module object for something that was require()d",
"main": "index.js",
"scripts": {
"pretest": "standard",
"test": "nyc ava",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"release": "standard-version"
},
"files": [
"index.js"
],
"repository": {
"type": "git",
"url": "git+https://github.com/nexdrew/which-module.git"
},
"keywords": [
"which",
"module",
"exports",
"filename",
"require",
"reverse",
"lookup"
],
"author": "nexdrew",
"license": "ISC",
"bugs": {
"url": "https://github.com/nexdrew/which-module/issues"
},
"homepage": "https://github.com/nexdrew/which-module#readme",
"devDependencies": {
"ava": "^2.0.0",
"coveralls": "^3.0.3",
"nyc": "^14.0.0",
"standard": "^14.0.0",
"standard-version": "^7.0.0"
}
}
nexdrew-which-module-aec6457/test.js 0000664 0000000 0000000 00000002627 14420517672 0017525 0 ustar 00root root 0000000 0000000 const test = require('ava')
const whichModule = require('./')
const path = require('path')
test('finds required local module', (t) => {
const indexModule = whichModule(whichModule)
const expectedFilename = path.join(__dirname, 'index.js')
t.is(indexModule.id, expectedFilename)
t.is(indexModule.filename, expectedFilename)
t.is(indexModule.exports, whichModule)
t.is(indexModule.parent, module)
t.is(indexModule.loaded, true)
t.is(indexModule.paths[0], path.join(__dirname, 'node_modules'))
})
test('finds required dependency module', (t) => {
const avaModule = whichModule(test)
const expectedFilename = path.join(__dirname, 'node_modules', 'ava', 'index.js')
t.is(avaModule.id, expectedFilename)
t.is(avaModule.filename, expectedFilename)
t.is(avaModule.exports, test)
t.is(avaModule.parent, module)
t.is(avaModule.loaded, true)
t.is(avaModule.paths[0], path.join(__dirname, 'node_modules', 'ava', 'node_modules'))
t.truthy(avaModule.children.length)
})
test('returns falsy for system module', (t) => {
t.falsy(whichModule(path))
t.falsy(whichModule(require('fs')))
})
test('returns falsy for non-required', (t) => {
// note that a module may export a boolean (e.g. supports-color)
// or undefined (e.g. lodash/_Reflect.js)
t.falsy(whichModule(t))
t.falsy(whichModule({}))
t.falsy(whichModule(function () {}))
t.falsy(whichModule('foobar'))
t.falsy(whichModule(String))
})