Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

p-filter

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-filter - npm Package Compare versions

Comparing version 2.1.0 to 3.0.0

86

index.d.ts

@@ -1,61 +0,41 @@

import {Options as PMapOptions} from 'p-map';
import {Options} from 'p-map';
declare namespace pFilter {
type Options = PMapOptions;
}
/**
Filter promises concurrently.
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.
@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 from 'p-filter';
import getWeather from 'get-weather'; // Not a real module
@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 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;
};
const filterer = async place => {
const weather = await getWeather(place);
return weather.temperature > 30;
};
const result = await pFilter(places, filterer);
(async () => {
const result = await pFilter(places, filterer);
console.log(result);
//=> ['Bangkok, Thailand']
```
*/
export default function pFilter<ValueType>(
input: Iterable<ValueType | PromiseLike<ValueType>>,
filterer: (
element: ValueType,
index: number
) => boolean | PromiseLike<boolean>,
options?: Options
): Promise<ValueType[]>;
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;
export {Options} from 'p-map';

@@ -1,15 +0,11 @@

'use strict';
const pMap = require('p-map');
import pMap from 'p-map';
const pFilter = async (iterable, filterer, options) => {
export default async function pFilter(iterable, filterer, options) {
const values = await pMap(
iterable,
(element, index) => Promise.all([filterer(element, index), element]),
options
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;
}
{
"name": "p-filter",
"version": "2.1.0",
"version": "3.0.0",
"description": "Filter promises concurrently",
"license": "MIT",
"repository": "sindresorhus/p-filter",
"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"
},

@@ -38,9 +41,9 @@ "scripts": {

"dependencies": {
"p-map": "^2.0.0"
"p-map": "^5.1.0"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^3.15.0",
"tsd": "^0.17.0",
"xo": "^0.44.0"
}
}

@@ -1,2 +0,2 @@

# p-filter [![Build Status](https://travis-ci.org/sindresorhus/p-filter.svg?branch=master)](https://travis-ci.org/sindresorhus/p-filter)
# p-filter

@@ -7,3 +7,2 @@ > Filter promises concurrently

## Install

@@ -15,8 +14,7 @@

## Usage
```js
const pFilter = require('p-filter');
const getWeather = require('get-weather'); // not a real module
import pFilter from 'p-filter';
import getWeather from 'get-weather'; // Not a real module

@@ -27,3 +25,3 @@ const places = [

'Berlin, Germany',
'Tokyo, Japan'
'Tokyo, Japan',
];

@@ -36,14 +34,11 @@

(async () => {
const result = await pFilter(places, filterer);
const result = await pFilter(places, filterer);
console.log(result);
//=> ['Bangkok, Thailand']
})();
console.log(result);
//=> ['Bangkok, Thailand']
```
## API
### pFilter(input, filterer, [options])
### pFilter(input, filterer, options?)

@@ -66,13 +61,12 @@ 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.

Type: `Object`
Type: `object`
##### concurrency
Type: `number`<br>
Default: `Infinity`<br>
Type: `number`\
Default: `Infinity`\
Minimum: `1`
Number of concurrently pending promises returned by `filterer`.
The number of concurrently pending promises returned by `filterer`.
## Related

@@ -84,6 +78,1 @@

- [More…](https://github.com/sindresorhus/promise-fun)
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc