Security News
How Threat Actors are Abusing GitHub’s File Upload Feature to Host Malware
GitHub is susceptible to a CDN flaw that allows attackers to host malware on any public repository.
resolve-from
Advanced tools
Package description
The resolve-from npm package is a module that allows you to resolve the path of a module like require.resolve() but from a given path. It is useful for situations where you need to resolve modules from a different directory than the current file's directory.
Resolve the path of a module from a given path
This feature allows you to resolve the path of a module from a specific directory. You provide the directory as the first argument and the module name as the second argument. It returns the resolved path to the module.
const resolveFrom = require('resolve-from');
const modulePath = resolveFrom('/some/path', 'some-module');
Silently resolve the path of a module or return null
This feature is similar to the first, but it will return null instead of throwing an error if the module cannot be found. This is useful for cases where you want to check for a module's existence without causing an exception.
const resolveFrom = require('resolve-from');
const modulePath = resolveFrom.silent('/some/path', 'non-existent-module');
The 'resolve' package is similar to 'resolve-from' in that it helps to resolve the path of a module. However, 'resolve' provides more options and flexibility, such as the ability to customize the resolution algorithm or to resolve based on the package.json's 'main' field.
The 'enhanced-resolve' package is used by webpack and offers a highly configurable resolution mechanism that can resolve files, directories, and modules. It is more complex and feature-rich compared to 'resolve-from', which is simpler and more straightforward.
The 'browser-resolve' package is designed to resolve modules for browser environments, taking into account the 'browser' field in package.json. It is similar to 'resolve-from' but is specifically tailored for browser-based module resolution.
Readme
Resolve the path of a module like
require.resolve()
but from a given path
$ npm install resolve-from
const resolveFrom = require('resolve-from');
// There is a file at `./foo/bar.js`
resolveFrom('foo', './bar');
//=> '/Users/sindresorhus/dev/test/foo/bar.js'
Like require()
, throws when the module can't be found.
Returns undefined
instead of throwing when the module can't be found.
Type: string
Directory to resolve from.
Type: string
What you would use in require()
.
Create a partial using a bound function if you want to resolve from the same fromDirectory
multiple times:
const resolveFromFoo = resolveFrom.bind(null, 'foo');
resolveFromFoo('./bar');
resolveFromFoo('./baz');
MIT © Sindre Sorhus
FAQs
Resolve the path of a module like `require.resolve()` but from a given path
The npm package resolve-from receives a total of 66,220,991 weekly downloads. As such, resolve-from popularity was classified as popular.
We found that resolve-from demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub is susceptible to a CDN flaw that allows attackers to host malware on any public repository.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.