Skip to content

Commit

Permalink
Require Node.js 10
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Aug 10, 2020
1 parent 2e0d9bf commit b358273
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,5 +1,5 @@
language: node_js
node_js:
- '14'
- '12'
- '10'
- '8'
24 changes: 12 additions & 12 deletions index.d.ts
Expand Up @@ -42,6 +42,17 @@ declare namespace locatePath {
}

declare const locatePath: {
/**
Synchronously get the first path that exists on disk of multiple paths.
@param paths - Paths to check.
@returns The first path that exists or `undefined` if none exists.
*/
sync: (
paths: Iterable<string>,
options?: locatePath.Options
) => string | undefined;

/**
Get the first path that exists on disk of multiple paths.
Expand All @@ -65,19 +76,8 @@ declare const locatePath: {
```
*/
(paths: Iterable<string>, options?: locatePath.AsyncOptions): Promise<
string | undefined
string | undefined
>;

/**
Synchronously get the first path that exists on disk of multiple paths.
@param paths - Paths to check.
@returns The first path that exists or `undefined` if none exists.
*/
sync(
paths: Iterable<string>,
options?: locatePath.Options
): string | undefined;
};

export = locatePath;
9 changes: 6 additions & 3 deletions index.js
Expand Up @@ -29,14 +29,16 @@ module.exports = async (paths, options) => {
allowSymlinks: true,
...options
};

checkType(options);

const statFn = options.allowSymlinks ? fsStat : fsLStat;

return pLocate(paths, async path_ => {
try {
const stat = await statFn(path.resolve(options.cwd, path_));
return matchType(options.type, stat);
} catch (_) {
} catch {
return false;
}
}, options);
Expand All @@ -49,7 +51,9 @@ module.exports.sync = (paths, options) => {
type: 'file',
...options
};

checkType(options);

const statFn = options.allowSymlinks ? fs.statSync : fs.lstatSync;

for (const path_ of paths) {
Expand All @@ -59,7 +63,6 @@ module.exports.sync = (paths, options) => {
if (matchType(options.type, stat)) {
return path_;
}
} catch (_) {
}
} catch {}
}
};
2 changes: 1 addition & 1 deletion license
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
13 changes: 7 additions & 6 deletions package.json
Expand Up @@ -4,13 +4,14 @@
"description": "Get the first path that exists on disk of multiple paths",
"license": "MIT",
"repository": "sindresorhus/locate-path",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=8"
"node": ">=10"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -35,11 +36,11 @@
"iterator"
],
"dependencies": {
"p-locate": "^4.1.0"
"p-locate": "^5.0.0"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^2.4.0",
"tsd": "^0.13.1",
"xo": "^0.32.1"
}
}
25 changes: 10 additions & 15 deletions readme.md
@@ -1,15 +1,13 @@
# locate-path [![Build Status](https://travis-ci.org/sindresorhus/locate-path.svg?branch=master)](https://travis-ci.org/sindresorhus/locate-path)
# locate-path [![Build Status](https://travis-ci.com/sindresorhus/locate-path.svg?branch=master)](https://travis-ci.com/github/sindresorhus/locate-path)

> Get the first path that exists on disk of multiple paths

## Install

```
$ npm install locate-path
```


## Usage

Here we find the first file that exists on disk, in array order.
Expand All @@ -29,7 +27,6 @@ const files = [
})();
```


## API

### locatePath(paths, options?)
Expand All @@ -48,15 +45,15 @@ Type: `object`

##### concurrency

Type: `number`<br>
Default: `Infinity`<br>
Type: `number`\
Default: `Infinity`\
Minimum: `1`

Number of concurrently pending promises.

##### preserveOrder

Type: `boolean`<br>
Type: `boolean`\
Default: `true`

Preserve `paths` order when searching.
Expand All @@ -65,27 +62,27 @@ Disable this to improve performance if you don't care about the order.

##### cwd

Type: `string`<br>
Type: `string`\
Default: `process.cwd()`

Current working directory.

##### type

Type: `string`<br>
Default: `'file'`<br>
Values: `'file'` `'directory'`
Type: `string`\
Default: `'file'`\
Values: `'file' | 'directory'`

The type of paths that can match.

##### allowSymlinks

Type: `boolean`<br>
Type: `boolean`\
Default: `true`

Allow symbolic links to match if they point to the chosen path type.

### locatePath.sync(paths, [options])
### locatePath.sync(paths, options?)

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

Expand All @@ -111,12 +108,10 @@ Same as above.

Same as above.


## Related

- [path-exists](https://github.com/sindresorhus/path-exists) - Check if a path exists


---

<div align="center">
Expand Down

0 comments on commit b358273

Please sign in to comment.