{"name":"p-filter","version":"4.1.0","description":"Filter promises concurrently","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-filter.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"test":"xo && ava && tsd"},"keywords":["promise","filter","collection","iterable","iterator","fulfilled","async","await","promises","concurrently","concurrency","parallel"],"dependencies":{"p-map":"^7.0.1"},"devDependencies":{"ava":"^6.0.1","tsd":"^0.30.1","xo":"^0.56.0"},"types":"./index.d.ts","gitHead":"ec5496d1ce853addb6a003652565c9223ea51fba","bugs":{"url":"https://github.com/sindresorhus/p-filter/issues"},"homepage":"https://github.com/sindresorhus/p-filter#readme","_id":"p-filter@4.1.0","_nodeVersion":"21.2.0","_npmVersion":"9.2.0","dist":{"integrity":"sha512-37/tPdZ3oJwHaS3gNJdenCDB3Tz26i9sjhnguBtvN0vYlRIiDNnvTWkuh+0hETV9rLPdJ3rlL3yVOYPIAnM8rw==","shasum":"fe0aa794e2dfad8ecf595a39a245484fcd09c6e4","tarball":"http://registry-npm.ywwl.com/p-filter/download/p-filter-4.1.0.tgz","fileCount":5,"unpackedSize":8173,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIArNAt1+2GTqxBodqqAQ5TkGX/a3RyQNiMCwt/708YjuAiB6lKCxn5JLEqOrW3qSTlhrvVRHsEX6PBVlkgG7fmnQUQ=="}],"size":2676,"noattachment":false,"key":"/p-filter/-/p-filter-4.1.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-filter_4.1.0_1703692976091_0.9156248707343033"},"_hasShrinkwrap":false,"readme":"# p-filter\n\n> Filter promises concurrently\n\nUseful when you need to run promise-returning & async functions multiple times with different inputs concurrently and get a filtered down result.\n\n## Install\n\n```sh\nnpm install p-filter\n```\n\n## Usage\n\n```js\nimport pFilter from 'p-filter';\nimport getWeather from 'get-weather'; // Not a real module\n\nconst places = [\n\tgetCapital('Norway').then(info => info.name),\n\t'Bangkok, Thailand',\n\t'Berlin, Germany',\n\t'Tokyo, Japan',\n];\n\nconst filterer = async place => {\n\tconst weather = await getWeather(place);\n\treturn weather.temperature > 30;\n};\n\nconst result = await pFilter(places, filterer);\n\nconsole.log(result);\n//=> ['Bangkok, Thailand']\n```\n\n## API\n\n### pFilter(input, filterer, options?)\n\nReturns 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.\n\n#### input\n\nType: `Iterable<Promise<unknown> | unknown>`\n\nIterated over concurrently in the `filterer` function.\n\n#### filterer(element, index)\n\nType: `Function`\n\nThe filterer function that decides whether an element should be included into result. Expected to return `boolean | Promise<boolean>`.\n\n#### options\n\nType: `object`\n\nSee the [`p-map` options](https://github.com/sindresorhus/p-map#options).\n\n##### concurrency\n\nType: `number`\\\nDefault: `Infinity`\\\nMinimum: `1`\n\nThe number of concurrently pending promises returned by `filterer`.\n\n### pFilterIterable(iterable, filterer, options?)\n\nReturns an async iterable that iterates over the promises in `iterable` and ones returned from `filterer` concurrently, calling `filterer` for each element.\n\n```js\nimport {pFilterIterable} from 'p-filter';\nimport getWeather from 'get-weather'; // Not a real module\n\nasync function * getPlaces() {\n\tconst name = await getCapital('Norway');\n\n\tyield name;\n\tyield 'Bangkok, Thailand';\n\tyield 'Berlin, Germany';\n\tyield 'Tokyo, Japan';\n}\n\nconst places = getPlaces();\n\nconst filterer = async place => {\n\tconst weather = await getWeather(place);\n\treturn weather.temperature > 30;\n};\n\nfor await (const element of pFilterIterable(places, filterer)) {\n\tconsole.log(element);\n}\n//=> ['Bangkok, Thailand']\n```\n\n#### iterable\n\nType: `Iterable<Promise<unknown> | unknown>`\n\nIterated over concurrently in the `filterer` function.\n\n#### filterer(element, index)\n\nType: `Function`\n\nThe filterer function that decides whether an element should be included into result. Expected to return `boolean | Promise<boolean>`.\n\n#### options\n\nType: `object`\n\nSee the [`p-map` options](https://github.com/sindresorhus/p-map#options).\n\n##### concurrency\n\nType: `number`\\\nDefault: `Infinity`\\\nMinimum: `1`\n\nThe number of concurrently pending promises returned by `filterer`.\n\n## Related\n\n- [p-locate](https://github.com/sindresorhus/p-locate) - Get the first fulfilled promise that satisfies the provided testing function\n- [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently\n- [p-times](https://github.com/sindresorhus/p-times) - Run promise-returning & async functions a specific number of times concurrently\n- [More…](https://github.com/sindresorhus/promise-fun)\n","publish_time":1703692976291,"_cnpm_publish_time":1703692976291,"dist-tags":{"latest":"4.1.0"}}