{"id":14982026,"url":"https://github.com/gulpjs/now-and-later","last_synced_at":"2025-04-09T19:19:12.947Z","repository":{"id":39759789,"uuid":"23029481","full_name":"gulpjs/now-and-later","owner":"gulpjs","description":"Map over an array or object of values in parallel or series, passing each through the async iterator, with optional lifecycle hooks.","archived":false,"fork":false,"pushed_at":"2023-03-14T00:12:30.000Z","size":45,"stargazers_count":24,"open_issues_count":1,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-09T19:19:03.554Z","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/gulpjs.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,"governance":null},"funding":{"github":["gulpjs","phated","yocontra"],"tidelift":"npm/gulp","open_collective":"gulpjs"}},"created_at":"2014-08-16T23:49:45.000Z","updated_at":"2023-11-05T01:45:19.000Z","dependencies_parsed_at":"2022-09-05T17:00:36.556Z","dependency_job_id":"33d73f78-8d10-45fc-b9a8-4cea091adca8","html_url":"https://github.com/gulpjs/now-and-later","commit_stats":{"total_commits":37,"total_committers":8,"mean_commits":4.625,"dds":"0.29729729729729726","last_synced_commit":"d9ad43732f99bc7d74dd04acd4d0eb66d31c851d"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gulpjs%2Fnow-and-later","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gulpjs%2Fnow-and-later/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gulpjs%2Fnow-and-later/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gulpjs%2Fnow-and-later/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gulpjs","download_url":"https://codeload.github.com/gulpjs/now-and-later/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248094991,"owners_count":21046770,"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-09-24T14:04:39.860Z","updated_at":"2025-04-09T19:19:12.907Z","avatar_url":"https://github.com/gulpjs.png","language":"JavaScript","funding_links":["https://github.com/sponsors/gulpjs","https://github.com/sponsors/phated","https://github.com/sponsors/yocontra","https://tidelift.com/funding/github/npm/gulp","https://opencollective.com/gulpjs"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://gulpjs.com\"\u003e\n    \u003cimg height=\"257\" width=\"114\" src=\"https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n# now-and-later\n\n[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url]\n\nMap over an array or object of values in parallel or series, passing each through the async iterator, with optional lifecycle hooks.\n\n## Usage\n\n```js\nvar nal = require('now-and-later');\n\nfunction iterator(value, key, cb) {\n  // called with each value in sequence\n  // also passes the key\n  cb(null, value * 2);\n}\n\nfunction create(value, key) {\n  // called at the beginning of every iteration\n  // return a storage object to be passed to each lifecycle method\n  return { key: key, value: value };\n}\n\nfunction before(storage) {\n  // called before the iterator function of every iteration\n  // receives the storage returned from `create`\n}\n\nfunction after(result, storage) {\n  // called after a success occurs in the iterator function of any iteration\n  // receives the `result` of the iterator and the storage returned from `create`\n}\n\nfunction error(error, storage) {\n  // called after an error occurs in the iterator function of any iteration\n  // receives the `error` of the iterator and the storage returned from `create`\n}\n\nfunction done(error, results) {\n  // called after all iterations complete or an error occurs in an iterator\n  // receives an `error` if one occurred and all results (or partial results upon error) of the iterators\n}\n\n/*\n  Calling mapSeries with an object can't guarantee order\n  It uses Object.keys to get an order\n  It is better to use an array if order must be guaranteed\n */\nnal.mapSeries(\n  [1, 2, 3],\n  iterator,\n  {\n    create: create,\n    before: before,\n    after: after,\n    error: error,\n  },\n  done\n);\n\nnal.map(\n  {\n    iter1: 1,\n    iter2: 2,\n  },\n  iterator,\n  {\n    create: create,\n    before: before,\n    after: after,\n    error: error,\n  },\n  done\n);\n```\n\n## API\n\n### `map(values, iterator[, options][, callback])`\n\nTakes an object or array of `values` and an `iterator` function to execute with each value.\nOptionally, takes an `options` object and a `callback` function that is called upon completion of the iterations.\n\nAll iterations run in parallel.\n\n#### `values`\n\nAn array or object of values to iterate over.\n\nIf `values` is an array, iterations are started in order by index. If `values` is an object, iterations are started in order by the order returned by `Object.keys` (order is not guaranteed).\n\nIf `values` is an array, the results of each iteration will be mapped to an array. If `values` is an object, the results of each iteration will be mapped to an object with corresponding keys.\n\n#### `iterator(value, key, done)`\n\nAn async function called per iteration. All iterations are run in parallel.\n\nThe `iterator` function is called once with each `value`, `key` and a function (`done(error, result)`) to call when the async work is complete.\n\nIf `done` is passed an error as the first argument, the iteration will fail and the sequence will be ended; however, any iterations in progress will still complete. If `done` is passed a `result` value as the second argument, it will be added to the final results array or object.\n\n#### `options`\n\nThe `options` object is primarily used for specifying functions that give insight into the lifecycle of each iteration. The possible extension points are `create`, `before`, `after` and `error`. If an extension point is not specified, it defaults to a no-op function.\n\nThe `options` object for `map` also allows specifying `concurrency` in which to run your iterations. By default, your iterations will run at maximum concurrency.\n\n##### `options.concurrency`\n\nLimits the amount of iterations allowed to run at a given time.\n\n##### `options.create(value, key)`\n\nCalled at the very beginning of each iteration with the `value` being iterated and the `key` from the array or object. If `create` returns a value (`storage`), it is passed to the `before`, `after` and `error` extension points.\n\nIf a value is not returned, an empty object is used as `storage` for each other extension point.\n\nThis is useful for tracking information across an iteration.\n\n##### `options.before(storage)`\n\nCalled immediately before each iteration with the `storage` value returned from the `create` extension point.\n\n##### `options.after(result, storage)`\n\nCalled immediately after each iteration with the `result` of the iteration and the `storage` value returned from the `create` extension point.\n\n##### `options.error(error, storage)`\n\nCalled immediately after a failed iteration with the `error` of the iteration and the `storage` value returned from the `create` extension point.\n\n#### `callback(error, results)`\n\nA function that is called after all iterations have completed or one iteration has errored.\n\nIf all iterations completed successfully, the `error` argument will be empty and the `results` will be a mapping of the `iterator` results.\n\nIf an iteration errored, the `error` argument will be passed from that iteration and the `results` will be whatever partial results had completed successfully before the error occurred.\n\n### `mapSeries(values, iterator[, options][, callback])`\n\nTakes an object or array of `values` and an `iterator` function to execute with each value.\nOptionally, takes an `options` object and a `callback` function that is called upon completion of the iterations.\n\nAll iterations run in serial.\n\n#### `values`\n\nAn array or object of values to iterate over.\n\nIf `values` is an array, iterations are started in order by index. If `values` is an object, iterations are started in order by the order returned by `Object.keys` (order is not guaranteed).\n\nIf `values` is an array, the results of each iteration will be mapped to an array. If `values` is an object, the results of each iteration will be mapped to an object with corresponding keys.\n\n#### `iterator(value, key, done)`\n\nAn async function called per iteration. All iterations are run in serial.\n\nThe `iterator` function is called once with each `value`, `key` and a function (`done(error, result)`) to call when the async work is complete.\n\nIf `done` is passed an error as the first argument, the iteration will fail and the sequence will be ended without executing any more iterations. If `done` is passed a `result` value as the second argument, it will be added to the final results array or object.\n\n#### `options`\n\nThe `options` object is primarily used for specifying functions that give insight into the lifecycle of each iteration. The possible extension points are `create`, `before`, `after` and `error`. If an extension point is not specified, it defaults to a no-op function.\n\n##### `options.create(value, key)`\n\nCalled at the very beginning of each iteration with the `value` being iterated and the `key` from the array or object. If `create` returns a value (`storage`), it is passed to the `before`, `after` and `error` extension points.\n\nIf a value is not returned, an empty object is used as `storage` for each other extension point.\n\nThis is useful for tracking information across an iteration.\n\n##### `options.before(storage)`\n\nCalled immediately before each iteration with the `storage` value returned from the `create` extension point.\n\n##### `options.after(result, storage)`\n\nCalled immediately after each iteration with the `result` of the iteration and the `storage` value returned from the `create` extension point.\n\n##### `options.error(error, storage)`\n\nCalled immediately after a failed iteration with the `error` of the iteration and the `storage` value returned from the `create` extension point.\n\n#### `callback(error, results)`\n\nA function that is called after all iterations have completed or one iteration has errored.\n\nIf all iterations completed successfully, the `error` argument will be empty and the `results` will be a mapping of the `iterator` results.\n\nIf an iteration errored, the `error` argument will be passed from that iteration and the `results` will be whatever partial results had completed successfully before the error occurred.\n\n## License\n\nMIT\n\n\u003c!-- prettier-ignore-start --\u003e\n[downloads-image]: https://img.shields.io/npm/dm/now-and-later.svg?style=flat-square\n[npm-url]: https://www.npmjs.com/package/now-and-later\n[npm-image]: https://img.shields.io/npm/v/now-and-later.svg?style=flat-square\n\n[ci-url]: https://github.com/gulpjs/now-and-later/actions?query=workflow:dev\n[ci-image]: https://img.shields.io/github/actions/workflow/status/gulpjs/now-and-later/dev.yml?branch=master\u0026style=flat-square\n\n[coveralls-url]: https://coveralls.io/r/gulpjs/now-and-later\n[coveralls-image]: https://img.shields.io/coveralls/gulpjs/now-and-later/master.svg?style=flat-square\n\u003c!-- prettier-ignore-end --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgulpjs%2Fnow-and-later","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgulpjs%2Fnow-and-later","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgulpjs%2Fnow-and-later/lists"}