aboutsummaryrefslogtreecommitdiff
path: root/node_modules/p-locate
diff options
context:
space:
mode:
authorJoel Kronqvist <work.joelkronqvist@pm.me>2022-03-11 20:46:06 +0200
committerJoel Kronqvist <work.joelkronqvist@pm.me>2022-03-11 20:46:06 +0200
commit080c5819d87b933816d724a83f3bf4f1686770a7 (patch)
tree4a2ccc68b27edf7d4cbc586c932cc7542b655e19 /node_modules/p-locate
parent5ac7049a9d30733165cc212dee308163c2a14644 (diff)
parentd003b82235a9329f912522a2f70aa950dfce4998 (diff)
downloadLYLLRuoka-080c5819d87b933816d724a83f3bf4f1686770a7.tar.gz
LYLLRuoka-080c5819d87b933816d724a83f3bf4f1686770a7.zip
Merge branch 'master' of https://github.com/JoelHMikael/FoodJS
Updating remote changes
Diffstat (limited to 'node_modules/p-locate')
-rw-r--r--node_modules/p-locate/index.d.ts64
-rw-r--r--node_modules/p-locate/index.js52
-rw-r--r--node_modules/p-locate/license9
-rw-r--r--node_modules/p-locate/package.json53
-rw-r--r--node_modules/p-locate/readme.md90
5 files changed, 268 insertions, 0 deletions
diff --git a/node_modules/p-locate/index.d.ts b/node_modules/p-locate/index.d.ts
new file mode 100644
index 0000000..14115e1
--- /dev/null
+++ b/node_modules/p-locate/index.d.ts
@@ -0,0 +1,64 @@
+declare namespace pLocate {
+ interface Options {
+ /**
+ Number of concurrently pending promises returned by `tester`. Minimum: `1`.
+
+ @default Infinity
+ */
+ readonly concurrency?: number;
+
+ /**
+ Preserve `input` order when searching.
+
+ Disable this to improve performance if you don't care about the order.
+
+ @default true
+ */
+ readonly preserveOrder?: boolean;
+ }
+}
+
+declare const pLocate: {
+ /**
+ 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`.
+
+ @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'
+ ];
+
+ (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>;
+
+ // 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;
diff --git a/node_modules/p-locate/index.js b/node_modules/p-locate/index.js
new file mode 100644
index 0000000..e13ce15
--- /dev/null
+++ b/node_modules/p-locate/index.js
@@ -0,0 +1,52 @@
+'use strict';
+const pLimit = require('p-limit');
+
+class EndError extends Error {
+ constructor(value) {
+ super();
+ this.value = value;
+ }
+}
+
+// The input can also be a promise, so we await it
+const testElement = async (element, tester) => tester(await element);
+
+// The input can also be a promise, so we `Promise.all()` them both
+const finder = async element => {
+ const values = await Promise.all(element);
+ if (values[1] === true) {
+ throw new EndError(values[0]);
+ }
+
+ return false;
+};
+
+const pLocate = async (iterable, tester, options) => {
+ options = {
+ concurrency: Infinity,
+ preserveOrder: true,
+ ...options
+ };
+
+ const limit = pLimit(options.concurrency);
+
+ // Start all the promises concurrently with optional limit
+ const items = [...iterable].map(element => [element, limit(testElement, element, tester)]);
+
+ // Check the promises either serially or concurrently
+ const checkLimit = pLimit(options.preserveOrder ? 1 : Infinity);
+
+ try {
+ await Promise.all(items.map(element => checkLimit(finder, element)));
+ } catch (error) {
+ if (error instanceof EndError) {
+ return error.value;
+ }
+
+ throw error;
+ }
+};
+
+module.exports = pLocate;
+// TODO: Remove this for the next major release
+module.exports.default = pLocate;
diff --git a/node_modules/p-locate/license b/node_modules/p-locate/license
new file mode 100644
index 0000000..e7af2f7
--- /dev/null
+++ b/node_modules/p-locate/license
@@ -0,0 +1,9 @@
+MIT License
+
+Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/node_modules/p-locate/package.json b/node_modules/p-locate/package.json
new file mode 100644
index 0000000..e3de275
--- /dev/null
+++ b/node_modules/p-locate/package.json
@@ -0,0 +1,53 @@
+{
+ "name": "p-locate",
+ "version": "4.1.0",
+ "description": "Get the first fulfilled promise that satisfies the provided testing function",
+ "license": "MIT",
+ "repository": "sindresorhus/p-locate",
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus@gmail.com",
+ "url": "sindresorhus.com"
+ },
+ "engines": {
+ "node": ">=8"
+ },
+ "scripts": {
+ "test": "xo && ava && tsd"
+ },
+ "files": [
+ "index.js",
+ "index.d.ts"
+ ],
+ "keywords": [
+ "promise",
+ "locate",
+ "find",
+ "finder",
+ "search",
+ "searcher",
+ "test",
+ "array",
+ "collection",
+ "iterable",
+ "iterator",
+ "race",
+ "fulfilled",
+ "fastest",
+ "async",
+ "await",
+ "promises",
+ "bluebird"
+ ],
+ "dependencies": {
+ "p-limit": "^2.2.0"
+ },
+ "devDependencies": {
+ "ava": "^1.4.1",
+ "delay": "^4.1.0",
+ "in-range": "^1.0.0",
+ "time-span": "^3.0.0",
+ "tsd": "^0.7.2",
+ "xo": "^0.24.0"
+ }
+}
diff --git a/node_modules/p-locate/readme.md b/node_modules/p-locate/readme.md
new file mode 100644
index 0000000..f8e2c2e
--- /dev/null
+++ b/node_modules/p-locate/readme.md
@@ -0,0 +1,90 @@
+# p-locate [![Build Status](https://travis-ci.org/sindresorhus/p-locate.svg?branch=master)](https://travis-ci.org/sindresorhus/p-locate)
+
+> Get the first fulfilled promise that satisfies the provided testing function
+
+Think of it like an async version of [`Array#find`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/find).
+
+
+## Install
+
+```
+$ npm install p-locate
+```
+
+
+## Usage
+
+Here we find the first file that exists on disk, in array order.
+
+```js
+const pathExists = require('path-exists');
+const pLocate = require('p-locate');
+
+const files = [
+ 'unicorn.png',
+ 'rainbow.png', // Only this one actually exists on disk
+ 'pony.png'
+];
+
+(async () => {
+ const foundPath = await pLocate(files, file => pathExists(file));
+
+ console.log(foundPath);
+ //=> 'rainbow'
+})();
+```
+
+*The above is just an example. Use [`locate-path`](https://github.com/sindresorhus/locate-path) if you need this.*
+
+
+## API
+
+### pLocate(input, tester, [options])
+
+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`.
+
+#### input
+
+Type: `Iterable<Promise | unknown>`
+
+An iterable of promises/values to test.
+
+#### tester(element)
+
+Type: `Function`
+
+This function will receive resolved values from `input` and is expected to return a `Promise<boolean>` or `boolean`.
+
+#### options
+
+Type: `Object`
+
+##### concurrency
+
+Type: `number`<br>
+Default: `Infinity`<br>
+Minimum: `1`
+
+Number of concurrently pending promises returned by `tester`.
+
+##### preserveOrder
+
+Type: `boolean`<br>
+Default: `true`
+
+Preserve `input` order when searching.
+
+Disable this to improve performance if you don't care about the order.
+
+
+## Related
+
+- [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently
+- [p-filter](https://github.com/sindresorhus/p-filter) - Filter promises concurrently
+- [p-any](https://github.com/sindresorhus/p-any) - Wait for any promise to be fulfilled
+- [More…](https://github.com/sindresorhus/promise-fun)
+
+
+## License
+
+MIT © [Sindre Sorhus](https://sindresorhus.com)