Installing dependencies.

This commit is contained in:
2025-11-11 06:53:11 -05:00
parent 2c36c04da6
commit 0d2fea3c88
14371 changed files with 2770923 additions and 25 deletions
+61
View File
@@ -0,0 +1,61 @@
import {Options as PMapOptions} from 'p-map';
declare namespace pFilter {
type Options = PMapOptions;
}
declare const pFilter: {
/**
Filter promises concurrently.
@param input - Iterated over concurrently in the `filterer` function.
@param filterer - The filterer function that decides whether an element should be included into result.
@example
```
import pFilter = require('p-filter');
import getWeather from 'get-weather'; // not a real module
const places = [
getCapital('Norway').then(info => info.name),
'Bangkok, Thailand',
'Berlin, Germany',
'Tokyo, Japan'
];
const filterer = async place => {
const weather = await getWeather(place);
return weather.temperature > 30;
};
(async () => {
const result = await pFilter(places, filterer);
console.log(result);
//=> ['Bangkok, Thailand']
})();
```
*/
<ValueType>(
input: Iterable<ValueType | PromiseLike<ValueType>>,
filterer: (
element: ValueType,
index: number
) => boolean | PromiseLike<boolean>,
options?: pFilter.Options
): Promise<ValueType[]>;
// TODO: Remove this for the next major release, refactor the whole definition to:
// declare function pFilter<ValueType>(
// input: Iterable<ValueType | PromiseLike<ValueType>>,
// filterer: (
// element: ValueType,
// index: number
// ) => boolean | PromiseLike<boolean>,
// options?: pFilter.Options
// ): Promise<ValueType[]>;
// export = pFilter;
default: typeof pFilter;
};
export = pFilter;
+15
View File
@@ -0,0 +1,15 @@
'use strict';
const pMap = require('p-map');
const pFilter = async (iterable, filterer, options) => {
const values = await pMap(
iterable,
(element, index) => Promise.all([filterer(element, index), element]),
options
);
return values.filter(value => Boolean(value[0])).map(value => value[1]);
};
module.exports = pFilter;
// TODO: Remove this for the next major release
module.exports.default = pFilter;
+9
View File
@@ -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.
+45
View File
@@ -0,0 +1,45 @@
{
"name": "p-filter",
"version": "2.1.0",
"description": "Filter promises concurrently",
"license": "MIT",
"repository": "sindresorhus/p-filter",
"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",
"filter",
"collection",
"iterable",
"iterator",
"fulfilled",
"async",
"await",
"promises",
"concurrently",
"concurrency",
"parallel",
"bluebird"
],
"dependencies": {
"p-map": "^2.0.0"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
+83
View File
@@ -0,0 +1,83 @@
# p-filter [![Build Status](https://travis-ci.org/sindresorhus/p-filter.svg?branch=master)](https://travis-ci.org/sindresorhus/p-filter)
> Filter promises concurrently
Useful when you need to run promise-returning & async functions multiple times with different inputs concurrently and get a filtered down result.
## Install
```
$ npm install p-filter
```
## Usage
```js
const pFilter = require('p-filter');
const getWeather = require('get-weather'); // not a real module
const places = [
getCapital('Norway').then(info => info.name),
'Bangkok, Thailand',
'Berlin, Germany',
'Tokyo, Japan'
];
const filterer = async place => {
const weather = await getWeather(place);
return weather.temperature > 30;
};
(async () => {
const result = await pFilter(places, filterer);
console.log(result);
//=> ['Bangkok, Thailand']
})();
```
## API
### pFilter(input, filterer, [options])
Returns a `Promise` that is fulfilled when all promises in `input` and ones returned from `filterer` are fulfilled, or rejects if any of the promises reject. The fulfilled value is an `Array` of the fulfilled values returned from `filterer` in `input` order.
#### input
Type: `Iterable<Promise|any>`
Iterated over concurrently in the `filterer` function.
#### filterer(element, index)
Type: `Function`
The filterer function that decides whether an element should be included into result. Expected to return `boolean | Promise<boolean>`.
#### options
Type: `Object`
##### concurrency
Type: `number`<br>
Default: `Infinity`<br>
Minimum: `1`
Number of concurrently pending promises returned by `filterer`.
## Related
- [p-locate](https://github.com/sindresorhus/p-locate) - Get the first fulfilled promise that satisfies the provided testing function
- [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently
- [p-times](https://github.com/sindresorhus/p-times) - Run promise-returning & async functions a specific number of times concurrently
- [More…](https://github.com/sindresorhus/promise-fun)
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)