Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
locate-path
Advanced tools
Package description
The locate-path npm package is designed to find a file or directory by looking for it in multiple paths. It is useful for situations where you need to locate a file but are unsure of its exact location within a list of possible directories. It can be used synchronously or asynchronously and supports both promises and async/await syntax.
Asynchronous Path Location
This feature allows you to asynchronously locate a file or directory from an array of paths. The first path that contains the file or directory is returned.
const locatePath = require('locate-path');
(async () => {
const foundPath = await locatePath(['unicorn.png', 'rainbow.png'], {cwd: 'images'});
console.log(foundPath);
//=> 'images/unicorn.png'
})();
Synchronous Path Location
This feature provides a synchronous way to locate a file or directory from an array of paths. It is useful when you need to find a path in a blocking manner.
const locatePath = require('locate-path');
const foundPath = locatePath.sync(['unicorn.png', 'rainbow.png'], {cwd: 'images'});
console.log(foundPath);
//=> 'images/unicorn.png'
The find-up package is similar to locate-path in that it helps you find a file or directory by searching upwards from a given directory. It differs in that it searches up the directory tree, starting from the current directory, rather than across a list of specified paths.
Globby is a package that allows you to find files using glob patterns. While locate-path is used to find a file from a list of paths, globby can search for files matching patterns, which can be more flexible in certain scenarios.
Resolve-from is a package that resolves the path of a module from a given path, similar to require.resolve but from a specified directory. It is more specific to module resolution compared to locate-path which is for general file or directory location.
Readme
Get the first path that exists on disk of multiple paths
$ npm install locate-path
Here we find the first file that exists on disk, in array order.
const locatePath = require('locate-path');
const files = [
'unicorn.png',
'rainbow.png', // Only this one actually exists on disk
'pony.png'
];
(async () => {
console(await locatePath(files));
//=> 'rainbow'
})();
Returns a Promise<string>
for the first path that exists or undefined
if none exists.
Type: Iterable<string>
Paths to check.
Type: object
Type: number
Default: Infinity
Minimum: 1
Number of concurrently pending promises.
Type: boolean
Default: true
Preserve paths
order when searching.
Disable this to improve performance if you don't care about the order.
Type: string
Default: process.cwd()
Current working directory.
Type: string
Default: 'file'
Values: 'file' | 'directory'
The type of paths that can match.
Type: boolean
Default: true
Allow symbolic links to match if they point to the chosen path type.
Returns the first path that exists or undefined
if none exists.
Type: Iterable<string>
Paths to check.
Type: object
Same as above.
Same as above.
Same as above.
FAQs
Get the first path that exists on disk of multiple paths
The npm package locate-path receives a total of 113,709,462 weekly downloads. As such, locate-path popularity was classified as popular.
We found that locate-path 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.