{"id":13733150,"url":"https://github.com/sindresorhus/p-filter","last_synced_at":"2025-04-04T17:09:01.796Z","repository":{"id":55420237,"uuid":"71528845","full_name":"sindresorhus/p-filter","owner":"sindresorhus","description":"Filter promises concurrently","archived":false,"fork":false,"pushed_at":"2023-12-27T16:02:58.000Z","size":20,"stargazers_count":76,"open_issues_count":0,"forks_count":8,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-28T07:23:07.691Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2016-10-21T04:09:33.000Z","updated_at":"2025-03-04T19:47:56.000Z","dependencies_parsed_at":"2023-12-22T16:50:52.174Z","dependency_job_id":"46518ab2-8a75-4fe8-8aa3-1f2775148790","html_url":"https://github.com/sindresorhus/p-filter","commit_stats":{"total_commits":22,"total_committers":5,"mean_commits":4.4,"dds":0.2727272727272727,"last_synced_commit":"ec5496d1ce853addb6a003652565c9223ea51fba"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fp-filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fp-filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fp-filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fp-filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/p-filter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246660081,"owners_count":20813338,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T03:00:38.375Z","updated_at":"2025-04-04T17:09:01.768Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["Packages","Convenience Utilities"],"sub_categories":["sindresorhus's many Promise utilities (\u003cb\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;5149⭐\u003c/code\u003e\u003c/b\u003e \u003cb\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;137🍴\u003c/code\u003e\u003c/b\u003e [see notes](https://github.com/sindresorhus/promise-fun)))","sindresorhus's many Promise utilities ([see notes](https://github.com/sindresorhus/promise-fun))"],"readme":"# p-filter\n\n\u003e Filter promises concurrently\n\nUseful when you need to run promise-returning \u0026 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 =\u003e info.name),\n\t'Bangkok, Thailand',\n\t'Berlin, Germany',\n\t'Tokyo, Japan',\n];\n\nconst filterer = async place =\u003e {\n\tconst weather = await getWeather(place);\n\treturn weather.temperature \u003e 30;\n};\n\nconst result = await pFilter(places, filterer);\n\nconsole.log(result);\n//=\u003e ['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\u003cPromise\u003cunknown\u003e | unknown\u003e`\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\u003cboolean\u003e`.\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 =\u003e {\n\tconst weather = await getWeather(place);\n\treturn weather.temperature \u003e 30;\n};\n\nfor await (const element of pFilterIterable(places, filterer)) {\n\tconsole.log(element);\n}\n//=\u003e ['Bangkok, Thailand']\n```\n\n#### iterable\n\nType: `Iterable\u003cPromise\u003cunknown\u003e | unknown\u003e`\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\u003cboolean\u003e`.\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 \u0026 async functions a specific number of times concurrently\n- [More…](https://github.com/sindresorhus/promise-fun)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fp-filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fp-filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fp-filter/lists"}