{"id":19560663,"url":"https://github.com/zoubin/async-array-methods","last_synced_at":"2026-06-19T10:31:16.080Z","repository":{"id":57185456,"uuid":"43229369","full_name":"zoubin/async-array-methods","owner":"zoubin","description":"Async methods to manipulate arrays","archived":false,"fork":false,"pushed_at":"2016-01-20T09:03:30.000Z","size":25,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-24T01:57:16.564Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/zoubin.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-27T01:12:20.000Z","updated_at":"2016-01-20T09:03:31.000Z","dependencies_parsed_at":"2022-09-06T04:10:58.960Z","dependency_job_id":null,"html_url":"https://github.com/zoubin/async-array-methods","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/zoubin/async-array-methods","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Fasync-array-methods","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Fasync-array-methods/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Fasync-array-methods/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Fasync-array-methods/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zoubin","download_url":"https://codeload.github.com/zoubin/async-array-methods/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Fasync-array-methods/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34528134,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-19T02:00:06.005Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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:24.750Z","updated_at":"2026-06-19T10:31:16.061Z","avatar_url":"https://github.com/zoubin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# async-array-methods\n[![version](https://img.shields.io/npm/v/async-array-methods.svg)](https://www.npmjs.org/package/async-array-methods)\n[![status](https://travis-ci.org/zoubin/async-array-methods.svg?branch=master)](https://travis-ci.org/zoubin/async-array-methods)\n[![coverage](https://img.shields.io/coveralls/zoubin/async-array-methods.svg)](https://coveralls.io/github/zoubin/async-array-methods)\n[![dependencies](https://david-dm.org/zoubin/async-array-methods.svg)](https://david-dm.org/zoubin/async-array-methods)\n[![devDependencies](https://david-dm.org/zoubin/async-array-methods/dev-status.svg)](https://david-dm.org/zoubin/async-array-methods#info=devDependencies)\n\nAsync methods to manipulate arrays.\n\n## Usage\n\n```javascript\nvar methods = require('async-array-methods')\nvar AsyncArray = methods.Array\nvar filter = methods.filter\nvar map = methods.map\nvar forEach = methods.forEach\nvar reduce = methods.reduce\n\n```\n\nAll methods return a promise.\n\n- [filter](#filter)\n- [map](#map)\n- [series](#series)\n- [forEach](#foreach)\n- [reduce](#reduce)\n- [AsyncArray](#asyncarray)\n\n## Methods\n\nCallbacks can be made asynchronous\nby returning a promise, or\naccepting a function argument,\nwhich will be called when the callback finishes.\n\nOtherwise, the callback is treated as synchronous.\n\n### filter\n\nSignature: `filter(arr, fn, context)`\n\n```javascript\nfilter(\n  [1, 2, 3, 4],\n  function (v, i, a, next) {\n    process.nextTick(function () {\n      next(null, v % 2)\n    })\n  }\n)\n.then(function (res) {\n  // [1, 3]\n  console.log(res)\n})\n\n```\n\n### map\n\nSignature: `map(arr, fn, context)`\n\n`fn` is called with each element in parallel.\n\n```javascript\nmap(\n  [1, 2, 3, 4],\n  function (v) {\n    return new Promise(function (rs) {\n      process.nextTick(function () {\n        rs(v \u003c\u003c 2)\n      })\n    })\n  },\n  { num: 2 }\n)\n// [4, 8, 12, 16]\n.then(console.log.bind(console))\n\n```\n\n### series\nThis method works like `map`,\nexcept that `fn` is called with each element in sequence rather than in parallel.\n\nSignature: `series(arr, fn, context)`\n\n\n```javascript\nvar n = 1\nseries(\n  [1, 2, 3, 4],\n  function (v, i, arr, next) {\n    var delay = rand()\n    console.log('i:', i, 'delay:', delay)\n    setTimeout(function() {\n      next(null, v \u003c\u003c n++)\n    }, delay)\n  }\n)\n// i: 0 delay: 10\n// i: 1 delay: 50\n// i: 2 delay: 0\n// i: 3 delay: 80\n// [2, 8, 24, 64]\n.then(log)\n\nfunction rand() {\n  return Math.floor(Math.random() * 10) * 10\n}\n\n```\n\n### forEach\n\n`fn` is called with elements in sequence.\n\nSignature: `forEach(arr, fn, context)`\n\n```javascript\nvar count = 0\n\nforEach(\n  [1, 2, 3, 4],\n  function (v, i, _, next) {\n    process.nextTick(function () {\n      console.log(count++, i)\n      next(null, v \u003c\u003c 2)\n    })\n  }\n)\n.then(function (arr) {\n  // [1, 2, 3, 4]\n  console.log(arr)\n})\n\n```\n\n### reduce\n\nSignature: `reduce(arr, fn, initial)`\n\n```javascript\nreduce(\n  [1, 2, 3, 4],\n  function (a, b, i, arr, next) {\n    process.nextTick(function () {\n      next(null, a + b)\n    })\n  }\n)\n// 10\n.then(console.log.bind(console))\n\n```\n\n### AsyncArray\nSignature: `AsyncArray(arr)`\n\nMethods:\n* `map`\n* `series`\n* `filter`\n* `forEach`\n* `reduce`\n\n```javascript\nvar origin = AsyncArray([1, 2, 3, 4, 5, 6])\nvar odd = origin.filter(isOdd)\nvar even = origin.filter(isEven)\n\nreturn odd.then(function (res) {\n  // [1, 3, 5]\n  console.log(res)\n  return even\n})\n.then(function (res) {\n  // [2, 4, 6]\n  console.log(res)\n})\n.then(function () {\n  return even.reduce(flagMap, {})\n})\n.then(function (res) {\n  // { 2: true, 4: true, 6: true }\n  console.log(res)\n})\n.then(function () {\n  // chain\n  return origin.filter(isOdd).reduce(flagMap, {})\n})\n.then(function (res) {\n  // { 1: true, 3: true, 5: true }\n  console.log(res)\n})\n\nfunction isOdd(n, i, arr, next) {\n  process.nextTick(function () {\n    next(null, n % 2)\n  })\n}\n\nfunction isEven(n, i, arr, next) {\n  return new Promise(function (resolve) {\n    process.nextTick(function () {\n      resolve((n + 1) % 2)\n    })\n  })\n}\n\nfunction flagMap(o, v) {\n  o[v] = true\n  return o\n}\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoubin%2Fasync-array-methods","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzoubin%2Fasync-array-methods","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoubin%2Fasync-array-methods/lists"}