Comparing version 3.0.0 to 4.0.0
@@ -1,46 +0,34 @@ | ||
import PCancelable = require('p-cancelable'); | ||
import { | ||
Options as PSomeOptions, | ||
AggregateError as PSomeAggregateError | ||
} from 'p-some'; | ||
import PCancelable from 'p-cancelable'; | ||
import {Options as PSomeOptions} from 'p-some'; | ||
declare namespace pAny { | ||
type Value<ValueType> = ValueType | PromiseLike<ValueType>; | ||
type Options<ValueType> = Omit<PSomeOptions<ValueType>, 'count'>; | ||
type CancelablePromise<ValueType> = PCancelable<ValueType>; | ||
type AggregateError = PSomeAggregateError; | ||
} | ||
export type Value<ValueType> = ValueType | PromiseLike<ValueType>; | ||
export type Options<ValueType> = Omit<PSomeOptions<ValueType>, 'count'>; // eslint-disable-line @typescript-eslint/ban-types | ||
export type CancelablePromise<ValueType> = PCancelable<ValueType>; | ||
declare const pAny: { | ||
/** | ||
Wait for any promise to be fulfilled. | ||
/** | ||
Wait for any promise to be fulfilled. | ||
@param input - An `Iterable` collection of promises/values to wait for. | ||
@returns A [cancelable `Promise`](https://github.com/sindresorhus/p-cancelable) that is fulfilled when any promise from `input` is fulfilled. If all the input promises reject, it will reject with an [`AggregateError`](https://github.com/sindresorhus/aggregate-error) error. | ||
@param input - An `Iterable` collection of promises/values to wait for. | ||
@returns A [cancelable `Promise`](https://github.com/sindresorhus/p-cancelable) that is fulfilled when any promise from `input` is fulfilled. If all the input promises reject, it will reject with an [`AggregateError`](https://github.com/sindresorhus/aggregate-error) error. | ||
@example | ||
``` | ||
import got = require('got'); | ||
import pAny = require('p-any'); | ||
@example | ||
``` | ||
import pAny from 'p-any'; | ||
import got from 'got'; | ||
(async () => { | ||
const first = await pAny([ | ||
got.head('https://github.com').then(() => 'github'), | ||
got.head('https://google.com').then(() => 'google'), | ||
got.head('https://twitter.com').then(() => 'twitter'), | ||
]); | ||
const first = await pAny([ | ||
got.head('https://github.com').then(() => 'github'), | ||
got.head('https://google.com').then(() => 'google'), | ||
got.head('https://twitter.com').then(() => 'twitter'), | ||
]); | ||
console.log(first); | ||
//=> 'google' | ||
})(); | ||
``` | ||
*/ | ||
<ValueType>( | ||
input: Iterable<pAny.Value<ValueType>>, | ||
options?: pAny.Options<ValueType> | ||
): pAny.CancelablePromise<ValueType>; | ||
console.log(first); | ||
//=> 'google' | ||
``` | ||
*/ | ||
export default function pAny<ValueType>( | ||
input: Iterable<Value<ValueType>>, | ||
options?: Options<ValueType> | ||
): CancelablePromise<ValueType>; | ||
AggregateError: typeof PSomeAggregateError; | ||
}; | ||
export = pAny; | ||
export {AggregateError} from 'p-some'; |
11
index.js
@@ -1,6 +0,5 @@ | ||
'use strict'; | ||
const pSome = require('p-some'); | ||
const PCancelable = require('p-cancelable'); | ||
import pSome from 'p-some'; | ||
import PCancelable from 'p-cancelable'; | ||
module.exports = (iterable, options) => { | ||
export default function pAny(iterable, options) { | ||
const anyCancelable = pSome(iterable, {...options, count: 1}); | ||
@@ -16,4 +15,4 @@ | ||
})(); | ||
}; | ||
} | ||
module.exports.AggregateError = pSome.AggregateError; | ||
export {AggregateError} from 'p-some'; |
{ | ||
"name": "p-any", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "Wait for any promise to be fulfilled", | ||
@@ -13,4 +13,6 @@ "license": "MIT", | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=12.20" | ||
}, | ||
@@ -43,11 +45,11 @@ "scripts": { | ||
"dependencies": { | ||
"p-cancelable": "^2.0.0", | ||
"p-some": "^5.0.0" | ||
"p-cancelable": "^3.0.0", | ||
"p-some": "^6.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"delay": "^4.1.0", | ||
"tsd": "^0.11.0", | ||
"xo": "^0.26.1" | ||
"ava": "^3.15.0", | ||
"delay": "^5.0.0", | ||
"tsd": "^0.16.0", | ||
"xo": "^0.40.1" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# p-any [![Build Status](https://travis-ci.org/sindresorhus/p-any.svg?branch=master)](https://travis-ci.org/sindresorhus/p-any) | ||
# p-any | ||
@@ -9,2 +9,4 @@ > Wait for any promise to be fulfilled | ||
*With [Node.js 15](https://medium.com/@nodejs/node-js-v15-0-0-is-here-deb00750f278), there's now a built-in [`Promise#any`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any) method. The benefit of this package is that it has cancellation functionality.* | ||
## Install | ||
@@ -21,15 +23,13 @@ | ||
```js | ||
const got = require('got'); | ||
const pAny = require('p-any'); | ||
import pAny from 'p-any'; | ||
import got from 'got'; | ||
(async () => { | ||
const first = await pAny([ | ||
got.head('https://github.com').then(() => 'github'), | ||
got.head('https://google.com').then(() => 'google'), | ||
got.head('https://twitter.com').then(() => 'twitter'), | ||
]); | ||
const first = await pAny([ | ||
got.head('https://github.com').then(() => 'github'), | ||
got.head('https://google.com').then(() => 'google'), | ||
got.head('https://twitter.com').then(() => 'twitter'), | ||
]); | ||
console.log(first); | ||
//=> 'google' | ||
})(); | ||
console.log(first); | ||
//=> 'google' | ||
``` | ||
@@ -45,3 +45,3 @@ | ||
Type: `Iterable<Promise|any>` | ||
Type: `Iterable<Promise | unknown>` | ||
@@ -58,3 +58,3 @@ #### options | ||
### pAny.AggregateError | ||
### AggregateError | ||
@@ -61,0 +61,0 @@ Exposed for instance checking. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5395
Yes
40
+ Addedaggregate-error@4.0.1(transitive)
+ Addedclean-stack@4.2.0(transitive)
+ Addedescape-string-regexp@5.0.0(transitive)
+ Addedindent-string@5.0.0(transitive)
+ Addedp-cancelable@3.0.0(transitive)
+ Addedp-some@6.0.0(transitive)
- Removedaggregate-error@3.1.0(transitive)
- Removedclean-stack@2.2.0(transitive)
- Removedindent-string@4.0.0(transitive)
- Removedp-cancelable@2.1.1(transitive)
- Removedp-some@5.0.0(transitive)
Updatedp-cancelable@^3.0.0
Updatedp-some@^6.0.0