Upgrade Ava to v4
This commit is contained in:
parent
9a40cc5274
commit
ce89f1b611
1153 changed files with 27264 additions and 95308 deletions
91
node_modules/p-locate/index.d.ts
generated
vendored
91
node_modules/p-locate/index.d.ts
generated
vendored
|
|
@ -1,64 +1,49 @@
|
|||
declare namespace pLocate {
|
||||
interface Options {
|
||||
/**
|
||||
Number of concurrently pending promises returned by `tester`. Minimum: `1`.
|
||||
export interface Options {
|
||||
/**
|
||||
The number of concurrently pending promises returned by `tester`.
|
||||
|
||||
@default Infinity
|
||||
*/
|
||||
readonly concurrency?: number;
|
||||
Minimum: `1`
|
||||
|
||||
/**
|
||||
Preserve `input` order when searching.
|
||||
@default Infinity
|
||||
*/
|
||||
readonly concurrency?: number;
|
||||
|
||||
Disable this to improve performance if you don't care about the order.
|
||||
/**
|
||||
Preserve `input` order when searching.
|
||||
|
||||
@default true
|
||||
*/
|
||||
readonly preserveOrder?: boolean;
|
||||
}
|
||||
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.
|
||||
/**
|
||||
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} from 'path-exists';
|
||||
import pLocate from '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));
|
||||
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;
|
||||
console.log(foundPath);
|
||||
//=> 'rainbow'
|
||||
```
|
||||
*/
|
||||
export default function pLocate<ValueType>(
|
||||
input: Iterable<PromiseLike<ValueType> | ValueType>,
|
||||
tester: (element: ValueType) => PromiseLike<boolean> | boolean,
|
||||
options?: Options
|
||||
): Promise<ValueType | undefined>;
|
||||
|
|
|
|||
36
node_modules/p-locate/index.js
generated
vendored
36
node_modules/p-locate/index.js
generated
vendored
|
|
@ -1,5 +1,4 @@
|
|||
'use strict';
|
||||
const pLimit = require('p-limit');
|
||||
import pLimit from 'p-limit';
|
||||
|
||||
class EndError extends Error {
|
||||
constructor(value) {
|
||||
|
|
@ -8,10 +7,10 @@ class EndError extends Error {
|
|||
}
|
||||
}
|
||||
|
||||
// The input can also be a promise, so we await it
|
||||
// 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
|
||||
// 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) {
|
||||
|
|
@ -21,20 +20,21 @@ const finder = async element => {
|
|||
return false;
|
||||
};
|
||||
|
||||
const pLocate = async (iterable, tester, options) => {
|
||||
options = {
|
||||
concurrency: Infinity,
|
||||
preserveOrder: true,
|
||||
...options
|
||||
};
|
||||
export default async function pLocate(
|
||||
iterable,
|
||||
tester,
|
||||
{
|
||||
concurrency = Number.POSITIVE_INFINITY,
|
||||
preserveOrder = true,
|
||||
} = {},
|
||||
) {
|
||||
const limit = pLimit(concurrency);
|
||||
|
||||
const limit = pLimit(options.concurrency);
|
||||
|
||||
// Start all the promises concurrently with optional limit
|
||||
// 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);
|
||||
// Check the promises either serially or concurrently.
|
||||
const checkLimit = pLimit(preserveOrder ? 1 : Number.POSITIVE_INFINITY);
|
||||
|
||||
try {
|
||||
await Promise.all(items.map(element => checkLimit(finder, element)));
|
||||
|
|
@ -45,8 +45,4 @@ const pLocate = async (iterable, tester, options) => {
|
|||
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = pLocate;
|
||||
// TODO: Remove this for the next major release
|
||||
module.exports.default = pLocate;
|
||||
}
|
||||
|
|
|
|||
2
node_modules/p-locate/license
generated
vendored
2
node_modules/p-locate/license
generated
vendored
|
|
@ -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:
|
||||
|
||||
|
|
|
|||
23
node_modules/p-locate/package.json
generated
vendored
23
node_modules/p-locate/package.json
generated
vendored
|
|
@ -1,16 +1,19 @@
|
|||
{
|
||||
"name": "p-locate",
|
||||
"version": "4.1.0",
|
||||
"version": "6.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"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": "./index.js",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
|
|
@ -40,14 +43,14 @@
|
|||
"bluebird"
|
||||
],
|
||||
"dependencies": {
|
||||
"p-limit": "^2.2.0"
|
||||
"p-limit": "^4.0.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"
|
||||
"ava": "^3.15.0",
|
||||
"delay": "^5.0.0",
|
||||
"in-range": "^3.0.0",
|
||||
"time-span": "^5.0.0",
|
||||
"tsd": "^0.17.0",
|
||||
"xo": "^0.44.0"
|
||||
}
|
||||
}
|
||||
43
node_modules/p-locate/readme.md
generated
vendored
43
node_modules/p-locate/readme.md
generated
vendored
|
|
@ -1,24 +1,22 @@
|
|||
# p-locate [](https://travis-ci.org/sindresorhus/p-locate)
|
||||
# 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');
|
||||
import {pathExists} from 'path-exists';
|
||||
import pLocate from 'p-locate';
|
||||
|
||||
const files = [
|
||||
'unicorn.png',
|
||||
|
|
@ -26,20 +24,17 @@ const files = [
|
|||
'pony.png'
|
||||
];
|
||||
|
||||
(async () => {
|
||||
const foundPath = await pLocate(files, file => pathExists(file));
|
||||
const foundPath = await pLocate(files, file => pathExists(file));
|
||||
|
||||
console.log(foundPath);
|
||||
//=> 'rainbow'
|
||||
})();
|
||||
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])
|
||||
### 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`.
|
||||
|
||||
|
|
@ -57,26 +52,25 @@ This function will receive resolved values from `input` and is expected to retur
|
|||
|
||||
#### options
|
||||
|
||||
Type: `Object`
|
||||
Type: `object`
|
||||
|
||||
##### concurrency
|
||||
|
||||
Type: `number`<br>
|
||||
Default: `Infinity`<br>
|
||||
Type: `number`\
|
||||
Default: `Infinity`\
|
||||
Minimum: `1`
|
||||
|
||||
Number of concurrently pending promises returned by `tester`.
|
||||
The number of concurrently pending promises returned by `tester`.
|
||||
|
||||
##### preserveOrder
|
||||
|
||||
Type: `boolean`<br>
|
||||
Type: `boolean`\
|
||||
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
|
||||
|
|
@ -84,7 +78,14 @@ Disable this to improve performance if you don't care about the order.
|
|||
- [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)
|
||||
<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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue