{"id":19560649,"url":"https://github.com/zoubin/array-async-filter","last_synced_at":"2025-08-24T17:27:53.050Z","repository":{"id":143802578,"uuid":"42507439","full_name":"zoubin/array-async-filter","owner":"zoubin","description":"Async filter function for arrays","archived":false,"fork":false,"pushed_at":"2018-02-23T03:27:57.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-19T18:13:54.352Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zoubin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-09-15T09:11:50.000Z","updated_at":"2018-02-23T03:23:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"ce2ba3fd-1256-4073-9517-82b28a428594","html_url":"https://github.com/zoubin/array-async-filter","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/zoubin/array-async-filter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Farray-async-filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Farray-async-filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Farray-async-filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Farray-async-filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zoubin","download_url":"https://codeload.github.com/zoubin/array-async-filter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Farray-async-filter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259549865,"owners_count":22875160,"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-11-11T05:08:22.721Z","updated_at":"2025-06-12T23:35:40.706Z","avatar_url":"https://github.com/zoubin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# array-async-filter\nFilter an array using async filter callback.\n\n## Example\n\nexample/filter.js:\n\n```javascript\nvar asyncFilter = require('..');\n\nasyncFilter(\n  ['abc', 'bcd', 'cde', 'def'],\n  function (val, i, arr, next) {\n    process.nextTick(function () {\n      next(null, val.indexOf('cd') !== -1);\n    });\n  },\n  function (err, res) {\n    console.log('async callback:', err, res);\n  }\n);\n\nasyncFilter(\n  ['abc', 'bcd', 'cde', 'def'],\n  function (val) {\n    return new Promise(function (rs) {\n      setTimeout(function() {\n        rs(val.indexOf('cd') !== -1);\n      }, 10);\n    });\n  },\n  function (err, res) {\n    console.log('promise callback:', err, res);\n  }\n);\n\nasyncFilter(\n  ['abc', 'bcd', 'cde', 'def'],\n  function (val) {\n    return val.indexOf('cd') !== -1;\n  },\n  function (err, res) {\n    console.log('sync callback:', err, res);\n  }\n);\n\n```\n\noutput:\n\n```\n⌘ node example/filter.js\nsync callback: null [ 'bcd', 'cde' ]\nasync callback: null [ 'bcd', 'cde' ]\npromise callback: null [ 'bcd', 'cde' ]\n\n```\n\n\n## asyncFilter(arr, fn, done)\n\nFilter `arr` using `fn`,\nand the results can be accessed by the callback `done`.\n\n### arr\n\nType: `Array`\n\nThe array to be filtered.\n\n### fn\n\nType: `Function`\n\nThe filter function.\n\nIt can be synchronous,\nwith signature `fn(val, index, arr)`.\nIf the returned value is truthy,\n`val` will be kept in the final results.\n\n`fn` can be made asynchronous if it does one of the following.\n\n#### Accept a callback as the 4th argument\n\n```javascript\nasyncFilter(\n  ['abc', 'bcd', 'cde', 'def'],\n  function (val, i, arr, next) {\n    process.nextTick(function () {\n      next(null, val.indexOf('cd') !== -1);\n    });\n  },\n  function (err, res) {\n    console.log('async callback:', err, res);\n  }\n);\n```\n\n#### Return a promise\n\n```javascript\nasyncFilter(\n  ['abc', 'bcd', 'cde', 'def'],\n  function (val) {\n    return new Promise(function (rs) {\n      setTimeout(function() {\n        rs(val.indexOf('cd') !== -1);\n      }, 10);\n    });\n  },\n  function (err, res) {\n    console.log('promise callback:', err, res);\n  }\n);\n```\n\n### done\n\nType: `Function`\n\nSignature: `done(err, results)`\n\nCalled when all elements are checked.\n\nIf an error is thrown when executing `fn`,\nor the `next` callback is passed a truthy value as the first argument,\nor the returned promise rejects,\n`done` will be called immediately,\nand filtering finishes.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoubin%2Farray-async-filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzoubin%2Farray-async-filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoubin%2Farray-async-filter/lists"}