package.json 7.45 KB
{
  "_args": [
    [
      {
        "raw": "async-foreach@^0.1.3",
        "scope": null,
        "escapedName": "async-foreach",
        "name": "async-foreach",
        "rawSpec": "^0.1.3",
        "spec": ">=0.1.3 <0.2.0",
        "type": "range"
      },
      "/Users/admin/Documents/workspace/programming/node_modules/node-sass"
    ]
  ],
  "_from": "async-foreach@>=0.1.3 <0.2.0",
  "_id": "async-foreach@0.1.3",
  "_inCache": true,
  "_location": "/async-foreach",
  "_npmUser": {
    "name": "cowboy",
    "email": "cowboy@rj3.net"
  },
  "_npmVersion": "1.1.70",
  "_phantomChildren": {},
  "_requested": {
    "raw": "async-foreach@^0.1.3",
    "scope": null,
    "escapedName": "async-foreach",
    "name": "async-foreach",
    "rawSpec": "^0.1.3",
    "spec": ">=0.1.3 <0.2.0",
    "type": "range"
  },
  "_requiredBy": [
    "/node-sass"
  ],
  "_resolved": "https://registry.npmjs.org/async-foreach/-/async-foreach-0.1.3.tgz",
  "_shasum": "36121f845c0578172de419a97dbeb1d16ec34542",
  "_shrinkwrap": null,
  "_spec": "async-foreach@^0.1.3",
  "_where": "/Users/admin/Documents/workspace/programming/node_modules/node-sass",
  "author": {
    "name": "\"Cowboy\" Ben Alman",
    "url": "http://benalman.com/"
  },
  "bugs": {
    "url": "https://github.com/cowboy/javascript-sync-async-foreach/issues"
  },
  "dependencies": {},
  "description": "An optionally-asynchronous forEach with an interesting interface.",
  "devDependencies": {},
  "directories": {},
  "dist": {
    "shasum": "36121f845c0578172de419a97dbeb1d16ec34542",
    "tarball": "https://registry.npmjs.org/async-foreach/-/async-foreach-0.1.3.tgz"
  },
  "engines": {
    "node": "*"
  },
  "homepage": "http://github.com/cowboy/javascript-sync-async-foreach",
  "keywords": [
    "array",
    "loop",
    "sync",
    "async",
    "foreach"
  ],
  "main": "lib/foreach",
  "maintainers": [
    {
      "name": "cowboy",
      "email": "cowboy@rj3.net"
    }
  ],
  "name": "async-foreach",
  "optionalDependencies": {},
  "readme": "# JavaScript Sync/Async forEach\n\nAn optionally-asynchronous forEach with an interesting interface.\n\n## Getting Started\n\nThis code should work just fine in Node.js:\n\nFirst, install the module with: `npm install async-foreach`\n\n```javascript\nvar forEach = require('async-foreach').forEach;\nforEach([\"a\", \"b\", \"c\"], function(item, index, arr) {\n  console.log(\"each\", item, index, arr);\n});\n// logs:\n// each a 0 [\"a\", \"b\", \"c\"]\n// each b 1 [\"a\", \"b\", \"c\"]\n// each c 2 [\"a\", \"b\", \"c\"]\n```\n\nOr in the browser:\n\n```html\n<script src=\"dist/ba-foreach.min.js\"></script>\n<script>\nforEach([\"a\", \"b\", \"c\"], function(item, index, arr) {\n  console.log(\"each\", item, index, arr);\n});\n// logs:\n// each a 0 [\"a\", \"b\", \"c\"]\n// each b 1 [\"a\", \"b\", \"c\"]\n// each c 2 [\"a\", \"b\", \"c\"]\n</script>\n```\n\nIn the browser, you can attach the forEach method to any object.\n\n```html\n<script>\nthis.exports = Bocoup.utils;\n</script>\n<script src=\"dist/ba-foreach.min.js\"></script>\n<script>\nBocoup.utils.forEach([\"a\", \"b\", \"c\"], function(item, index, arr) {\n  console.log(\"each\", item, index, arr);\n});\n// logs:\n// each a 0 [\"a\", \"b\", \"c\"]\n// each b 1 [\"a\", \"b\", \"c\"]\n// each c 2 [\"a\", \"b\", \"c\"]\n</script>\n```\n\n## The General Idea (Why I thought this was worth sharing)\n\nThe idea is to allow the callback to decide _at runtime_ whether the loop will be synchronous or asynchronous. By using `this` in a creative way (in situations where that value isn't already spoken for), an entire control API can be offered without over-complicating function signatures.\n\n```javascript\nforEach(arr, function(item, index) {\n  // Synchronous.\n});\n\nforEach(arr, function(item, index) {\n  // Only when `this.async` is called does iteration becomes asynchronous. The\n  // loop won't be continued until the `done` function is executed.\n  var done = this.async();\n  // Continue in one second.\n  setTimeout(done, 1000);\n});\n\nforEach(arr, function(item, index) {\n  // Break out of synchronous iteration early by returning false.\n  return index !== 1;\n});\n\nforEach(arr, function(item, index) {\n  // Break out of asynchronous iteration early...\n  var done = this.async();\n  // ...by passing false to the done function.\n  setTimeout(function() {\n    done(index !== 1);\n  });\n});\n```\n\n## Examples\nSee the unit tests for more examples.\n\n```javascript\n// Generic \"done\" callback.\nfunction allDone(notAborted, arr) {\n  console.log(\"done\", notAborted, arr);\n}\n\n// Synchronous.\nforEach([\"a\", \"b\", \"c\"], function(item, index, arr) {\n  console.log(\"each\", item, index, arr);\n}, allDone);\n// logs:\n// each a 0 [\"a\", \"b\", \"c\"]\n// each b 1 [\"a\", \"b\", \"c\"]\n// each c 2 [\"a\", \"b\", \"c\"]\n// done true [\"a\", \"b\", \"c\"]\n\n// Synchronous with early abort.\nforEach([\"a\", \"b\", \"c\"], function(item, index, arr) {\n  console.log(\"each\", item, index, arr);\n  if (item === \"b\") { return false; }\n}, allDone);\n// logs:\n// each a 0 [\"a\", \"b\", \"c\"]\n// each b 1 [\"a\", \"b\", \"c\"]\n// done false [\"a\", \"b\", \"c\"]\n\n// Asynchronous.\nforEach([\"a\", \"b\", \"c\"], function(item, index, arr) {\n  console.log(\"each\", item, index, arr);\n  var done = this.async();\n  setTimeout(function() {\n    done();\n  }, 500);\n}, allDone);\n// logs:\n// each a 0 [\"a\", \"b\", \"c\"]\n// each b 1 [\"a\", \"b\", \"c\"]\n// each c 2 [\"a\", \"b\", \"c\"]\n// done true [\"a\", \"b\", \"c\"]\n\n// Asynchronous with early abort.\nforEach([\"a\", \"b\", \"c\"], function(item, index, arr) {\n  console.log(\"each\", item, index, arr);\n  var done = this.async();\n  setTimeout(function() {\n    done(item !== \"b\");\n  }, 500);\n}, allDone);\n// logs:\n// each a 0 [\"a\", \"b\", \"c\"]\n// each b 1 [\"a\", \"b\", \"c\"]\n// done false [\"a\", \"b\", \"c\"]\n\n// Not actually asynchronous.\nforEach([\"a\", \"b\", \"c\"], function(item, index, arr) {\n  console.log(\"each\", item, index, arr);\n  var done = this.async()\n  done();\n}, allDone);\n// logs:\n// each a 0 [\"a\", \"b\", \"c\"]\n// each b 1 [\"a\", \"b\", \"c\"]\n// each c 2 [\"a\", \"b\", \"c\"]\n// done true [\"a\", \"b\", \"c\"]\n\n// Not actually asynchronous with early abort.\nforEach([\"a\", \"b\", \"c\"], function(item, index, arr) {\n  console.log(\"each\", item, index, arr);\n  var done = this.async();\n  done(item !== \"b\");\n}, allDone);\n// logs:\n// each a 0 [\"a\", \"b\", \"c\"]\n// each b 1 [\"a\", \"b\", \"c\"]\n// done false [\"a\", \"b\", \"c\"]\n```\n\n## Contributing\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt](https://github.com/cowboy/grunt).\n\n_Also, please don't edit files in the \"dist\" subdirectory as they are generated via grunt. You'll find source code in the \"lib\" subdirectory!_\n\n## Release History\n\n04/29/2013\nv0.1.3\nRemoved hard Node.js version dependency.\n\n11/17/2011\nv0.1.2\nAdding sparse array support.\nInvalid length properties are now sanitized.\nThis closes issue #1 (like a boss).\n\n11/11/2011\nv0.1.1\nRefactored code to be much simpler. Yay for unit tests!\n\n11/11/2011\nv0.1.0\nInitial Release.\n\n## License\nCopyright (c) 2012 \"Cowboy\" Ben Alman  \nLicensed under the MIT license.  \n<http://benalman.com/about/license/>\n",
  "readmeFilename": "README.md",
  "repository": {
    "type": "git",
    "url": "git://github.com/cowboy/javascript-sync-async-foreach.git"
  },
  "version": "0.1.3"
}