Socket
Socket
Sign inDemoInstall

find-up

Package Overview
Dependencies
5
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.0 to 4.1.0

94

index.d.ts

@@ -24,8 +24,8 @@ import {Options as LocatePathOptions} from 'locate-path';

// └── Users
// └── sindresorhus
// ├── unicorn.png
// └── foo
// └── bar
// ├── baz
// └── example.js
// └── sindresorhus
// ├── unicorn.png
// └── foo
// └── bar
// ├── baz
// └── example.js

@@ -51,20 +51,82 @@ // example.js

@returns The first path found or `undefined` if none could be found.
@example
```
import path = require('path');
import findUp = require('find-up');
(async () => {
console.log(await findUp(async directory => {
const hasUnicorns = await findUp.exists(path.join(directory, 'unicorn.png'));
return hasUnicorns && directory;
}, {type: 'directory'}));
//=> '/Users/sindresorhus'
})();
```
*/
(matcher: (directory: string) => (findUp.Match | Promise<findUp.Match>), options?: findUp.Options): Promise<string | undefined>;
/**
Synchronously find a file or directory by walking up parent directories.
sync: {
/**
Synchronously find a file or directory by walking up parent directories.
@param name - Name of the file or directory to find. Can be multiple.
@returns The first path found (by respecting the order of `name`s) or `undefined` if none could be found.
*/
sync(name: string | string[], options?: findUp.Options): string | undefined;
@param name - Name of the file or directory to find. Can be multiple.
@returns The first path found (by respecting the order of `name`s) or `undefined` if none could be found.
*/
(name: string | string[], options?: findUp.Options): string | undefined;
/**
Synchronously find a file or directory by walking up parent directories.
@param matcher - Called for each directory in the search. Return a path or `findUp.stop` to stop the search.
@returns The first path found or `undefined` if none could be found.
@example
```
import path = require('path');
import findUp = require('find-up');
console.log(findUp.sync(directory => {
const hasUnicorns = findUp.sync.exists(path.join(directory, 'unicorn.png'));
return hasUnicorns && directory;
}, {type: 'directory'}));
//=> '/Users/sindresorhus'
```
*/
(matcher: (directory: string) => findUp.Match, options?: findUp.Options): string | undefined;
/**
Synchronously check if a path exists.
@param path - Path to the file or directory.
@returns Whether the path exists.
@example
```
import findUp = require('find-up');
console.log(findUp.sync.exists('/Users/sindresorhus/unicorn.png'));
//=> true
```
*/
exists(path: string): boolean;
}
/**
Synchronously find a file or directory by walking up parent directories.
Check if a path exists.
@param matcher - Called for each directory in the search. Return a path or `findUp.stop` to stop the search.
@returns The first path found or `undefined` if none could be found.
@param path - Path to a file or directory.
@returns Whether the path exists.
@example
```
import findUp = require('find-up');
(async () => {
console.log(await findUp.exists('/Users/sindresorhus/unicorn.png'));
//=> true
})();
```
*/
sync(matcher: (directory: string) => findUp.Match, options?: findUp.Options): string | undefined;
exists(path: string): Promise<boolean>;

@@ -71,0 +133,0 @@ /**

'use strict';
const path = require('path');
const locatePath = require('locate-path');
const pathExists = require('path-exists');

@@ -84,2 +85,6 @@ const stop = Symbol('findUp.stop');

module.exports.exists = pathExists;
module.exports.sync.exists = pathExists.sync;
module.exports.stop = stop;

7

package.json
{
"name": "find-up",
"version": "4.0.0",
"version": "4.1.0",
"description": "Find a file or directory by walking up parent directories",

@@ -43,6 +43,7 @@ "license": "MIT",

"dependencies": {
"locate-path": "^5.0.0"
"locate-path": "^5.0.0",
"path-exists": "^4.0.0"
},
"devDependencies": {
"ava": "^1.4.1",
"ava": "^2.1.0",
"is-path-inside": "^2.1.0",

@@ -49,0 +50,0 @@ "tempy": "^0.3.0",

@@ -5,16 +5,3 @@ # find-up [![Build Status](https://travis-ci.org/sindresorhus/find-up.svg?branch=master)](https://travis-ci.org/sindresorhus/find-up)

---
<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-find-up?utm_source=npm-find-up&utm_medium=referral&utm_campaign=readme">Get professional support for 'find-up' with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>
---
## Install

@@ -32,8 +19,8 @@

└── Users
└── sindresorhus
├── unicorn.png
└── foo
└── bar
├── baz
└── example.js
└── sindresorhus
├── unicorn.png
└── foo
└── bar
├── baz
└── example.js
```

@@ -44,3 +31,2 @@

```js
const fs = require('fs');
const path = require('path');

@@ -56,7 +42,6 @@ const findUp = require('find-up');

const pathExists = filePath => fs.promises.access(filePath).then(_ => true).catch(_ => false);
console.log(await findUp(async directory => {
const hasUnicorns = await pathExists(path.join(directory, 'unicorn.png'));
const hasUnicorns = await findUp.exists(path.join(directory, 'unicorn.png'));
return hasUnicorns && directory;
}}, {type: 'directory'});
}, {type: 'directory'}));
//=> '/Users/sindresorhus'

@@ -69,19 +54,19 @@ })();

### findUp(name, [options])
### findUp(matcher, [options])
### findUp(name, options?)
### findUp(matcher, options?)
Returns a `Promise` for either the path or `undefined` if it couldn't be found.
### findUp([nameA, nameB], [options])
### findUp([...name], options?)
Returns a `Promise` for either the first path found (by respecting the order) or `undefined` if none could be found.
Returns a `Promise` for either the first path found (by respecting the order of the array) or `undefined` if none could be found.
### findUp.sync(name, [options])
### findUp.sync(matcher, [options])
### findUp.sync(name, options?)
### findUp.sync(matcher, options?)
Returns a path or `undefined` if it couldn't be found.
### findUp.sync([nameA, nameB], [options])
### findUp.sync([...name], options?)
Returns the first path found (by respecting the order) or `undefined` if none could be found.
Returns the first path found (by respecting the order of the array) or `undefined` if none could be found.

@@ -98,3 +83,3 @@ #### name

A function that will be called with each directory until it returns a `string` with the path, which stops the search, or the root directory has been reached and nothing was found. Useful if you want to match files with certain patterns, set of permissions, or other advanced use cases.
A function that will be called with each directory until it returns a `string` with the path, which stops the search, or the root directory has been reached and nothing was found. Useful if you want to match files with certain patterns, set of permissions, or other advanced use-cases.

@@ -117,4 +102,4 @@ When using async mode, the `matcher` may optionally be an async or promise-returning function that returns the path.

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

@@ -130,2 +115,16 @@ The type of paths that can match.

### findUp.exists(path)
Returns a `Promise<boolean>` of whether the path exists.
### findUp.sync.exists(path)
Returns a `boolean` of whether the path exists.
#### path
Type: `string`
Path to a file or directory.
### findUp.stop

@@ -147,7 +146,2 @@

## Security
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
## Related

@@ -161,4 +155,12 @@

## License
---
MIT © [Sindre Sorhus](https://sindresorhus.com)
<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-find-up?utm_source=npm-find-up&utm_medium=referral&utm_campaign=readme">Get professional support for 'find-up' with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>
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