p-locate
Advanced tools
Comparing version 4.1.0 to 5.0.0
@@ -21,45 +21,34 @@ declare namespace pLocate { | ||
declare const pLocate: { | ||
/** | ||
Get the first fulfilled promise that satisfies the provided testing function. | ||
/** | ||
Get the first fulfilled promise that satisfies the provided testing function. | ||
@param input - An iterable of promises/values to test. | ||
@param tester - This function will receive resolved values from `input` and is expected to return a `Promise<boolean>` or `boolean`. | ||
@returns A `Promise` that is fulfilled when `tester` resolves to `true` or the iterable is done, or rejects if any of the promises reject. The fulfilled value is the current iterable value or `undefined` if `tester` never resolved to `true`. | ||
@param input - An iterable of promises/values to test. | ||
@param tester - This function will receive resolved values from `input` and is expected to return a `Promise<boolean>` or `boolean`. | ||
@returns A `Promise` that is fulfilled when `tester` resolves to `true` or the iterable is done, or rejects if any of the promises reject. The fulfilled value is the current iterable value or `undefined` if `tester` never resolved to `true`. | ||
@example | ||
``` | ||
import pathExists = require('path-exists'); | ||
import pLocate = require('p-locate'); | ||
@example | ||
``` | ||
import pathExists = require('path-exists'); | ||
import pLocate = require('p-locate'); | ||
const files = [ | ||
'unicorn.png', | ||
'rainbow.png', // Only this one actually exists on disk | ||
'pony.png' | ||
]; | ||
const files = [ | ||
'unicorn.png', | ||
'rainbow.png', // Only this one actually exists on disk | ||
'pony.png' | ||
]; | ||
(async () => { | ||
const foundPath = await pLocate(files, file => pathExists(file)); | ||
(async () => { | ||
const foundPath = await pLocate(files, file => pathExists(file)); | ||
console.log(foundPath); | ||
//=> 'rainbow' | ||
})(); | ||
``` | ||
*/ | ||
<ValueType>( | ||
input: Iterable<PromiseLike<ValueType> | ValueType>, | ||
tester: (element: ValueType) => PromiseLike<boolean> | boolean, | ||
options?: pLocate.Options | ||
): Promise<ValueType | undefined>; | ||
console.log(foundPath); | ||
//=> 'rainbow' | ||
})(); | ||
``` | ||
*/ | ||
declare function pLocate<ValueType>( | ||
input: Iterable<PromiseLike<ValueType> | ValueType>, | ||
tester: (element: ValueType) => PromiseLike<boolean> | boolean, | ||
options?: pLocate.Options | ||
): Promise<ValueType | undefined>; | ||
// TODO: Remove this for the next major release, refactor the whole definition to: | ||
// declare function pLocate<ValueType>( | ||
// input: Iterable<PromiseLike<ValueType> | ValueType>, | ||
// tester: (element: ValueType) => PromiseLike<boolean> | boolean, | ||
// options?: pLocate.Options | ||
// ): Promise<ValueType | undefined>; | ||
// export = pLocate; | ||
default: typeof pLocate; | ||
}; | ||
export = pLocate; |
@@ -51,3 +51,1 @@ 'use strict'; | ||
module.exports = pLocate; | ||
// TODO: Remove this for the next major release | ||
module.exports.default = pLocate; |
{ | ||
"name": "p-locate", | ||
"version": "4.1.0", | ||
"version": "5.0.0", | ||
"description": "Get the first fulfilled promise that satisfies the provided testing function", | ||
"license": "MIT", | ||
"repository": "sindresorhus/p-locate", | ||
"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" | ||
}, | ||
@@ -43,12 +44,12 @@ "scripts": { | ||
"dependencies": { | ||
"p-limit": "^2.2.0" | ||
"p-limit": "^3.0.2" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"ava": "^2.4.0", | ||
"delay": "^4.1.0", | ||
"in-range": "^1.0.0", | ||
"time-span": "^3.0.0", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
"in-range": "^2.0.0", | ||
"time-span": "^4.0.0", | ||
"tsd": "^0.13.1", | ||
"xo": "^0.32.1" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# p-locate [![Build Status](https://travis-ci.org/sindresorhus/p-locate.svg?branch=master)](https://travis-ci.org/sindresorhus/p-locate) | ||
# p-locate [![Build Status](https://travis-ci.com/sindresorhus/p-locate.svg?branch=master)](https://travis-ci.com/github/sindresorhus/p-locate) | ||
@@ -7,3 +7,2 @@ > Get the first fulfilled promise that satisfies the provided testing function | ||
## Install | ||
@@ -15,3 +14,2 @@ | ||
## Usage | ||
@@ -41,6 +39,5 @@ | ||
## API | ||
### pLocate(input, tester, [options]) | ||
### pLocate(input, tester, options?) | ||
@@ -63,8 +60,8 @@ Returns a `Promise` that is fulfilled when `tester` resolves to `true` or the iterable is done, or rejects if any of the promises reject. The fulfilled value is the current iterable value or `undefined` if `tester` never resolved to `true`. | ||
Type: `Object` | ||
Type: `object` | ||
##### concurrency | ||
Type: `number`<br> | ||
Default: `Infinity`<br> | ||
Type: `number`\ | ||
Default: `Infinity`\ | ||
Minimum: `1` | ||
@@ -76,3 +73,3 @@ | ||
Type: `boolean`<br> | ||
Type: `boolean`\ | ||
Default: `true` | ||
@@ -84,3 +81,2 @@ | ||
## Related | ||
@@ -93,5 +89,12 @@ | ||
--- | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) | ||
<div align="center"> | ||
<b> | ||
<a href="https://tidelift.com/subscription/pkg/npm-p-locate?utm_source=npm-p-locate&utm_medium=referral&utm_campaign=readme">Get professional support for this package 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> |
Sorry, the diff of this file is not supported yet
94
7240
81
+ Addedp-limit@3.1.0(transitive)
+ Addedyocto-queue@0.1.0(transitive)
- Removedp-limit@2.3.0(transitive)
- Removedp-try@2.2.0(transitive)
Updatedp-limit@^3.0.2