{"name":"p-filter","version":"4.0.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.0"},"devDependencies":{"ava":"^6.0.1","tsd":"^0.30.0","xo":"^0.56.0"},"types":"./index.d.ts","gitHead":"def98651f6e086e10d05cf2be49795fb4caba418","bugs":{"url":"https://github.com/sindresorhus/p-filter/issues"},"homepage":"https://github.com/sindresorhus/p-filter#readme","_id":"p-filter@4.0.0","_nodeVersion":"21.2.0","_npmVersion":"9.2.0","dist":{"integrity":"sha512-3gxOrNadcyxj+YKFyRmRIEuCMGayNNJoXL7Zf1dqfdfoDsVB190bHfFfhqfcNEDFLfQP1q2uir2cBgIqnIT+cQ==","shasum":"10d55bf804712a1301a9bfb1588d5ec641cce754","tarball":"http://registry-npm.ywwl.com/p-filter/download/p-filter-4.0.0.tgz","fileCount":5,"unpackedSize":8117,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD6a0IeDcD8aebGNNtqdxpQ1EYwUxtEZxzInhGa/A6EKwIhAPVz+zFDA90sBahBR2qthvPh0wEPKviDgjUlWobyszM9"}],"size":2665,"noattachment":false,"key":"/p-filter/-/p-filter-4.0.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.0.0_1703260910374_0.4073599827487109"},"_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":1703260910571,"_cnpm_publish_time":1703260910571,"dist-tags":{"latest":"4.1.0"}}