Socket
Socket
Sign inDemoInstall

locate-path

Package Overview
Dependencies
4
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

locate-path

Get the first path that exists on disk of multiple paths


Version published
Maintainers
1
Weekly downloads
112,037,009
decreased by-9.29%

Weekly downloads

Package description

What is locate-path?

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.

What are locate-path's main functionalities?

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'

Other packages similar to locate-path

Readme

Source

locate-path Build Status

Get the first path that exists on disk of multiple paths

Install

$ npm install --save locate-path

Usage

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'
];

locatePath(files).then(foundPath => {
	console.log(foundPath);
	//=> 'rainbow'
});

API

locatePath(input, [options])

Returns a Promise for the first path that exists or undefined if none exists.

input

Type: Iterable<string>

Paths to check.

options

Type: Object

concurrency

Type: number
Default: Infinity
Minimum: 1

Number of concurrently pending promises.

preserveOrder

Type: boolean
Default: true

Preserve input order when searching.

Disable this to improve performance if you don't care about the order.

cwd

Type: string
Default: process.cwd()

Current working directory.

locatePath.sync(input, [options])

Returns the first path that exists or undefined if none exists.

input

Type: Iterable<string>

Paths to check.

options

Type: Object

cwd

Same as above.

  • path-exists - Check if a path exists

License

MIT © Sindre Sorhus

Keywords

FAQs

Last updated on 28 Nov 2016

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.

Install

Related posts

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