source: imaps-frontend/node_modules/p-locate/readme.md@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.5 KB
Line 
1# p-locate [![Build Status](https://travis-ci.com/sindresorhus/p-locate.svg?branch=master)](https://travis-ci.com/github/sindresorhus/p-locate)
2
3> Get the first fulfilled promise that satisfies the provided testing function
4
5Think of it like an async version of [`Array#find`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/find).
6
7## Install
8
9```
10$ npm install p-locate
11```
12
13## Usage
14
15Here we find the first file that exists on disk, in array order.
16
17```js
18const pathExists = require('path-exists');
19const pLocate = require('p-locate');
20
21const files = [
22 'unicorn.png',
23 'rainbow.png', // Only this one actually exists on disk
24 'pony.png'
25];
26
27(async () => {
28 const foundPath = await pLocate(files, file => pathExists(file));
29
30 console.log(foundPath);
31 //=> 'rainbow'
32})();
33```
34
35*The above is just an example. Use [`locate-path`](https://github.com/sindresorhus/locate-path) if you need this.*
36
37## API
38
39### pLocate(input, tester, options?)
40
41Returns 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`.
42
43#### input
44
45Type: `Iterable<Promise | unknown>`
46
47An iterable of promises/values to test.
48
49#### tester(element)
50
51Type: `Function`
52
53This function will receive resolved values from `input` and is expected to return a `Promise<boolean>` or `boolean`.
54
55#### options
56
57Type: `object`
58
59##### concurrency
60
61Type: `number`\
62Default: `Infinity`\
63Minimum: `1`
64
65Number of concurrently pending promises returned by `tester`.
66
67##### preserveOrder
68
69Type: `boolean`\
70Default: `true`
71
72Preserve `input` order when searching.
73
74Disable this to improve performance if you don't care about the order.
75
76## Related
77
78- [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently
79- [p-filter](https://github.com/sindresorhus/p-filter) - Filter promises concurrently
80- [p-any](https://github.com/sindresorhus/p-any) - Wait for any promise to be fulfilled
81- [More…](https://github.com/sindresorhus/promise-fun)
82
83---
84
85<div align="center">
86 <b>
87 <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>
88 </b>
89 <br>
90 <sub>
91 Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
92 </sub>
93</div>
Note: See TracBrowser for help on using the repository browser.