Changeset 516 for Dev/trunk/node_modules/grunt-contrib-less
- Timestamp:
- 03/14/14 12:36:58 (11 years ago)
- Location:
- Dev/trunk
- Files:
-
- 32 added
- 3 deleted
- 28 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk
- Property svn:ignore
-
old new 1 1 build 2 quod-erat.git
-
- Property svn:ignore
-
Dev/trunk/node_modules/grunt-contrib-less/node_modules/grunt-lib-contrib/package.json
r484 r516 36 36 "zlib-browserify": "0.0.1" 37 37 }, 38 "readme": "# grunt-lib-contrib [](http://travis-ci.org/gruntjs/grunt-lib-contrib)\n\n> Common functionality shared across grunt-contrib tasks.\n\nThe purpose of grunt-lib-contrib is to explore solutions to common problems task writers encounter, and to ease the upgrade path for contrib tasks.\n\n**These APIs should be considered highly unstable. Depend on them at your own risk!**\n\n_Over time, some of the functionality provided here may be incorporated directly into grunt for mainstream use. Until then, you may require `grunt-lib-contrib` as a dependency in your projects, but be very careful to specify an exact version number instead of a range, as backwards-incompatible changes are likely to be introduced._\n\n### Helper Functions\n\n#### getNamespaceDeclaration(ns)\n\nThis helper is used to build JS namespace declarations.\n\n#### optsToArgs(options)\n\nConvert an object to an array of CLI arguments, which can be used with `child_process.spawn()`.\n\n```js\n// Example\n{\n fooBar: 'a', // ['--foo-bar', 'a']\n fooBar: 1, // ['--foo-bar', '1']\n fooBar: true, // ['--foo-bar']\n fooBar: false, //\n fooBar: ['a', 'b'] // ['--foo-bar', 'a', '--foo-bar', 'b']\n}\n```\n\n#### stripPath(pth, strip)\n\nStrip a path from a path. normalize both paths for best results.\n\n#### minMaxInfo(min, max, report)\n\nHelper for logging compressed, uncompressed and gzipped sizes of strings.\n\n#### report\nChoices: `false`, `'min'`, `'gzip'`\nDefault: `false`\n\nEither do not report anything, report only minification result, or report minification and gzip results.\n\n**Important** Including `'gzip'` results can make this task 5-10x slower depending on the size of the file.\n\n\n```js\nvar max = grunt.file.read('max.js');\nvar min = minify(max);\nminMaxInfo(min, max, 'gzip');\n```\n\nWould print:\n\n```\nOriginal: 495 bytes.\nMinified: 396 bytes.\nGzipped: 36 bytes.\n```\n\n--\n\n*Lib submitted by [Tyler Kellen](https://goingslowly.com/).*", 39 "readmeFilename": "README.md", 38 40 "contributors": [ 39 41 { … … 54 56 } 55 57 ], 56 "readme": "# grunt-lib-contrib [](http://travis-ci.org/gruntjs/grunt-lib-contrib)\n\n> Common functionality shared across grunt-contrib tasks.\n\nThe purpose of grunt-lib-contrib is to explore solutions to common problems task writers encounter, and to ease the upgrade path for contrib tasks.\n\n**These APIs should be considered highly unstable. Depend on them at your own risk!**\n\n_Over time, some of the functionality provided here may be incorporated directly into grunt for mainstream use. Until then, you may require `grunt-lib-contrib` as a dependency in your projects, but be very careful to specify an exact version number instead of a range, as backwards-incompatible changes are likely to be introduced._\n\n### Helper Functions\n\n#### getNamespaceDeclaration(ns)\n\nThis helper is used to build JS namespace declarations.\n\n#### optsToArgs(options)\n\nConvert an object to an array of CLI arguments, which can be used with `child_process.spawn()`.\n\n```js\n// Example\n{\n fooBar: 'a', // ['--foo-bar', 'a']\n fooBar: 1, // ['--foo-bar', '1']\n fooBar: true, // ['--foo-bar']\n fooBar: false, //\n fooBar: ['a', 'b'] // ['--foo-bar', 'a', '--foo-bar', 'b']\n}\n```\n\n#### stripPath(pth, strip)\n\nStrip a path from a path. normalize both paths for best results.\n\n#### minMaxInfo(min, max, report)\n\nHelper for logging compressed, uncompressed and gzipped sizes of strings.\n\n#### report\nChoices: `false`, `'min'`, `'gzip'`\nDefault: `false`\n\nEither do not report anything, report only minification result, or report minification and gzip results.\n\n**Important** Including `'gzip'` results can make this task 5-10x slower depending on the size of the file.\n\n\n```js\nvar max = grunt.file.read('max.js');\nvar min = minify(max);\nminMaxInfo(min, max, 'gzip');\n```\n\nWould print:\n\n```\nOriginal: 495 bytes.\nMinified: 396 bytes.\nGzipped: 36 bytes.\n```\n\n--\n\n*Lib submitted by [Tyler Kellen](https://goingslowly.com/).*",57 "readmeFilename": "README.md",58 58 "_id": "grunt-lib-contrib@0.6.1", 59 59 "_from": "grunt-lib-contrib@~0.6.1" -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/mime/package.json
r484 r516 33 33 "homepage": "https://github.com/broofa/node-mime", 34 34 "_id": "mime@1.2.11", 35 "_from": "mime@1.2.x" 35 "_from": "mime@1.2.x", 36 "scripts": {} 36 37 } -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/mkdirp/package.json
r484 r516 31 31 "homepage": "https://github.com/substack/node-mkdirp", 32 32 "_id": "mkdirp@0.3.5", 33 "dist": { 34 "shasum": "7d4fee48c751e68eddf5903038ad25370cd80618" 35 }, 36 "_from": "mkdirp@~0.3.4", 37 "_resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.5.tgz" 33 "_from": "mkdirp@~0.3.4" 38 34 } -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/.npmignore
r484 r516 1 tests 1 2 node_modules -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/README.md
r484 r516 24 24 ``` 25 25 26 You can also stream a file to a PUT or POST request. This method will also check the file extension against a mapping of file extensions to content-types , in this case `application/json`, and use the proper content-type in the PUT request if one is not already provided in the headers.26 You can also stream a file to a PUT or POST request. This method will also check the file extension against a mapping of file extensions to content-types (in this case `application/json`) and use the proper `content-type` in the PUT request (if the headers donât already provide one). 27 27 28 28 ```javascript … … 30 30 ``` 31 31 32 Request can also pipe to itself. When doing so the content-type and content-length will be preserved in the PUT headers.32 Request can also `pipe` to itself. When doing so, `content-type` and `content-length` are preserved in the PUT headers. 33 33 34 34 ```javascript … … 36 36 ``` 37 37 38 Now let 's get fancy.38 Now letâs get fancy. 39 39 40 40 ```javascript … … 50 50 ``` 51 51 52 You can also pipe() from a http.ServerRequest instance and to a http.ServerResponse instance. The HTTP method and headers will be sent as well as the entity-body data. Which means that, if you don't really care about security, you can do:52 You can also `pipe()` from `http.ServerRequest` instances, as well as to `http.ServerResponse` instances. The HTTP method, headers, and entity-body data will be sent. Which means that, if you don't really care about security, you can do: 53 53 54 54 ```javascript … … 62 62 ``` 63 63 64 And since pipe() returns the destination stream in node 0.5.x you can do one line proxying:)64 And since `pipe()` returns the destination stream in ⥠Node 0.5.x you can do one line proxying. :) 65 65 66 66 ```javascript … … 79 79 }) 80 80 ``` 81 81 82 You can still use intermediate proxies, the requests will still follow HTTP forwards, etc. 82 83 84 ## UNIX Socket 85 86 `request` supports the `unix://` protocol for all requests. The path is assumed to be absolute to the root of the host file system. 87 88 HTTP paths are extracted from the supplied URL by testing each level of the full URL against net.connect for a socket response. 89 90 Thus the following request will GET `/httppath` from the HTTP server listening on `/tmp/unix.socket` 91 92 ```javascript 93 request.get('unix://tmp/unix.socket/httppath') 94 ``` 95 83 96 ## Forms 84 97 85 98 `request` supports `application/x-www-form-urlencoded` and `multipart/form-data` form uploads. For `multipart/related` refer to the `multipart` API. 86 99 87 U rl encoded forms are simple100 URL-encoded forms are simple. 88 101 89 102 ```javascript … … 93 106 ``` 94 107 95 For `multipart/form-data` we use the [form-data](https://github.com/felixge/node-form-data) library by [@felixge](https://github.com/felixge). You don 't need to worry about piping the form object or setting the headers, `request` will handle that for you.108 For `multipart/form-data` we use the [form-data](https://github.com/felixge/node-form-data) library by [@felixge](https://github.com/felixge). You donât need to worry about piping the form object or setting the headers, `request` will handle that for you. 96 109 97 110 ```javascript … … 120 133 If passed as an option, `auth` should be a hash containing values `user` || `username`, `password` || `pass`, and `sendImmediately` (optional). The method form takes parameters `auth(username, password, sendImmediately)`. 121 134 122 `sendImmediately` defaults to true, which will cause a basic authentication header to be sent. If `sendImmediately` is `false`, then `request` will retry with a proper authentication header after receiving a 401response from the server (which must contain a `WWW-Authenticate` header indicating the required authentication method).123 124 Digest authentication is supported, but it only works with `sendImmediately` set to `false` (otherwise `request` will send basic authentication on the initial request, which will probably cause the request to fail).135 `sendImmediately` defaults to `true`, which causes a basic authentication header to be sent. If `sendImmediately` is `false`, then `request` will retry with a proper authentication header after receiving a `401` response from the server (which must contain a `WWW-Authenticate` header indicating the required authentication method). 136 137 Digest authentication is supported, but it only works with `sendImmediately` set to `false`; otherwise `request` will send basic authentication on the initial request, which will probably cause the request to fail. 125 138 126 139 ## OAuth Signing … … 158 171 , token_secret: perm_token.oauth_token_secret 159 172 } 160 , url = 'https://api.twitter.com/1 /users/show.json?'173 , url = 'https://api.twitter.com/1.1/users/show.json?' 161 174 , params = 162 175 { screen_name: perm_token.screen_name … … 172 185 ``` 173 186 174 187 ### Custom HTTP Headers 188 189 HTTP Headers, such as `User-Agent`, can be set in the `options` object. 190 In the example below, we call the github API to find out the number 191 of stars and forks for the request repository. This requires a 192 custom `User-Agent` header as well as https. 193 194 ```javascript 195 var request = require('request'); 196 197 var options = { 198 url: 'https://api.github.com/repos/mikeal/request', 199 headers: { 200 'User-Agent': 'request' 201 } 202 }; 203 204 function callback(error, response, body) { 205 if (!error && response.statusCode == 200) { 206 var info = JSON.parse(body); 207 console.log(info.stargazers_count + " Stars"); 208 console.log(info.forks_count + " Forks"); 209 } 210 } 211 212 request(options, callback); 213 ``` 175 214 176 215 ### request(options, callback) 177 216 178 The first argument can be either a url or an options object. The only required option is uri,all others are optional.179 180 * `uri` || `url` - fully qualified uri or a parsed url object from url.parse()181 * `qs` - object containing querystring values to be appended to the uri182 * `method` - http method , defaults to GET183 * `headers` - http headers , defaults to {}184 * `body` - entity body for PATCH, POST and PUT requests. Must be buffer or string.185 * `form` - when passed an object this will set `body` but to a querystring representation of value and adds `Content-type: application/x-www-form-urlencoded; charset=utf-8` header. When passed no option a FormData instance is returned that will be piped to request.217 The first argument can be either a `url` or an `options` object. The only required option is `uri`; all others are optional. 218 219 * `uri` || `url` - fully qualified uri or a parsed url object from `url.parse()` 220 * `qs` - object containing querystring values to be appended to the `uri` 221 * `method` - http method (default: `"GET"`) 222 * `headers` - http headers (default: `{}`) 223 * `body` - entity body for PATCH, POST and PUT requests. Must be a `Buffer` or `String`. 224 * `form` - when passed an object, this sets `body` to a querystring representation of value, and adds `Content-type: application/x-www-form-urlencoded; charset=utf-8` header. When passed no options, a `FormData` instance is returned (and is piped to request). 186 225 * `auth` - A hash containing values `user` || `username`, `password` || `pass`, and `sendImmediately` (optional). See documentation above. 187 * `json` - sets `body` but to JSON representation of value and adds `Content-type: application/json` header. Additionally, parses the response body as json.226 * `json` - sets `body` but to JSON representation of value and adds `Content-type: application/json` header. Additionally, parses the response body as JSON. 188 227 * `multipart` - (experimental) array of objects which contains their own headers and `body` attribute. Sends `multipart/related` request. See example below. 189 * `followRedirect` - follow HTTP 3xx responses as redirects . defaults to true.190 * `followAllRedirects` - follow non-GET HTTP 3xx responses as redirects . defaults to false.191 * `maxRedirects` - the maximum number of redirects to follow , defaults to 10.192 * `encoding` - Encoding to be used on `setEncoding` of response data. If set to `null`, the body is returned as a Buffer.193 * `pool` - A hash object containing the agents for these requests. If omitted this request will use the global pool which is set to node's default maxSockets.228 * `followRedirect` - follow HTTP 3xx responses as redirects (default: `true`) 229 * `followAllRedirects` - follow non-GET HTTP 3xx responses as redirects (default: `false`) 230 * `maxRedirects` - the maximum number of redirects to follow (default: `10`) 231 * `encoding` - Encoding to be used on `setEncoding` of response data. If `null`, the `body` is returned as a `Buffer`. 232 * `pool` - A hash object containing the agents for these requests. If omitted, the request will use the global pool (which is set to node's default `maxSockets`) 194 233 * `pool.maxSockets` - Integer containing the maximum amount of sockets in the pool. 195 234 * `timeout` - Integer containing the number of milliseconds to wait for a request to respond before aborting the request 196 * `proxy` - An HTTP proxy to be used. Support proxy Auth with Basic Auth the same way it's supported with the `url` parameter by embedding the auth info in the uri.197 * `oauth` - Options for OAuth HMAC-SHA1 signing , see documentation above.235 * `proxy` - An HTTP proxy to be used. Supports proxy Auth with Basic Auth, identical to support for the `url` parameter (by embedding the auth info in the `uri`) 236 * `oauth` - Options for OAuth HMAC-SHA1 signing. See documentation above. 198 237 * `hawk` - Options for [Hawk signing](https://github.com/hueniverse/hawk). The `credentials` key must contain the necessary signing info, [see hawk docs for details](https://github.com/hueniverse/hawk#usage-example). 199 * `strictSSL` - Set to `true` to require that SSL certificates be valid. Note: to use your own certificate authority, you need to specify an agent that was created with that caas an option.200 * `jar` - Set to `true` if you want cookies to be remembered for future use, or define your custom cookie jar (see examples section)201 * `aws` - object containing aws signing information, should have the properties `key` and `secret` as well as `bucket` unless you're specifying your bucket as part of the path, or you are making a request that doesn't use a bucket (i.e. GET Services)238 * `strictSSL` - If `true`, requires SSL certificates be valid. **Note:** to use your own certificate authority, you need to specify an agent that was created with that CA as an option. 239 * `jar` - If `true`, remember cookies for future use (or define your custom cookie jar; see examples section) 240 * `aws` - `object` containing AWS signing information. Should have the properties `key`, `secret`. Also requires the property `bucket`, unless youâre specifying your `bucket` as part of the path, or the request doesnât use a bucket (i.e. GET Services) 202 241 * `httpSignature` - Options for the [HTTP Signature Scheme](https://github.com/joyent/node-http-signature/blob/master/http_signing.md) using [Joyent's library](https://github.com/joyent/node-http-signature). The `keyId` and `key` properties must be specified. See the docs for other options. 203 242 * `localAddress` - Local interface to bind for network connections. 204 243 205 244 206 The callback argument gets 3 arguments. The first is an error when applicable (usually from the http.Client option not the http.ClientRequest object). The second is an http.ClientResponse object. The third is the response body String or Buffer. 245 The callback argument gets 3 arguments: 246 247 1. An `error` when applicable (usually from [`http.ClientRequest`](http://nodejs.org/api/http.html#http_class_http_clientrequest) object) 248 2. An [`http.IncomingMessage`](http://nodejs.org/api/http.html#http_http_incomingmessage) object 249 3. The third is the `response` body (`String` or `Buffer`, or JSON object if the `json` option is supplied) 207 250 208 251 ## Convenience methods … … 216 259 ### request.put 217 260 218 Same as request()but defaults to `method: "PUT"`.261 Same as `request()`, but defaults to `method: "PUT"`. 219 262 220 263 ```javascript … … 224 267 ### request.patch 225 268 226 Same as request()but defaults to `method: "PATCH"`.269 Same as `request()`, but defaults to `method: "PATCH"`. 227 270 228 271 ```javascript … … 232 275 ### request.post 233 276 234 Same as request()but defaults to `method: "POST"`.277 Same as `request()`, but defaults to `method: "POST"`. 235 278 236 279 ```javascript … … 248 291 ### request.del 249 292 250 Same as request()but defaults to `method: "DELETE"`.293 Same as `request()`, but defaults to `method: "DELETE"`. 251 294 252 295 ```javascript … … 256 299 ### request.get 257 300 258 Alias to normal request method for uniformity.301 Same as `request()` (for uniformity). 259 302 260 303 ```javascript … … 303 346 ) 304 347 ``` 305 Cookies are disabled by default (else, they would be used in subsequent requests). To enable cookies set jar to true (either in defaults or in the options sent). 348 349 Cookies are disabled by default (else, they would be used in subsequent requests). To enable cookies, set `jar` to `true` (either in `defaults` or `options`). 306 350 307 351 ```javascript … … 312 356 ``` 313 357 314 If you to use a custom cookie jar (instead of letting request use its own global cookie jar) you do so by setting the jar default or by specifying it as an option: 358 To use a custom cookie jar (instead `request`âs global cookie jar), set `jar` to an instance of `request.jar()` (either in `defaults` or `options`) 315 359 316 360 ```javascript … … 321 365 }) 322 366 ``` 367 323 368 OR 324 369 … … 326 371 var j = request.jar() 327 372 var cookie = request.cookie('your_cookie_here') 328 j. add(cookie)373 j.setCookie(cookie, uri); 329 374 request({url: 'http://www.google.com', jar: j}, function () { 330 375 request('http://images.google.com') -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/index.js
r484 r516 13 13 // limitations under the License. 14 14 15 var Cookie = require('cookie-jar') 16 , CookieJar = Cookie.Jar 17 , cookieJar = new CookieJar 18 15 var cookies = require('./lib/cookies') 19 16 , copy = require('./lib/copy') 20 17 , Request = require('./request') … … 93 90 } 94 91 92 function requester(params) { 93 if(typeof params.options._requester === 'function') { 94 return params.options._requester 95 } else { 96 return request 97 } 98 } 99 95 100 request.forever = function (agentOptions, optionsArg) { 96 101 var options = {} 97 102 if (optionsArg) { 98 for ( option in optionsArg) {103 for (var option in optionsArg) { 99 104 options[option] = optionsArg[option] 100 105 } … … 109 114 var params = initParams(uri, options, callback) 110 115 params.options.method = 'POST' 111 return request (params.uri || null, params.options, params.callback)116 return requester(params)(params.uri || null, params.options, params.callback) 112 117 } 113 118 request.put = function (uri, options, callback) { 114 119 var params = initParams(uri, options, callback) 115 120 params.options.method = 'PUT' 116 return request (params.uri || null, params.options, params.callback)121 return requester(params)(params.uri || null, params.options, params.callback) 117 122 } 118 123 request.patch = function (uri, options, callback) { 119 124 var params = initParams(uri, options, callback) 120 125 params.options.method = 'PATCH' 121 return request (params.uri || null, params.options, params.callback)126 return requester(params)(params.uri || null, params.options, params.callback) 122 127 } 123 128 request.head = function (uri, options, callback) { … … 130 135 throw new Error("HTTP HEAD requests MUST NOT include a request body.") 131 136 } 132 return request(params.uri || null, params.options, params.callback) 137 138 return requester(params)(params.uri || null, params.options, params.callback) 133 139 } 134 140 request.del = function (uri, options, callback) { 135 141 var params = initParams(uri, options, callback) 136 142 params.options.method = 'DELETE' 137 if(typeof params.options._requester === 'function') { 138 request = params.options._requester 139 } 140 return request(params.uri || null, params.options, params.callback) 143 return requester(params)(params.uri || null, params.options, params.callback) 141 144 } 142 145 request.jar = function () { 143 return new CookieJar146 return cookies.jar(); 144 147 } 145 148 request.cookie = function (str) { 146 if (str && str.uri) str = str.uri 147 if (typeof str !== 'string') throw new Error("The cookie function only accepts STRING as param") 148 return new Cookie(str) 149 return cookies.parse(str); 149 150 } -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/lib/debug.js
r484 r516 1 var util = require('util') 2 1 3 module.exports = 2 4 function debug () { -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/node_modules/forever-agent/index.js
r484 r516 25 25 26 26 // if an error happens while we don't use the socket anyway, meh, throw the socket away 27 function onIdleError() {27 var onIdleError = function() { 28 28 socket.destroy() 29 29 } -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/node_modules/forever-agent/package.json
r484 r516 7 7 "name": "forever-agent", 8 8 "description": "HTTP Agent that keeps socket connections alive between keep-alive requests. Formerly part of mikeal/request, now a standalone module.", 9 "version": "0.5. 0",9 "version": "0.5.2", 10 10 "repository": { 11 11 "url": "https://github.com/mikeal/forever-agent" … … 24 24 }, 25 25 "homepage": "https://github.com/mikeal/forever-agent", 26 "_id": "forever-agent@0.5.0", 27 "_from": "forever-agent@~0.5.0" 26 "_id": "forever-agent@0.5.2", 27 "_from": "forever-agent@~0.5.0", 28 "scripts": {} 28 29 } -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/node_modules/form-data/node_modules/async/README.md
r484 r516 105 105 106 106 * [each](#each) 107 * [eachSeries](#eachSeries) 108 * [eachLimit](#eachLimit) 107 109 * [map](#map) 110 * [mapSeries](#mapSeries) 111 * [mapLimit](#mapLimit) 108 112 * [filter](#filter) 113 * [filterSeries](#filterSeries) 109 114 * [reject](#reject) 115 * [rejectSeries](#rejectSeries) 110 116 * [reduce](#reduce) 117 * [reduceRight](#reduceRight) 111 118 * [detect](#detect) 119 * [detectSeries](#detectSeries) 112 120 * [sortBy](#sortBy) 113 121 * [some](#some) 114 122 * [every](#every) 115 123 * [concat](#concat) 124 * [concatSeries](#concatSeries) 116 125 117 126 ### Control Flow … … 119 128 * [series](#series) 120 129 * [parallel](#parallel) 130 * [parallelLimit](#parallellimittasks-limit-callback) 121 131 * [whilst](#whilst) 122 132 * [doWhilst](#doWhilst) … … 127 137 * [compose](#compose) 128 138 * [applyEach](#applyEach) 139 * [applyEachSeries](#applyEachSeries) 129 140 * [queue](#queue) 130 141 * [cargo](#cargo) … … 296 307 297 308 ```js 298 async.map (['file1','file2','file3'], 1, fs.stat, function(err, results){309 async.mapLimit(['file1','file2','file3'], 1, fs.stat, function(err, results){ 299 310 // results is now an array of stats for each file 300 311 }); … … 1063 1074 ```js 1064 1075 async.auto({ 1065 readData: async.apply(fs.readFile, 'data.txt', 'utf-8') ;1076 readData: async.apply(fs.readFile, 'data.txt', 'utf-8') 1066 1077 }, callback); 1067 1078 ``` -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/node_modules/form-data/node_modules/async/lib/async.js
r484 r516 92 92 async.nextTick = process.nextTick; 93 93 if (typeof setImmediate !== 'undefined') { 94 async.setImmediate = setImmediate; 94 async.setImmediate = function (fn) { 95 // not a direct alias for IE10 compatibility 96 setImmediate(fn); 97 }; 95 98 } 96 99 else { -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/node_modules/form-data/node_modules/async/package.json
r484 r516 6 6 "name": "Caolan McMahon" 7 7 }, 8 "version": "0.2. 9",8 "version": "0.2.10", 9 9 "repository": { 10 10 "type": "git", … … 36 36 "test": "nodeunit test/test-async.js" 37 37 }, 38 "readme": "# Async.js\n\nAsync is a utility module which provides straight-forward, powerful functions\nfor working with asynchronous JavaScript. Although originally designed for\nuse with [node.js](http://nodejs.org), it can also be used directly in the\nbrowser. Also supports [component](https://github.com/component/component).\n\nAsync provides around 20 functions that include the usual 'functional'\nsuspects (map, reduce, filter, eachâŠ) as well as some common patterns\nfor asynchronous control flow (parallel, series, waterfallâŠ). All these\nfunctions assume you follow the node.js convention of providing a single\ncallback as the last argument of your async function.\n\n\n## Quick Examples\n\n```javascript\nasync.map(['file1','file2','file3'], fs.stat, function(err, results){\n // results is now an array of stats for each file\n});\n\nasync.filter(['file1','file2','file3'], fs.exists, function(results){\n // results now equals an array of the existing files\n});\n\nasync.parallel([\n function(){ ... },\n function(){ ... }\n], callback);\n\nasync.series([\n function(){ ... },\n function(){ ... }\n]);\n```\n\nThere are many more functions available so take a look at the docs below for a\nfull list. This module aims to be comprehensive, so if you feel anything is\nmissing please create a GitHub issue for it.\n\n## Common Pitfalls\n\n### Binding a context to an iterator\n\nThis section is really about bind, not about async. If you are wondering how to\nmake async execute your iterators in a given context, or are confused as to why\na method of another library isn't working as an iterator, study this example:\n\n```js\n// Here is a simple object with an (unnecessarily roundabout) squaring method\nvar AsyncSquaringLibrary = {\n squareExponent: 2,\n square: function(number, callback){ \n var result = Math.pow(number, this.squareExponent);\n setTimeout(function(){\n callback(null, result);\n }, 200);\n }\n};\n\nasync.map([1, 2, 3], AsyncSquaringLibrary.square, function(err, result){\n // result is [NaN, NaN, NaN]\n // This fails because the `this.squareExponent` expression in the square\n // function is not evaluated in the context of AsyncSquaringLibrary, and is\n // therefore undefined.\n});\n\nasync.map([1, 2, 3], AsyncSquaringLibrary.square.bind(AsyncSquaringLibrary), function(err, result){\n // result is [1, 4, 9]\n // With the help of bind we can attach a context to the iterator before\n // passing it to async. Now the square function will be executed in its \n // 'home' AsyncSquaringLibrary context and the value of `this.squareExponent`\n // will be as expected.\n});\n```\n\n## Download\n\nThe source is available for download from\n[GitHub](http://github.com/caolan/async).\nAlternatively, you can install using Node Package Manager (npm):\n\n npm install async\n\n__Development:__ [async.js](https://github.com/caolan/async/raw/master/lib/async.js) - 29.6kb Uncompressed\n\n## In the Browser\n\nSo far it's been tested in IE6, IE7, IE8, FF3.6 and Chrome 5. Usage:\n\n```html\n<script type=\"text/javascript\" src=\"async.js\"></script>\n<script type=\"text/javascript\">\n\n async.map(data, asyncProcess, function(err, results){\n alert(results);\n });\n\n</script>\n```\n\n## Documentation\n\n### Collections\n\n* [each](#each)\n* [ map](#map)\n* [filter](#filter)\n* [reject](#reject)\n* [reduce](#reduce)\n* [detect](#detect)\n* [sortBy](#sortBy)\n* [some](#some)\n* [every](#every)\n* [concat](#concat)\n\n### Control Flow\n\n* [series](#series)\n* [parallel](#parallel)\n* [whilst](#whilst)\n* [doWhilst](#doWhilst)\n* [until](#until)\n* [doUntil](#doUntil)\n* [forever](#forever)\n* [waterfall](#waterfall)\n* [compose](#compose)\n* [applyEach](#applyEach)\n* [queue](#queue)\n* [cargo](#cargo)\n* [auto](#auto)\n* [iterator](#iterator)\n* [apply](#apply)\n* [nextTick](#nextTick)\n* [times](#times)\n* [timesSeries](#timesSeries)\n\n### Utils\n\n* [memoize](#memoize)\n* [unmemoize](#unmemoize)\n* [log](#log)\n* [dir](#dir)\n* [noConflict](#noConflict)\n\n\n## Collections\n\n<a name=\"forEach\" />\n<a name=\"each\" />\n### each(arr, iterator, callback)\n\nApplies an iterator function to each item in an array, in parallel.\nThe iterator is called with an item from the list and a callback for when it\nhas finished. If the iterator passes an error to this callback, the main\ncallback for the each function is immediately called with the error.\n\nNote, that since this function applies the iterator to each item in parallel\nthere is no guarantee that the iterator functions will complete in order.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A function to apply to each item in the array.\n The iterator is passed a callback(err) which must be called once it has \n completed. If no error has occured, the callback should be run without \n arguments or with an explicit null argument.\n* callback(err) - A callback which is called after all the iterator functions\n have finished, or an error has occurred.\n\n__Example__\n\n```js\n// assuming openFiles is an array of file names and saveFile is a function\n// to save the modified contents of that file:\n\nasync.each(openFiles, saveFile, function(err){\n // if any of the saves produced an error, err would equal that error\n});\n```\n\n---------------------------------------\n\n<a name=\"forEachSeries\" />\n<a name=\"eachSeries\" />\n### eachSeries(arr, iterator, callback)\n\nThe same as each only the iterator is applied to each item in the array in\nseries. The next iterator is only called once the current one has completed\nprocessing. This means the iterator functions will complete in order.\n\n\n---------------------------------------\n\n<a name=\"forEachLimit\" />\n<a name=\"eachLimit\" />\n### eachLimit(arr, limit, iterator, callback)\n\nThe same as each only no more than \"limit\" iterators will be simultaneously \nrunning at any time.\n\nNote that the items are not processed in batches, so there is no guarantee that\n the first \"limit\" iterator functions will complete before any others are \nstarted.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* limit - The maximum number of iterators to run at any time.\n* iterator(item, callback) - A function to apply to each item in the array.\n The iterator is passed a callback(err) which must be called once it has \n completed. If no error has occured, the callback should be run without \n arguments or with an explicit null argument.\n* callback(err) - A callback which is called after all the iterator functions\n have finished, or an error has occurred.\n\n__Example__\n\n```js\n// Assume documents is an array of JSON objects and requestApi is a\n// function that interacts with a rate-limited REST api.\n\nasync.eachLimit(documents, 20, requestApi, function(err){\n // if any of the saves produced an error, err would equal that error\n});\n```\n\n---------------------------------------\n\n<a name=\"map\" />\n### map(arr, iterator, callback)\n\nProduces a new array of values by mapping each value in the given array through\nthe iterator function. The iterator is called with an item from the array and a\ncallback for when it has finished processing. The callback takes 2 arguments, \nan error and the transformed item from the array. If the iterator passes an\nerror to this callback, the main callback for the map function is immediately\ncalled with the error.\n\nNote, that since this function applies the iterator to each item in parallel\nthere is no guarantee that the iterator functions will complete in order, however\nthe results array will be in the same order as the original array.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A function to apply to each item in the array.\n The iterator is passed a callback(err, transformed) which must be called once \n it has completed with an error (which can be null) and a transformed item.\n* callback(err, results) - A callback which is called after all the iterator\n functions have finished, or an error has occurred. Results is an array of the\n transformed items from the original array.\n\n__Example__\n\n```js\nasync.map(['file1','file2','file3'], fs.stat, function(err, results){\n // results is now an array of stats for each file\n});\n```\n\n---------------------------------------\n\n<a name=\"mapSeries\" />\n### mapSeries(arr, iterator, callback)\n\nThe same as map only the iterator is applied to each item in the array in\nseries. The next iterator is only called once the current one has completed\nprocessing. The results array will be in the same order as the original.\n\n\n---------------------------------------\n\n<a name=\"mapLimit\" />\n### mapLimit(arr, limit, iterator, callback)\n\nThe same as map only no more than \"limit\" iterators will be simultaneously \nrunning at any time.\n\nNote that the items are not processed in batches, so there is no guarantee that\n the first \"limit\" iterator functions will complete before any others are \nstarted.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* limit - The maximum number of iterators to run at any time.\n* iterator(item, callback) - A function to apply to each item in the array.\n The iterator is passed a callback(err, transformed) which must be called once \n it has completed with an error (which can be null) and a transformed item.\n* callback(err, results) - A callback which is called after all the iterator\n functions have finished, or an error has occurred. Results is an array of the\n transformed items from the original array.\n\n__Example__\n\n```js\nasync.map(['file1','file2','file3'], 1, fs.stat, function(err, results){\n // results is now an array of stats for each file\n});\n```\n\n---------------------------------------\n\n<a name=\"filter\" />\n### filter(arr, iterator, callback)\n\n__Alias:__ select\n\nReturns a new array of all the values which pass an async truth test.\n_The callback for each iterator call only accepts a single argument of true or\nfalse, it does not accept an error argument first!_ This is in-line with the\nway node libraries work with truth tests like fs.exists. This operation is\nperformed in parallel, but the results array will be in the same order as the\noriginal.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A truth test to apply to each item in the array.\n The iterator is passed a callback(truthValue) which must be called with a \n boolean argument once it has completed.\n* callback(results) - A callback which is called after all the iterator\n functions have finished.\n\n__Example__\n\n```js\nasync.filter(['file1','file2','file3'], fs.exists, function(results){\n // results now equals an array of the existing files\n});\n```\n\n---------------------------------------\n\n<a name=\"filterSeries\" />\n### filterSeries(arr, iterator, callback)\n\n__alias:__ selectSeries\n\nThe same as filter only the iterator is applied to each item in the array in\nseries. The next iterator is only called once the current one has completed\nprocessing. The results array will be in the same order as the original.\n\n---------------------------------------\n\n<a name=\"reject\" />\n### reject(arr, iterator, callback)\n\nThe opposite of filter. Removes values that pass an async truth test.\n\n---------------------------------------\n\n<a name=\"rejectSeries\" />\n### rejectSeries(arr, iterator, callback)\n\nThe same as reject, only the iterator is applied to each item in the array\nin series.\n\n\n---------------------------------------\n\n<a name=\"reduce\" />\n### reduce(arr, memo, iterator, callback)\n\n__aliases:__ inject, foldl\n\nReduces a list of values into a single value using an async iterator to return\neach successive step. Memo is the initial state of the reduction. This\nfunction only operates in series. For performance reasons, it may make sense to\nsplit a call to this function into a parallel map, then use the normal\nArray.prototype.reduce on the results. This function is for situations where\neach step in the reduction needs to be async, if you can get the data before\nreducing it then it's probably a good idea to do so.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* memo - The initial state of the reduction.\n* iterator(memo, item, callback) - A function applied to each item in the\n array to produce the next step in the reduction. The iterator is passed a\n callback(err, reduction) which accepts an optional error as its first \n argument, and the state of the reduction as the second. If an error is \n passed to the callback, the reduction is stopped and the main callback is \n immediately called with the error.\n* callback(err, result) - A callback which is called after all the iterator\n functions have finished. Result is the reduced value.\n\n__Example__\n\n```js\nasync.reduce([1,2,3], 0, function(memo, item, callback){\n // pointless async:\n process.nextTick(function(){\n callback(null, memo + item)\n });\n}, function(err, result){\n // result is now equal to the last value of memo, which is 6\n});\n```\n\n---------------------------------------\n\n<a name=\"reduceRight\" />\n### reduceRight(arr, memo, iterator, callback)\n\n__Alias:__ foldr\n\nSame as reduce, only operates on the items in the array in reverse order.\n\n\n---------------------------------------\n\n<a name=\"detect\" />\n### detect(arr, iterator, callback)\n\nReturns the first value in a list that passes an async truth test. The\niterator is applied in parallel, meaning the first iterator to return true will\nfire the detect callback with that result. That means the result might not be\nthe first item in the original array (in terms of order) that passes the test.\n\nIf order within the original array is important then look at detectSeries.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A truth test to apply to each item in the array.\n The iterator is passed a callback(truthValue) which must be called with a \n boolean argument once it has completed.\n* callback(result) - A callback which is called as soon as any iterator returns\n true, or after all the iterator functions have finished. Result will be\n the first item in the array that passes the truth test (iterator) or the\n value undefined if none passed.\n\n__Example__\n\n```js\nasync.detect(['file1','file2','file3'], fs.exists, function(result){\n // result now equals the first file in the list that exists\n});\n```\n\n---------------------------------------\n\n<a name=\"detectSeries\" />\n### detectSeries(arr, iterator, callback)\n\nThe same as detect, only the iterator is applied to each item in the array\nin series. This means the result is always the first in the original array (in\nterms of array order) that passes the truth test.\n\n\n---------------------------------------\n\n<a name=\"sortBy\" />\n### sortBy(arr, iterator, callback)\n\nSorts a list by the results of running each value through an async iterator.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A function to apply to each item in the array.\n The iterator is passed a callback(err, sortValue) which must be called once it\n has completed with an error (which can be null) and a value to use as the sort\n criteria.\n* callback(err, results) - A callback which is called after all the iterator\n functions have finished, or an error has occurred. Results is the items from\n the original array sorted by the values returned by the iterator calls.\n\n__Example__\n\n```js\nasync.sortBy(['file1','file2','file3'], function(file, callback){\n fs.stat(file, function(err, stats){\n callback(err, stats.mtime);\n });\n}, function(err, results){\n // results is now the original array of files sorted by\n // modified date\n});\n```\n\n---------------------------------------\n\n<a name=\"some\" />\n### some(arr, iterator, callback)\n\n__Alias:__ any\n\nReturns true if at least one element in the array satisfies an async test.\n_The callback for each iterator call only accepts a single argument of true or\nfalse, it does not accept an error argument first!_ This is in-line with the\nway node libraries work with truth tests like fs.exists. Once any iterator\ncall returns true, the main callback is immediately called.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A truth test to apply to each item in the array.\n The iterator is passed a callback(truthValue) which must be called with a \n boolean argument once it has completed.\n* callback(result) - A callback which is called as soon as any iterator returns\n true, or after all the iterator functions have finished. Result will be\n either true or false depending on the values of the async tests.\n\n__Example__\n\n```js\nasync.some(['file1','file2','file3'], fs.exists, function(result){\n // if result is true then at least one of the files exists\n});\n```\n\n---------------------------------------\n\n<a name=\"every\" />\n### every(arr, iterator, callback)\n\n__Alias:__ all\n\nReturns true if every element in the array satisfies an async test.\n_The callback for each iterator call only accepts a single argument of true or\nfalse, it does not accept an error argument first!_ This is in-line with the\nway node libraries work with truth tests like fs.exists.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A truth test to apply to each item in the array.\n The iterator is passed a callback(truthValue) which must be called with a \n boolean argument once it has completed.\n* callback(result) - A callback which is called after all the iterator\n functions have finished. Result will be either true or false depending on\n the values of the async tests.\n\n__Example__\n\n```js\nasync.every(['file1','file2','file3'], fs.exists, function(result){\n // if result is true then every file exists\n});\n```\n\n---------------------------------------\n\n<a name=\"concat\" />\n### concat(arr, iterator, callback)\n\nApplies an iterator to each item in a list, concatenating the results. Returns the\nconcatenated list. The iterators are called in parallel, and the results are\nconcatenated as they return. There is no guarantee that the results array will\nbe returned in the original order of the arguments passed to the iterator function.\n\n__Arguments__\n\n* arr - An array to iterate over\n* iterator(item, callback) - A function to apply to each item in the array.\n The iterator is passed a callback(err, results) which must be called once it \n has completed with an error (which can be null) and an array of results.\n* callback(err, results) - A callback which is called after all the iterator\n functions have finished, or an error has occurred. Results is an array containing\n the concatenated results of the iterator function.\n\n__Example__\n\n```js\nasync.concat(['dir1','dir2','dir3'], fs.readdir, function(err, files){\n // files is now a list of filenames that exist in the 3 directories\n});\n```\n\n---------------------------------------\n\n<a name=\"concatSeries\" />\n### concatSeries(arr, iterator, callback)\n\nSame as async.concat, but executes in series instead of parallel.\n\n\n## Control Flow\n\n<a name=\"series\" />\n### series(tasks, [callback])\n\nRun an array of functions in series, each one running once the previous\nfunction has completed. If any functions in the series pass an error to its\ncallback, no more functions are run and the callback for the series is\nimmediately called with the value of the error. Once the tasks have completed,\nthe results are passed to the final callback as an array.\n\nIt is also possible to use an object instead of an array. Each property will be\nrun as a function and the results will be passed to the final callback as an object\ninstead of an array. This can be a more readable way of handling results from\nasync.series.\n\n\n__Arguments__\n\n* tasks - An array or object containing functions to run, each function is passed\n a callback(err, result) it must call on completion with an error (which can\n be null) and an optional result value.\n* callback(err, results) - An optional callback to run once all the functions\n have completed. This function gets a results array (or object) containing all \n the result arguments passed to the task callbacks.\n\n__Example__\n\n```js\nasync.series([\n function(callback){\n // do some stuff ...\n callback(null, 'one');\n },\n function(callback){\n // do some more stuff ...\n callback(null, 'two');\n }\n],\n// optional callback\nfunction(err, results){\n // results is now equal to ['one', 'two']\n});\n\n\n// an example using an object instead of an array\nasync.series({\n one: function(callback){\n setTimeout(function(){\n callback(null, 1);\n }, 200);\n },\n two: function(callback){\n setTimeout(function(){\n callback(null, 2);\n }, 100);\n }\n},\nfunction(err, results) {\n // results is now equal to: {one: 1, two: 2}\n});\n```\n\n---------------------------------------\n\n<a name=\"parallel\" />\n### parallel(tasks, [callback])\n\nRun an array of functions in parallel, without waiting until the previous\nfunction has completed. If any of the functions pass an error to its\ncallback, the main callback is immediately called with the value of the error.\nOnce the tasks have completed, the results are passed to the final callback as an\narray.\n\nIt is also possible to use an object instead of an array. Each property will be\nrun as a function and the results will be passed to the final callback as an object\ninstead of an array. This can be a more readable way of handling results from\nasync.parallel.\n\n\n__Arguments__\n\n* tasks - An array or object containing functions to run, each function is passed \n a callback(err, result) it must call on completion with an error (which can\n be null) and an optional result value.\n* callback(err, results) - An optional callback to run once all the functions\n have completed. This function gets a results array (or object) containing all \n the result arguments passed to the task callbacks.\n\n__Example__\n\n```js\nasync.parallel([\n function(callback){\n setTimeout(function(){\n callback(null, 'one');\n }, 200);\n },\n function(callback){\n setTimeout(function(){\n callback(null, 'two');\n }, 100);\n }\n],\n// optional callback\nfunction(err, results){\n // the results array will equal ['one','two'] even though\n // the second function had a shorter timeout.\n});\n\n\n// an example using an object instead of an array\nasync.parallel({\n one: function(callback){\n setTimeout(function(){\n callback(null, 1);\n }, 200);\n },\n two: function(callback){\n setTimeout(function(){\n callback(null, 2);\n }, 100);\n }\n},\nfunction(err, results) {\n // results is now equals to: {one: 1, two: 2}\n});\n```\n\n---------------------------------------\n\n<a name=\"parallel\" />\n### parallelLimit(tasks, limit, [callback])\n\nThe same as parallel only the tasks are executed in parallel with a maximum of \"limit\" \ntasks executing at any time.\n\nNote that the tasks are not executed in batches, so there is no guarantee that \nthe first \"limit\" tasks will complete before any others are started.\n\n__Arguments__\n\n* tasks - An array or object containing functions to run, each function is passed \n a callback(err, result) it must call on completion with an error (which can\n be null) and an optional result value.\n* limit - The maximum number of tasks to run at any time.\n* callback(err, results) - An optional callback to run once all the functions\n have completed. This function gets a results array (or object) containing all \n the result arguments passed to the task callbacks.\n\n---------------------------------------\n\n<a name=\"whilst\" />\n### whilst(test, fn, callback)\n\nRepeatedly call fn, while test returns true. Calls the callback when stopped,\nor an error occurs.\n\n__Arguments__\n\n* test() - synchronous truth test to perform before each execution of fn.\n* fn(callback) - A function to call each time the test passes. The function is\n passed a callback(err) which must be called once it has completed with an \n optional error argument.\n* callback(err) - A callback which is called after the test fails and repeated\n execution of fn has stopped.\n\n__Example__\n\n```js\nvar count = 0;\n\nasync.whilst(\n function () { return count < 5; },\n function (callback) {\n count++;\n setTimeout(callback, 1000);\n },\n function (err) {\n // 5 seconds have passed\n }\n);\n```\n\n---------------------------------------\n\n<a name=\"doWhilst\" />\n### doWhilst(fn, test, callback)\n\nThe post check version of whilst. To reflect the difference in the order of operations `test` and `fn` arguments are switched. `doWhilst` is to `whilst` as `do while` is to `while` in plain JavaScript.\n\n---------------------------------------\n\n<a name=\"until\" />\n### until(test, fn, callback)\n\nRepeatedly call fn, until test returns true. Calls the callback when stopped,\nor an error occurs.\n\nThe inverse of async.whilst.\n\n---------------------------------------\n\n<a name=\"doUntil\" />\n### doUntil(fn, test, callback)\n\nLike doWhilst except the test is inverted. Note the argument ordering differs from `until`.\n\n---------------------------------------\n\n<a name=\"forever\" />\n### forever(fn, callback)\n\nCalls the asynchronous function 'fn' repeatedly, in series, indefinitely.\nIf an error is passed to fn's callback then 'callback' is called with the\nerror, otherwise it will never be called.\n\n---------------------------------------\n\n<a name=\"waterfall\" />\n### waterfall(tasks, [callback])\n\nRuns an array of functions in series, each passing their results to the next in\nthe array. However, if any of the functions pass an error to the callback, the\nnext function is not executed and the main callback is immediately called with\nthe error.\n\n__Arguments__\n\n* tasks - An array of functions to run, each function is passed a \n callback(err, result1, result2, ...) it must call on completion. The first\n argument is an error (which can be null) and any further arguments will be \n passed as arguments in order to the next task.\n* callback(err, [results]) - An optional callback to run once all the functions\n have completed. This will be passed the results of the last task's callback.\n\n\n\n__Example__\n\n```js\nasync.waterfall([\n function(callback){\n callback(null, 'one', 'two');\n },\n function(arg1, arg2, callback){\n callback(null, 'three');\n },\n function(arg1, callback){\n // arg1 now equals 'three'\n callback(null, 'done');\n }\n], function (err, result) {\n // result now equals 'done' \n});\n```\n\n---------------------------------------\n<a name=\"compose\" />\n### compose(fn1, fn2...)\n\nCreates a function which is a composition of the passed asynchronous\nfunctions. Each function consumes the return value of the function that\nfollows. Composing functions f(), g() and h() would produce the result of\nf(g(h())), only this version uses callbacks to obtain the return values.\n\nEach function is executed with the `this` binding of the composed function.\n\n__Arguments__\n\n* functions... - the asynchronous functions to compose\n\n\n__Example__\n\n```js\nfunction add1(n, callback) {\n setTimeout(function () {\n callback(null, n + 1);\n }, 10);\n}\n\nfunction mul3(n, callback) {\n setTimeout(function () {\n callback(null, n * 3);\n }, 10);\n}\n\nvar add1mul3 = async.compose(mul3, add1);\n\nadd1mul3(4, function (err, result) {\n // result now equals 15\n});\n```\n\n---------------------------------------\n<a name=\"applyEach\" />\n### applyEach(fns, args..., callback)\n\nApplies the provided arguments to each function in the array, calling the\ncallback after all functions have completed. If you only provide the first\nargument then it will return a function which lets you pass in the\narguments as if it were a single function call.\n\n__Arguments__\n\n* fns - the asynchronous functions to all call with the same arguments\n* args... - any number of separate arguments to pass to the function\n* callback - the final argument should be the callback, called when all\n functions have completed processing\n\n\n__Example__\n\n```js\nasync.applyEach([enableSearch, updateSchema], 'bucket', callback);\n\n// partial application example:\nasync.each(\n buckets,\n async.applyEach([enableSearch, updateSchema]),\n callback\n);\n```\n\n---------------------------------------\n\n<a name=\"applyEachSeries\" />\n### applyEachSeries(arr, iterator, callback)\n\nThe same as applyEach only the functions are applied in series.\n\n---------------------------------------\n\n<a name=\"queue\" />\n### queue(worker, concurrency)\n\nCreates a queue object with the specified concurrency. Tasks added to the\nqueue will be processed in parallel (up to the concurrency limit). If all\nworkers are in progress, the task is queued until one is available. Once\na worker has completed a task, the task's callback is called.\n\n__Arguments__\n\n* worker(task, callback) - An asynchronous function for processing a queued\n task, which must call its callback(err) argument when finished, with an \n optional error as an argument.\n* concurrency - An integer for determining how many worker functions should be\n run in parallel.\n\n__Queue objects__\n\nThe queue object returned by this function has the following properties and\nmethods:\n\n* length() - a function returning the number of items waiting to be processed.\n* concurrency - an integer for determining how many worker functions should be\n run in parallel. This property can be changed after a queue is created to\n alter the concurrency on-the-fly.\n* push(task, [callback]) - add a new task to the queue, the callback is called\n once the worker has finished processing the task.\n instead of a single task, an array of tasks can be submitted. the respective callback is used for every task in the list.\n* unshift(task, [callback]) - add a new task to the front of the queue.\n* saturated - a callback that is called when the queue length hits the concurrency and further tasks will be queued\n* empty - a callback that is called when the last item from the queue is given to a worker\n* drain - a callback that is called when the last item from the queue has returned from the worker\n\n__Example__\n\n```js\n// create a queue object with concurrency 2\n\nvar q = async.queue(function (task, callback) {\n console.log('hello ' + task.name);\n callback();\n}, 2);\n\n\n// assign a callback\nq.drain = function() {\n console.log('all items have been processed');\n}\n\n// add some items to the queue\n\nq.push({name: 'foo'}, function (err) {\n console.log('finished processing foo');\n});\nq.push({name: 'bar'}, function (err) {\n console.log('finished processing bar');\n});\n\n// add some items to the queue (batch-wise)\n\nq.push([{name: 'baz'},{name: 'bay'},{name: 'bax'}], function (err) {\n console.log('finished processing bar');\n});\n\n// add some items to the front of the queue\n\nq.unshift({name: 'bar'}, function (err) {\n console.log('finished processing bar');\n});\n```\n\n---------------------------------------\n\n<a name=\"cargo\" />\n### cargo(worker, [payload])\n\nCreates a cargo object with the specified payload. Tasks added to the\ncargo will be processed altogether (up to the payload limit). If the\nworker is in progress, the task is queued until it is available. Once\nthe worker has completed some tasks, each callback of those tasks is called.\n\n__Arguments__\n\n* worker(tasks, callback) - An asynchronous function for processing an array of\n queued tasks, which must call its callback(err) argument when finished, with \n an optional error as an argument.\n* payload - An optional integer for determining how many tasks should be\n processed per round; if omitted, the default is unlimited.\n\n__Cargo objects__\n\nThe cargo object returned by this function has the following properties and\nmethods:\n\n* length() - a function returning the number of items waiting to be processed.\n* payload - an integer for determining how many tasks should be\n process per round. This property can be changed after a cargo is created to\n alter the payload on-the-fly.\n* push(task, [callback]) - add a new task to the queue, the callback is called\n once the worker has finished processing the task.\n instead of a single task, an array of tasks can be submitted. the respective callback is used for every task in the list.\n* saturated - a callback that is called when the queue length hits the concurrency and further tasks will be queued\n* empty - a callback that is called when the last item from the queue is given to a worker\n* drain - a callback that is called when the last item from the queue has returned from the worker\n\n__Example__\n\n```js\n// create a cargo object with payload 2\n\nvar cargo = async.cargo(function (tasks, callback) {\n for(var i=0; i<tasks.length; i++){\n console.log('hello ' + tasks[i].name);\n }\n callback();\n}, 2);\n\n\n// add some items\n\ncargo.push({name: 'foo'}, function (err) {\n console.log('finished processing foo');\n});\ncargo.push({name: 'bar'}, function (err) {\n console.log('finished processing bar');\n});\ncargo.push({name: 'baz'}, function (err) {\n console.log('finished processing baz');\n});\n```\n\n---------------------------------------\n\n<a name=\"auto\" />\n### auto(tasks, [callback])\n\nDetermines the best order for running functions based on their requirements.\nEach function can optionally depend on other functions being completed first,\nand each function is run as soon as its requirements are satisfied. If any of\nthe functions pass an error to their callback, that function will not complete\n(so any other functions depending on it will not run) and the main callback\nwill be called immediately with the error. Functions also receive an object\ncontaining the results of functions which have completed so far.\n\nNote, all functions are called with a results object as a second argument, \nso it is unsafe to pass functions in the tasks object which cannot handle the\nextra argument. For example, this snippet of code:\n\n```js\nasync.auto({\n readData: async.apply(fs.readFile, 'data.txt', 'utf-8');\n}, callback);\n```\n\nwill have the effect of calling readFile with the results object as the last\nargument, which will fail:\n\n```js\nfs.readFile('data.txt', 'utf-8', cb, {});\n```\n\nInstead, wrap the call to readFile in a function which does not forward the \nresults object:\n\n```js\nasync.auto({\n readData: function(cb, results){\n fs.readFile('data.txt', 'utf-8', cb);\n }\n}, callback);\n```\n\n__Arguments__\n\n* tasks - An object literal containing named functions or an array of\n requirements, with the function itself the last item in the array. The key\n used for each function or array is used when specifying requirements. The \n function receives two arguments: (1) a callback(err, result) which must be \n called when finished, passing an error (which can be null) and the result of \n the function's execution, and (2) a results object, containing the results of\n the previously executed functions.\n* callback(err, results) - An optional callback which is called when all the\n tasks have been completed. The callback will receive an error as an argument\n if any tasks pass an error to their callback. Results will always be passed\n\tbut if an error occurred, no other tasks will be performed, and the results\n\tobject will only contain partial results.\n \n\n__Example__\n\n```js\nasync.auto({\n get_data: function(callback){\n // async code to get some data\n },\n make_folder: function(callback){\n // async code to create a directory to store a file in\n // this is run at the same time as getting the data\n },\n write_file: ['get_data', 'make_folder', function(callback){\n // once there is some data and the directory exists,\n // write the data to a file in the directory\n callback(null, filename);\n }],\n email_link: ['write_file', function(callback, results){\n // once the file is written let's email a link to it...\n // results.write_file contains the filename returned by write_file.\n }]\n});\n```\n\nThis is a fairly trivial example, but to do this using the basic parallel and\nseries functions would look like this:\n\n```js\nasync.parallel([\n function(callback){\n // async code to get some data\n },\n function(callback){\n // async code to create a directory to store a file in\n // this is run at the same time as getting the data\n }\n],\nfunction(err, results){\n async.series([\n function(callback){\n // once there is some data and the directory exists,\n // write the data to a file in the directory\n },\n function(callback){\n // once the file is written let's email a link to it...\n }\n ]);\n});\n```\n\nFor a complicated series of async tasks using the auto function makes adding\nnew tasks much easier and makes the code more readable.\n\n\n---------------------------------------\n\n<a name=\"iterator\" />\n### iterator(tasks)\n\nCreates an iterator function which calls the next function in the array,\nreturning a continuation to call the next one after that. It's also possible to\n'peek' the next iterator by doing iterator.next().\n\nThis function is used internally by the async module but can be useful when\nyou want to manually control the flow of functions in series.\n\n__Arguments__\n\n* tasks - An array of functions to run.\n\n__Example__\n\n```js\nvar iterator = async.iterator([\n function(){ sys.p('one'); },\n function(){ sys.p('two'); },\n function(){ sys.p('three'); }\n]);\n\nnode> var iterator2 = iterator();\n'one'\nnode> var iterator3 = iterator2();\n'two'\nnode> iterator3();\n'three'\nnode> var nextfn = iterator2.next();\nnode> nextfn();\n'three'\n```\n\n---------------------------------------\n\n<a name=\"apply\" />\n### apply(function, arguments..)\n\nCreates a continuation function with some arguments already applied, a useful\nshorthand when combined with other control flow functions. Any arguments\npassed to the returned function are added to the arguments originally passed\nto apply.\n\n__Arguments__\n\n* function - The function you want to eventually apply all arguments to.\n* arguments... - Any number of arguments to automatically apply when the\n continuation is called.\n\n__Example__\n\n```js\n// using apply\n\nasync.parallel([\n async.apply(fs.writeFile, 'testfile1', 'test1'),\n async.apply(fs.writeFile, 'testfile2', 'test2'),\n]);\n\n\n// the same process without using apply\n\nasync.parallel([\n function(callback){\n fs.writeFile('testfile1', 'test1', callback);\n },\n function(callback){\n fs.writeFile('testfile2', 'test2', callback);\n }\n]);\n```\n\nIt's possible to pass any number of additional arguments when calling the\ncontinuation:\n\n```js\nnode> var fn = async.apply(sys.puts, 'one');\nnode> fn('two', 'three');\none\ntwo\nthree\n```\n\n---------------------------------------\n\n<a name=\"nextTick\" />\n### nextTick(callback)\n\nCalls the callback on a later loop around the event loop. In node.js this just\ncalls process.nextTick, in the browser it falls back to setImmediate(callback)\nif available, otherwise setTimeout(callback, 0), which means other higher priority\nevents may precede the execution of the callback.\n\nThis is used internally for browser-compatibility purposes.\n\n__Arguments__\n\n* callback - The function to call on a later loop around the event loop.\n\n__Example__\n\n```js\nvar call_order = [];\nasync.nextTick(function(){\n call_order.push('two');\n // call_order now equals ['one','two']\n});\ncall_order.push('one')\n```\n\n<a name=\"times\" />\n### times(n, callback)\n\nCalls the callback n times and accumulates results in the same manner\nyou would use with async.map.\n\n__Arguments__\n\n* n - The number of times to run the function.\n* callback - The function to call n times.\n\n__Example__\n\n```js\n// Pretend this is some complicated async factory\nvar createUser = function(id, callback) {\n callback(null, {\n id: 'user' + id\n })\n}\n// generate 5 users\nasync.times(5, function(n, next){\n createUser(n, function(err, user) {\n next(err, user)\n })\n}, function(err, users) {\n // we should now have 5 users\n});\n```\n\n<a name=\"timesSeries\" />\n### timesSeries(n, callback)\n\nThe same as times only the iterator is applied to each item in the array in\nseries. The next iterator is only called once the current one has completed\nprocessing. The results array will be in the same order as the original.\n\n\n## Utils\n\n<a name=\"memoize\" />\n### memoize(fn, [hasher])\n\nCaches the results of an async function. When creating a hash to store function\nresults against, the callback is omitted from the hash and an optional hash\nfunction can be used.\n\nThe cache of results is exposed as the `memo` property of the function returned\nby `memoize`.\n\n__Arguments__\n\n* fn - the function you to proxy and cache results from.\n* hasher - an optional function for generating a custom hash for storing\n results, it has all the arguments applied to it apart from the callback, and\n must be synchronous.\n\n__Example__\n\n```js\nvar slow_fn = function (name, callback) {\n // do something\n callback(null, result);\n};\nvar fn = async.memoize(slow_fn);\n\n// fn can now be used as if it were slow_fn\nfn('some name', function () {\n // callback\n});\n```\n\n<a name=\"unmemoize\" />\n### unmemoize(fn)\n\nUndoes a memoized function, reverting it to the original, unmemoized\nform. Comes handy in tests.\n\n__Arguments__\n\n* fn - the memoized function\n\n<a name=\"log\" />\n### log(function, arguments)\n\nLogs the result of an async function to the console. Only works in node.js or\nin browsers that support console.log and console.error (such as FF and Chrome).\nIf multiple arguments are returned from the async function, console.log is\ncalled on each argument in order.\n\n__Arguments__\n\n* function - The function you want to eventually apply all arguments to.\n* arguments... - Any number of arguments to apply to the function.\n\n__Example__\n\n```js\nvar hello = function(name, callback){\n setTimeout(function(){\n callback(null, 'hello ' + name);\n }, 1000);\n};\n```\n```js\nnode> async.log(hello, 'world');\n'hello world'\n```\n\n---------------------------------------\n\n<a name=\"dir\" />\n### dir(function, arguments)\n\nLogs the result of an async function to the console using console.dir to\ndisplay the properties of the resulting object. Only works in node.js or\nin browsers that support console.dir and console.error (such as FF and Chrome).\nIf multiple arguments are returned from the async function, console.dir is\ncalled on each argument in order.\n\n__Arguments__\n\n* function - The function you want to eventually apply all arguments to.\n* arguments... - Any number of arguments to apply to the function.\n\n__Example__\n\n```js\nvar hello = function(name, callback){\n setTimeout(function(){\n callback(null, {hello: name});\n }, 1000);\n};\n```\n```js\nnode> async.dir(hello, 'world');\n{hello: 'world'}\n```\n\n---------------------------------------\n\n<a name=\"noConflict\" />\n### noConflict()\n\nChanges the value of async back to its original value, returning a reference to the\nasync object.\n",38 "readme": "# Async.js\n\nAsync is a utility module which provides straight-forward, powerful functions\nfor working with asynchronous JavaScript. Although originally designed for\nuse with [node.js](http://nodejs.org), it can also be used directly in the\nbrowser. Also supports [component](https://github.com/component/component).\n\nAsync provides around 20 functions that include the usual 'functional'\nsuspects (map, reduce, filter, eachâŠ) as well as some common patterns\nfor asynchronous control flow (parallel, series, waterfallâŠ). All these\nfunctions assume you follow the node.js convention of providing a single\ncallback as the last argument of your async function.\n\n\n## Quick Examples\n\n```javascript\nasync.map(['file1','file2','file3'], fs.stat, function(err, results){\n // results is now an array of stats for each file\n});\n\nasync.filter(['file1','file2','file3'], fs.exists, function(results){\n // results now equals an array of the existing files\n});\n\nasync.parallel([\n function(){ ... },\n function(){ ... }\n], callback);\n\nasync.series([\n function(){ ... },\n function(){ ... }\n]);\n```\n\nThere are many more functions available so take a look at the docs below for a\nfull list. This module aims to be comprehensive, so if you feel anything is\nmissing please create a GitHub issue for it.\n\n## Common Pitfalls\n\n### Binding a context to an iterator\n\nThis section is really about bind, not about async. If you are wondering how to\nmake async execute your iterators in a given context, or are confused as to why\na method of another library isn't working as an iterator, study this example:\n\n```js\n// Here is a simple object with an (unnecessarily roundabout) squaring method\nvar AsyncSquaringLibrary = {\n squareExponent: 2,\n square: function(number, callback){ \n var result = Math.pow(number, this.squareExponent);\n setTimeout(function(){\n callback(null, result);\n }, 200);\n }\n};\n\nasync.map([1, 2, 3], AsyncSquaringLibrary.square, function(err, result){\n // result is [NaN, NaN, NaN]\n // This fails because the `this.squareExponent` expression in the square\n // function is not evaluated in the context of AsyncSquaringLibrary, and is\n // therefore undefined.\n});\n\nasync.map([1, 2, 3], AsyncSquaringLibrary.square.bind(AsyncSquaringLibrary), function(err, result){\n // result is [1, 4, 9]\n // With the help of bind we can attach a context to the iterator before\n // passing it to async. Now the square function will be executed in its \n // 'home' AsyncSquaringLibrary context and the value of `this.squareExponent`\n // will be as expected.\n});\n```\n\n## Download\n\nThe source is available for download from\n[GitHub](http://github.com/caolan/async).\nAlternatively, you can install using Node Package Manager (npm):\n\n npm install async\n\n__Development:__ [async.js](https://github.com/caolan/async/raw/master/lib/async.js) - 29.6kb Uncompressed\n\n## In the Browser\n\nSo far it's been tested in IE6, IE7, IE8, FF3.6 and Chrome 5. Usage:\n\n```html\n<script type=\"text/javascript\" src=\"async.js\"></script>\n<script type=\"text/javascript\">\n\n async.map(data, asyncProcess, function(err, results){\n alert(results);\n });\n\n</script>\n```\n\n## Documentation\n\n### Collections\n\n* [each](#each)\n* [eachSeries](#eachSeries)\n* [eachLimit](#eachLimit)\n* [map](#map)\n* [mapSeries](#mapSeries)\n* [mapLimit](#mapLimit)\n* [filter](#filter)\n* [filterSeries](#filterSeries)\n* [reject](#reject)\n* [rejectSeries](#rejectSeries)\n* [reduce](#reduce)\n* [reduceRight](#reduceRight)\n* [detect](#detect)\n* [detectSeries](#detectSeries)\n* [sortBy](#sortBy)\n* [some](#some)\n* [every](#every)\n* [concat](#concat)\n* [concatSeries](#concatSeries)\n\n### Control Flow\n\n* [series](#series)\n* [parallel](#parallel)\n* [parallelLimit](#parallellimittasks-limit-callback)\n* [whilst](#whilst)\n* [doWhilst](#doWhilst)\n* [until](#until)\n* [doUntil](#doUntil)\n* [forever](#forever)\n* [waterfall](#waterfall)\n* [compose](#compose)\n* [applyEach](#applyEach)\n* [applyEachSeries](#applyEachSeries)\n* [queue](#queue)\n* [cargo](#cargo)\n* [auto](#auto)\n* [iterator](#iterator)\n* [apply](#apply)\n* [nextTick](#nextTick)\n* [times](#times)\n* [timesSeries](#timesSeries)\n\n### Utils\n\n* [memoize](#memoize)\n* [unmemoize](#unmemoize)\n* [log](#log)\n* [dir](#dir)\n* [noConflict](#noConflict)\n\n\n## Collections\n\n<a name=\"forEach\" />\n<a name=\"each\" />\n### each(arr, iterator, callback)\n\nApplies an iterator function to each item in an array, in parallel.\nThe iterator is called with an item from the list and a callback for when it\nhas finished. If the iterator passes an error to this callback, the main\ncallback for the each function is immediately called with the error.\n\nNote, that since this function applies the iterator to each item in parallel\nthere is no guarantee that the iterator functions will complete in order.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A function to apply to each item in the array.\n The iterator is passed a callback(err) which must be called once it has \n completed. If no error has occured, the callback should be run without \n arguments or with an explicit null argument.\n* callback(err) - A callback which is called after all the iterator functions\n have finished, or an error has occurred.\n\n__Example__\n\n```js\n// assuming openFiles is an array of file names and saveFile is a function\n// to save the modified contents of that file:\n\nasync.each(openFiles, saveFile, function(err){\n // if any of the saves produced an error, err would equal that error\n});\n```\n\n---------------------------------------\n\n<a name=\"forEachSeries\" />\n<a name=\"eachSeries\" />\n### eachSeries(arr, iterator, callback)\n\nThe same as each only the iterator is applied to each item in the array in\nseries. The next iterator is only called once the current one has completed\nprocessing. This means the iterator functions will complete in order.\n\n\n---------------------------------------\n\n<a name=\"forEachLimit\" />\n<a name=\"eachLimit\" />\n### eachLimit(arr, limit, iterator, callback)\n\nThe same as each only no more than \"limit\" iterators will be simultaneously \nrunning at any time.\n\nNote that the items are not processed in batches, so there is no guarantee that\n the first \"limit\" iterator functions will complete before any others are \nstarted.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* limit - The maximum number of iterators to run at any time.\n* iterator(item, callback) - A function to apply to each item in the array.\n The iterator is passed a callback(err) which must be called once it has \n completed. If no error has occured, the callback should be run without \n arguments or with an explicit null argument.\n* callback(err) - A callback which is called after all the iterator functions\n have finished, or an error has occurred.\n\n__Example__\n\n```js\n// Assume documents is an array of JSON objects and requestApi is a\n// function that interacts with a rate-limited REST api.\n\nasync.eachLimit(documents, 20, requestApi, function(err){\n // if any of the saves produced an error, err would equal that error\n});\n```\n\n---------------------------------------\n\n<a name=\"map\" />\n### map(arr, iterator, callback)\n\nProduces a new array of values by mapping each value in the given array through\nthe iterator function. The iterator is called with an item from the array and a\ncallback for when it has finished processing. The callback takes 2 arguments, \nan error and the transformed item from the array. If the iterator passes an\nerror to this callback, the main callback for the map function is immediately\ncalled with the error.\n\nNote, that since this function applies the iterator to each item in parallel\nthere is no guarantee that the iterator functions will complete in order, however\nthe results array will be in the same order as the original array.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A function to apply to each item in the array.\n The iterator is passed a callback(err, transformed) which must be called once \n it has completed with an error (which can be null) and a transformed item.\n* callback(err, results) - A callback which is called after all the iterator\n functions have finished, or an error has occurred. Results is an array of the\n transformed items from the original array.\n\n__Example__\n\n```js\nasync.map(['file1','file2','file3'], fs.stat, function(err, results){\n // results is now an array of stats for each file\n});\n```\n\n---------------------------------------\n\n<a name=\"mapSeries\" />\n### mapSeries(arr, iterator, callback)\n\nThe same as map only the iterator is applied to each item in the array in\nseries. The next iterator is only called once the current one has completed\nprocessing. The results array will be in the same order as the original.\n\n\n---------------------------------------\n\n<a name=\"mapLimit\" />\n### mapLimit(arr, limit, iterator, callback)\n\nThe same as map only no more than \"limit\" iterators will be simultaneously \nrunning at any time.\n\nNote that the items are not processed in batches, so there is no guarantee that\n the first \"limit\" iterator functions will complete before any others are \nstarted.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* limit - The maximum number of iterators to run at any time.\n* iterator(item, callback) - A function to apply to each item in the array.\n The iterator is passed a callback(err, transformed) which must be called once \n it has completed with an error (which can be null) and a transformed item.\n* callback(err, results) - A callback which is called after all the iterator\n functions have finished, or an error has occurred. Results is an array of the\n transformed items from the original array.\n\n__Example__\n\n```js\nasync.mapLimit(['file1','file2','file3'], 1, fs.stat, function(err, results){\n // results is now an array of stats for each file\n});\n```\n\n---------------------------------------\n\n<a name=\"filter\" />\n### filter(arr, iterator, callback)\n\n__Alias:__ select\n\nReturns a new array of all the values which pass an async truth test.\n_The callback for each iterator call only accepts a single argument of true or\nfalse, it does not accept an error argument first!_ This is in-line with the\nway node libraries work with truth tests like fs.exists. This operation is\nperformed in parallel, but the results array will be in the same order as the\noriginal.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A truth test to apply to each item in the array.\n The iterator is passed a callback(truthValue) which must be called with a \n boolean argument once it has completed.\n* callback(results) - A callback which is called after all the iterator\n functions have finished.\n\n__Example__\n\n```js\nasync.filter(['file1','file2','file3'], fs.exists, function(results){\n // results now equals an array of the existing files\n});\n```\n\n---------------------------------------\n\n<a name=\"filterSeries\" />\n### filterSeries(arr, iterator, callback)\n\n__alias:__ selectSeries\n\nThe same as filter only the iterator is applied to each item in the array in\nseries. The next iterator is only called once the current one has completed\nprocessing. The results array will be in the same order as the original.\n\n---------------------------------------\n\n<a name=\"reject\" />\n### reject(arr, iterator, callback)\n\nThe opposite of filter. Removes values that pass an async truth test.\n\n---------------------------------------\n\n<a name=\"rejectSeries\" />\n### rejectSeries(arr, iterator, callback)\n\nThe same as reject, only the iterator is applied to each item in the array\nin series.\n\n\n---------------------------------------\n\n<a name=\"reduce\" />\n### reduce(arr, memo, iterator, callback)\n\n__aliases:__ inject, foldl\n\nReduces a list of values into a single value using an async iterator to return\neach successive step. Memo is the initial state of the reduction. This\nfunction only operates in series. For performance reasons, it may make sense to\nsplit a call to this function into a parallel map, then use the normal\nArray.prototype.reduce on the results. This function is for situations where\neach step in the reduction needs to be async, if you can get the data before\nreducing it then it's probably a good idea to do so.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* memo - The initial state of the reduction.\n* iterator(memo, item, callback) - A function applied to each item in the\n array to produce the next step in the reduction. The iterator is passed a\n callback(err, reduction) which accepts an optional error as its first \n argument, and the state of the reduction as the second. If an error is \n passed to the callback, the reduction is stopped and the main callback is \n immediately called with the error.\n* callback(err, result) - A callback which is called after all the iterator\n functions have finished. Result is the reduced value.\n\n__Example__\n\n```js\nasync.reduce([1,2,3], 0, function(memo, item, callback){\n // pointless async:\n process.nextTick(function(){\n callback(null, memo + item)\n });\n}, function(err, result){\n // result is now equal to the last value of memo, which is 6\n});\n```\n\n---------------------------------------\n\n<a name=\"reduceRight\" />\n### reduceRight(arr, memo, iterator, callback)\n\n__Alias:__ foldr\n\nSame as reduce, only operates on the items in the array in reverse order.\n\n\n---------------------------------------\n\n<a name=\"detect\" />\n### detect(arr, iterator, callback)\n\nReturns the first value in a list that passes an async truth test. The\niterator is applied in parallel, meaning the first iterator to return true will\nfire the detect callback with that result. That means the result might not be\nthe first item in the original array (in terms of order) that passes the test.\n\nIf order within the original array is important then look at detectSeries.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A truth test to apply to each item in the array.\n The iterator is passed a callback(truthValue) which must be called with a \n boolean argument once it has completed.\n* callback(result) - A callback which is called as soon as any iterator returns\n true, or after all the iterator functions have finished. Result will be\n the first item in the array that passes the truth test (iterator) or the\n value undefined if none passed.\n\n__Example__\n\n```js\nasync.detect(['file1','file2','file3'], fs.exists, function(result){\n // result now equals the first file in the list that exists\n});\n```\n\n---------------------------------------\n\n<a name=\"detectSeries\" />\n### detectSeries(arr, iterator, callback)\n\nThe same as detect, only the iterator is applied to each item in the array\nin series. This means the result is always the first in the original array (in\nterms of array order) that passes the truth test.\n\n\n---------------------------------------\n\n<a name=\"sortBy\" />\n### sortBy(arr, iterator, callback)\n\nSorts a list by the results of running each value through an async iterator.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A function to apply to each item in the array.\n The iterator is passed a callback(err, sortValue) which must be called once it\n has completed with an error (which can be null) and a value to use as the sort\n criteria.\n* callback(err, results) - A callback which is called after all the iterator\n functions have finished, or an error has occurred. Results is the items from\n the original array sorted by the values returned by the iterator calls.\n\n__Example__\n\n```js\nasync.sortBy(['file1','file2','file3'], function(file, callback){\n fs.stat(file, function(err, stats){\n callback(err, stats.mtime);\n });\n}, function(err, results){\n // results is now the original array of files sorted by\n // modified date\n});\n```\n\n---------------------------------------\n\n<a name=\"some\" />\n### some(arr, iterator, callback)\n\n__Alias:__ any\n\nReturns true if at least one element in the array satisfies an async test.\n_The callback for each iterator call only accepts a single argument of true or\nfalse, it does not accept an error argument first!_ This is in-line with the\nway node libraries work with truth tests like fs.exists. Once any iterator\ncall returns true, the main callback is immediately called.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A truth test to apply to each item in the array.\n The iterator is passed a callback(truthValue) which must be called with a \n boolean argument once it has completed.\n* callback(result) - A callback which is called as soon as any iterator returns\n true, or after all the iterator functions have finished. Result will be\n either true or false depending on the values of the async tests.\n\n__Example__\n\n```js\nasync.some(['file1','file2','file3'], fs.exists, function(result){\n // if result is true then at least one of the files exists\n});\n```\n\n---------------------------------------\n\n<a name=\"every\" />\n### every(arr, iterator, callback)\n\n__Alias:__ all\n\nReturns true if every element in the array satisfies an async test.\n_The callback for each iterator call only accepts a single argument of true or\nfalse, it does not accept an error argument first!_ This is in-line with the\nway node libraries work with truth tests like fs.exists.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A truth test to apply to each item in the array.\n The iterator is passed a callback(truthValue) which must be called with a \n boolean argument once it has completed.\n* callback(result) - A callback which is called after all the iterator\n functions have finished. Result will be either true or false depending on\n the values of the async tests.\n\n__Example__\n\n```js\nasync.every(['file1','file2','file3'], fs.exists, function(result){\n // if result is true then every file exists\n});\n```\n\n---------------------------------------\n\n<a name=\"concat\" />\n### concat(arr, iterator, callback)\n\nApplies an iterator to each item in a list, concatenating the results. Returns the\nconcatenated list. The iterators are called in parallel, and the results are\nconcatenated as they return. There is no guarantee that the results array will\nbe returned in the original order of the arguments passed to the iterator function.\n\n__Arguments__\n\n* arr - An array to iterate over\n* iterator(item, callback) - A function to apply to each item in the array.\n The iterator is passed a callback(err, results) which must be called once it \n has completed with an error (which can be null) and an array of results.\n* callback(err, results) - A callback which is called after all the iterator\n functions have finished, or an error has occurred. Results is an array containing\n the concatenated results of the iterator function.\n\n__Example__\n\n```js\nasync.concat(['dir1','dir2','dir3'], fs.readdir, function(err, files){\n // files is now a list of filenames that exist in the 3 directories\n});\n```\n\n---------------------------------------\n\n<a name=\"concatSeries\" />\n### concatSeries(arr, iterator, callback)\n\nSame as async.concat, but executes in series instead of parallel.\n\n\n## Control Flow\n\n<a name=\"series\" />\n### series(tasks, [callback])\n\nRun an array of functions in series, each one running once the previous\nfunction has completed. If any functions in the series pass an error to its\ncallback, no more functions are run and the callback for the series is\nimmediately called with the value of the error. Once the tasks have completed,\nthe results are passed to the final callback as an array.\n\nIt is also possible to use an object instead of an array. Each property will be\nrun as a function and the results will be passed to the final callback as an object\ninstead of an array. This can be a more readable way of handling results from\nasync.series.\n\n\n__Arguments__\n\n* tasks - An array or object containing functions to run, each function is passed\n a callback(err, result) it must call on completion with an error (which can\n be null) and an optional result value.\n* callback(err, results) - An optional callback to run once all the functions\n have completed. This function gets a results array (or object) containing all \n the result arguments passed to the task callbacks.\n\n__Example__\n\n```js\nasync.series([\n function(callback){\n // do some stuff ...\n callback(null, 'one');\n },\n function(callback){\n // do some more stuff ...\n callback(null, 'two');\n }\n],\n// optional callback\nfunction(err, results){\n // results is now equal to ['one', 'two']\n});\n\n\n// an example using an object instead of an array\nasync.series({\n one: function(callback){\n setTimeout(function(){\n callback(null, 1);\n }, 200);\n },\n two: function(callback){\n setTimeout(function(){\n callback(null, 2);\n }, 100);\n }\n},\nfunction(err, results) {\n // results is now equal to: {one: 1, two: 2}\n});\n```\n\n---------------------------------------\n\n<a name=\"parallel\" />\n### parallel(tasks, [callback])\n\nRun an array of functions in parallel, without waiting until the previous\nfunction has completed. If any of the functions pass an error to its\ncallback, the main callback is immediately called with the value of the error.\nOnce the tasks have completed, the results are passed to the final callback as an\narray.\n\nIt is also possible to use an object instead of an array. Each property will be\nrun as a function and the results will be passed to the final callback as an object\ninstead of an array. This can be a more readable way of handling results from\nasync.parallel.\n\n\n__Arguments__\n\n* tasks - An array or object containing functions to run, each function is passed \n a callback(err, result) it must call on completion with an error (which can\n be null) and an optional result value.\n* callback(err, results) - An optional callback to run once all the functions\n have completed. This function gets a results array (or object) containing all \n the result arguments passed to the task callbacks.\n\n__Example__\n\n```js\nasync.parallel([\n function(callback){\n setTimeout(function(){\n callback(null, 'one');\n }, 200);\n },\n function(callback){\n setTimeout(function(){\n callback(null, 'two');\n }, 100);\n }\n],\n// optional callback\nfunction(err, results){\n // the results array will equal ['one','two'] even though\n // the second function had a shorter timeout.\n});\n\n\n// an example using an object instead of an array\nasync.parallel({\n one: function(callback){\n setTimeout(function(){\n callback(null, 1);\n }, 200);\n },\n two: function(callback){\n setTimeout(function(){\n callback(null, 2);\n }, 100);\n }\n},\nfunction(err, results) {\n // results is now equals to: {one: 1, two: 2}\n});\n```\n\n---------------------------------------\n\n<a name=\"parallel\" />\n### parallelLimit(tasks, limit, [callback])\n\nThe same as parallel only the tasks are executed in parallel with a maximum of \"limit\" \ntasks executing at any time.\n\nNote that the tasks are not executed in batches, so there is no guarantee that \nthe first \"limit\" tasks will complete before any others are started.\n\n__Arguments__\n\n* tasks - An array or object containing functions to run, each function is passed \n a callback(err, result) it must call on completion with an error (which can\n be null) and an optional result value.\n* limit - The maximum number of tasks to run at any time.\n* callback(err, results) - An optional callback to run once all the functions\n have completed. This function gets a results array (or object) containing all \n the result arguments passed to the task callbacks.\n\n---------------------------------------\n\n<a name=\"whilst\" />\n### whilst(test, fn, callback)\n\nRepeatedly call fn, while test returns true. Calls the callback when stopped,\nor an error occurs.\n\n__Arguments__\n\n* test() - synchronous truth test to perform before each execution of fn.\n* fn(callback) - A function to call each time the test passes. The function is\n passed a callback(err) which must be called once it has completed with an \n optional error argument.\n* callback(err) - A callback which is called after the test fails and repeated\n execution of fn has stopped.\n\n__Example__\n\n```js\nvar count = 0;\n\nasync.whilst(\n function () { return count < 5; },\n function (callback) {\n count++;\n setTimeout(callback, 1000);\n },\n function (err) {\n // 5 seconds have passed\n }\n);\n```\n\n---------------------------------------\n\n<a name=\"doWhilst\" />\n### doWhilst(fn, test, callback)\n\nThe post check version of whilst. To reflect the difference in the order of operations `test` and `fn` arguments are switched. `doWhilst` is to `whilst` as `do while` is to `while` in plain JavaScript.\n\n---------------------------------------\n\n<a name=\"until\" />\n### until(test, fn, callback)\n\nRepeatedly call fn, until test returns true. Calls the callback when stopped,\nor an error occurs.\n\nThe inverse of async.whilst.\n\n---------------------------------------\n\n<a name=\"doUntil\" />\n### doUntil(fn, test, callback)\n\nLike doWhilst except the test is inverted. Note the argument ordering differs from `until`.\n\n---------------------------------------\n\n<a name=\"forever\" />\n### forever(fn, callback)\n\nCalls the asynchronous function 'fn' repeatedly, in series, indefinitely.\nIf an error is passed to fn's callback then 'callback' is called with the\nerror, otherwise it will never be called.\n\n---------------------------------------\n\n<a name=\"waterfall\" />\n### waterfall(tasks, [callback])\n\nRuns an array of functions in series, each passing their results to the next in\nthe array. However, if any of the functions pass an error to the callback, the\nnext function is not executed and the main callback is immediately called with\nthe error.\n\n__Arguments__\n\n* tasks - An array of functions to run, each function is passed a \n callback(err, result1, result2, ...) it must call on completion. The first\n argument is an error (which can be null) and any further arguments will be \n passed as arguments in order to the next task.\n* callback(err, [results]) - An optional callback to run once all the functions\n have completed. This will be passed the results of the last task's callback.\n\n\n\n__Example__\n\n```js\nasync.waterfall([\n function(callback){\n callback(null, 'one', 'two');\n },\n function(arg1, arg2, callback){\n callback(null, 'three');\n },\n function(arg1, callback){\n // arg1 now equals 'three'\n callback(null, 'done');\n }\n], function (err, result) {\n // result now equals 'done' \n});\n```\n\n---------------------------------------\n<a name=\"compose\" />\n### compose(fn1, fn2...)\n\nCreates a function which is a composition of the passed asynchronous\nfunctions. Each function consumes the return value of the function that\nfollows. Composing functions f(), g() and h() would produce the result of\nf(g(h())), only this version uses callbacks to obtain the return values.\n\nEach function is executed with the `this` binding of the composed function.\n\n__Arguments__\n\n* functions... - the asynchronous functions to compose\n\n\n__Example__\n\n```js\nfunction add1(n, callback) {\n setTimeout(function () {\n callback(null, n + 1);\n }, 10);\n}\n\nfunction mul3(n, callback) {\n setTimeout(function () {\n callback(null, n * 3);\n }, 10);\n}\n\nvar add1mul3 = async.compose(mul3, add1);\n\nadd1mul3(4, function (err, result) {\n // result now equals 15\n});\n```\n\n---------------------------------------\n<a name=\"applyEach\" />\n### applyEach(fns, args..., callback)\n\nApplies the provided arguments to each function in the array, calling the\ncallback after all functions have completed. If you only provide the first\nargument then it will return a function which lets you pass in the\narguments as if it were a single function call.\n\n__Arguments__\n\n* fns - the asynchronous functions to all call with the same arguments\n* args... - any number of separate arguments to pass to the function\n* callback - the final argument should be the callback, called when all\n functions have completed processing\n\n\n__Example__\n\n```js\nasync.applyEach([enableSearch, updateSchema], 'bucket', callback);\n\n// partial application example:\nasync.each(\n buckets,\n async.applyEach([enableSearch, updateSchema]),\n callback\n);\n```\n\n---------------------------------------\n\n<a name=\"applyEachSeries\" />\n### applyEachSeries(arr, iterator, callback)\n\nThe same as applyEach only the functions are applied in series.\n\n---------------------------------------\n\n<a name=\"queue\" />\n### queue(worker, concurrency)\n\nCreates a queue object with the specified concurrency. Tasks added to the\nqueue will be processed in parallel (up to the concurrency limit). If all\nworkers are in progress, the task is queued until one is available. Once\na worker has completed a task, the task's callback is called.\n\n__Arguments__\n\n* worker(task, callback) - An asynchronous function for processing a queued\n task, which must call its callback(err) argument when finished, with an \n optional error as an argument.\n* concurrency - An integer for determining how many worker functions should be\n run in parallel.\n\n__Queue objects__\n\nThe queue object returned by this function has the following properties and\nmethods:\n\n* length() - a function returning the number of items waiting to be processed.\n* concurrency - an integer for determining how many worker functions should be\n run in parallel. This property can be changed after a queue is created to\n alter the concurrency on-the-fly.\n* push(task, [callback]) - add a new task to the queue, the callback is called\n once the worker has finished processing the task.\n instead of a single task, an array of tasks can be submitted. the respective callback is used for every task in the list.\n* unshift(task, [callback]) - add a new task to the front of the queue.\n* saturated - a callback that is called when the queue length hits the concurrency and further tasks will be queued\n* empty - a callback that is called when the last item from the queue is given to a worker\n* drain - a callback that is called when the last item from the queue has returned from the worker\n\n__Example__\n\n```js\n// create a queue object with concurrency 2\n\nvar q = async.queue(function (task, callback) {\n console.log('hello ' + task.name);\n callback();\n}, 2);\n\n\n// assign a callback\nq.drain = function() {\n console.log('all items have been processed');\n}\n\n// add some items to the queue\n\nq.push({name: 'foo'}, function (err) {\n console.log('finished processing foo');\n});\nq.push({name: 'bar'}, function (err) {\n console.log('finished processing bar');\n});\n\n// add some items to the queue (batch-wise)\n\nq.push([{name: 'baz'},{name: 'bay'},{name: 'bax'}], function (err) {\n console.log('finished processing bar');\n});\n\n// add some items to the front of the queue\n\nq.unshift({name: 'bar'}, function (err) {\n console.log('finished processing bar');\n});\n```\n\n---------------------------------------\n\n<a name=\"cargo\" />\n### cargo(worker, [payload])\n\nCreates a cargo object with the specified payload. Tasks added to the\ncargo will be processed altogether (up to the payload limit). If the\nworker is in progress, the task is queued until it is available. Once\nthe worker has completed some tasks, each callback of those tasks is called.\n\n__Arguments__\n\n* worker(tasks, callback) - An asynchronous function for processing an array of\n queued tasks, which must call its callback(err) argument when finished, with \n an optional error as an argument.\n* payload - An optional integer for determining how many tasks should be\n processed per round; if omitted, the default is unlimited.\n\n__Cargo objects__\n\nThe cargo object returned by this function has the following properties and\nmethods:\n\n* length() - a function returning the number of items waiting to be processed.\n* payload - an integer for determining how many tasks should be\n process per round. This property can be changed after a cargo is created to\n alter the payload on-the-fly.\n* push(task, [callback]) - add a new task to the queue, the callback is called\n once the worker has finished processing the task.\n instead of a single task, an array of tasks can be submitted. the respective callback is used for every task in the list.\n* saturated - a callback that is called when the queue length hits the concurrency and further tasks will be queued\n* empty - a callback that is called when the last item from the queue is given to a worker\n* drain - a callback that is called when the last item from the queue has returned from the worker\n\n__Example__\n\n```js\n// create a cargo object with payload 2\n\nvar cargo = async.cargo(function (tasks, callback) {\n for(var i=0; i<tasks.length; i++){\n console.log('hello ' + tasks[i].name);\n }\n callback();\n}, 2);\n\n\n// add some items\n\ncargo.push({name: 'foo'}, function (err) {\n console.log('finished processing foo');\n});\ncargo.push({name: 'bar'}, function (err) {\n console.log('finished processing bar');\n});\ncargo.push({name: 'baz'}, function (err) {\n console.log('finished processing baz');\n});\n```\n\n---------------------------------------\n\n<a name=\"auto\" />\n### auto(tasks, [callback])\n\nDetermines the best order for running functions based on their requirements.\nEach function can optionally depend on other functions being completed first,\nand each function is run as soon as its requirements are satisfied. If any of\nthe functions pass an error to their callback, that function will not complete\n(so any other functions depending on it will not run) and the main callback\nwill be called immediately with the error. Functions also receive an object\ncontaining the results of functions which have completed so far.\n\nNote, all functions are called with a results object as a second argument, \nso it is unsafe to pass functions in the tasks object which cannot handle the\nextra argument. For example, this snippet of code:\n\n```js\nasync.auto({\n readData: async.apply(fs.readFile, 'data.txt', 'utf-8')\n}, callback);\n```\n\nwill have the effect of calling readFile with the results object as the last\nargument, which will fail:\n\n```js\nfs.readFile('data.txt', 'utf-8', cb, {});\n```\n\nInstead, wrap the call to readFile in a function which does not forward the \nresults object:\n\n```js\nasync.auto({\n readData: function(cb, results){\n fs.readFile('data.txt', 'utf-8', cb);\n }\n}, callback);\n```\n\n__Arguments__\n\n* tasks - An object literal containing named functions or an array of\n requirements, with the function itself the last item in the array. The key\n used for each function or array is used when specifying requirements. The \n function receives two arguments: (1) a callback(err, result) which must be \n called when finished, passing an error (which can be null) and the result of \n the function's execution, and (2) a results object, containing the results of\n the previously executed functions.\n* callback(err, results) - An optional callback which is called when all the\n tasks have been completed. The callback will receive an error as an argument\n if any tasks pass an error to their callback. Results will always be passed\n\tbut if an error occurred, no other tasks will be performed, and the results\n\tobject will only contain partial results.\n \n\n__Example__\n\n```js\nasync.auto({\n get_data: function(callback){\n // async code to get some data\n },\n make_folder: function(callback){\n // async code to create a directory to store a file in\n // this is run at the same time as getting the data\n },\n write_file: ['get_data', 'make_folder', function(callback){\n // once there is some data and the directory exists,\n // write the data to a file in the directory\n callback(null, filename);\n }],\n email_link: ['write_file', function(callback, results){\n // once the file is written let's email a link to it...\n // results.write_file contains the filename returned by write_file.\n }]\n});\n```\n\nThis is a fairly trivial example, but to do this using the basic parallel and\nseries functions would look like this:\n\n```js\nasync.parallel([\n function(callback){\n // async code to get some data\n },\n function(callback){\n // async code to create a directory to store a file in\n // this is run at the same time as getting the data\n }\n],\nfunction(err, results){\n async.series([\n function(callback){\n // once there is some data and the directory exists,\n // write the data to a file in the directory\n },\n function(callback){\n // once the file is written let's email a link to it...\n }\n ]);\n});\n```\n\nFor a complicated series of async tasks using the auto function makes adding\nnew tasks much easier and makes the code more readable.\n\n\n---------------------------------------\n\n<a name=\"iterator\" />\n### iterator(tasks)\n\nCreates an iterator function which calls the next function in the array,\nreturning a continuation to call the next one after that. It's also possible to\n'peek' the next iterator by doing iterator.next().\n\nThis function is used internally by the async module but can be useful when\nyou want to manually control the flow of functions in series.\n\n__Arguments__\n\n* tasks - An array of functions to run.\n\n__Example__\n\n```js\nvar iterator = async.iterator([\n function(){ sys.p('one'); },\n function(){ sys.p('two'); },\n function(){ sys.p('three'); }\n]);\n\nnode> var iterator2 = iterator();\n'one'\nnode> var iterator3 = iterator2();\n'two'\nnode> iterator3();\n'three'\nnode> var nextfn = iterator2.next();\nnode> nextfn();\n'three'\n```\n\n---------------------------------------\n\n<a name=\"apply\" />\n### apply(function, arguments..)\n\nCreates a continuation function with some arguments already applied, a useful\nshorthand when combined with other control flow functions. Any arguments\npassed to the returned function are added to the arguments originally passed\nto apply.\n\n__Arguments__\n\n* function - The function you want to eventually apply all arguments to.\n* arguments... - Any number of arguments to automatically apply when the\n continuation is called.\n\n__Example__\n\n```js\n// using apply\n\nasync.parallel([\n async.apply(fs.writeFile, 'testfile1', 'test1'),\n async.apply(fs.writeFile, 'testfile2', 'test2'),\n]);\n\n\n// the same process without using apply\n\nasync.parallel([\n function(callback){\n fs.writeFile('testfile1', 'test1', callback);\n },\n function(callback){\n fs.writeFile('testfile2', 'test2', callback);\n }\n]);\n```\n\nIt's possible to pass any number of additional arguments when calling the\ncontinuation:\n\n```js\nnode> var fn = async.apply(sys.puts, 'one');\nnode> fn('two', 'three');\none\ntwo\nthree\n```\n\n---------------------------------------\n\n<a name=\"nextTick\" />\n### nextTick(callback)\n\nCalls the callback on a later loop around the event loop. In node.js this just\ncalls process.nextTick, in the browser it falls back to setImmediate(callback)\nif available, otherwise setTimeout(callback, 0), which means other higher priority\nevents may precede the execution of the callback.\n\nThis is used internally for browser-compatibility purposes.\n\n__Arguments__\n\n* callback - The function to call on a later loop around the event loop.\n\n__Example__\n\n```js\nvar call_order = [];\nasync.nextTick(function(){\n call_order.push('two');\n // call_order now equals ['one','two']\n});\ncall_order.push('one')\n```\n\n<a name=\"times\" />\n### times(n, callback)\n\nCalls the callback n times and accumulates results in the same manner\nyou would use with async.map.\n\n__Arguments__\n\n* n - The number of times to run the function.\n* callback - The function to call n times.\n\n__Example__\n\n```js\n// Pretend this is some complicated async factory\nvar createUser = function(id, callback) {\n callback(null, {\n id: 'user' + id\n })\n}\n// generate 5 users\nasync.times(5, function(n, next){\n createUser(n, function(err, user) {\n next(err, user)\n })\n}, function(err, users) {\n // we should now have 5 users\n});\n```\n\n<a name=\"timesSeries\" />\n### timesSeries(n, callback)\n\nThe same as times only the iterator is applied to each item in the array in\nseries. The next iterator is only called once the current one has completed\nprocessing. The results array will be in the same order as the original.\n\n\n## Utils\n\n<a name=\"memoize\" />\n### memoize(fn, [hasher])\n\nCaches the results of an async function. When creating a hash to store function\nresults against, the callback is omitted from the hash and an optional hash\nfunction can be used.\n\nThe cache of results is exposed as the `memo` property of the function returned\nby `memoize`.\n\n__Arguments__\n\n* fn - the function you to proxy and cache results from.\n* hasher - an optional function for generating a custom hash for storing\n results, it has all the arguments applied to it apart from the callback, and\n must be synchronous.\n\n__Example__\n\n```js\nvar slow_fn = function (name, callback) {\n // do something\n callback(null, result);\n};\nvar fn = async.memoize(slow_fn);\n\n// fn can now be used as if it were slow_fn\nfn('some name', function () {\n // callback\n});\n```\n\n<a name=\"unmemoize\" />\n### unmemoize(fn)\n\nUndoes a memoized function, reverting it to the original, unmemoized\nform. Comes handy in tests.\n\n__Arguments__\n\n* fn - the memoized function\n\n<a name=\"log\" />\n### log(function, arguments)\n\nLogs the result of an async function to the console. Only works in node.js or\nin browsers that support console.log and console.error (such as FF and Chrome).\nIf multiple arguments are returned from the async function, console.log is\ncalled on each argument in order.\n\n__Arguments__\n\n* function - The function you want to eventually apply all arguments to.\n* arguments... - Any number of arguments to apply to the function.\n\n__Example__\n\n```js\nvar hello = function(name, callback){\n setTimeout(function(){\n callback(null, 'hello ' + name);\n }, 1000);\n};\n```\n```js\nnode> async.log(hello, 'world');\n'hello world'\n```\n\n---------------------------------------\n\n<a name=\"dir\" />\n### dir(function, arguments)\n\nLogs the result of an async function to the console using console.dir to\ndisplay the properties of the resulting object. Only works in node.js or\nin browsers that support console.dir and console.error (such as FF and Chrome).\nIf multiple arguments are returned from the async function, console.dir is\ncalled on each argument in order.\n\n__Arguments__\n\n* function - The function you want to eventually apply all arguments to.\n* arguments... - Any number of arguments to apply to the function.\n\n__Example__\n\n```js\nvar hello = function(name, callback){\n setTimeout(function(){\n callback(null, {hello: name});\n }, 1000);\n};\n```\n```js\nnode> async.dir(hello, 'world');\n{hello: 'world'}\n```\n\n---------------------------------------\n\n<a name=\"noConflict\" />\n### noConflict()\n\nChanges the value of async back to its original value, returning a reference to the\nasync object.\n", 39 39 "readmeFilename": "README.md", 40 40 "homepage": "https://github.com/caolan/async", 41 "_id": "async@0.2. 9",41 "_id": "async@0.2.10", 42 42 "_from": "async@~0.2.9" 43 43 } -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/package.json
r484 r516 28 28 }, 29 29 "_id": "delayed-stream@0.0.5", 30 "_from": "delayed-stream@0.0.5" 30 "_from": "delayed-stream@0.0.5", 31 "scripts": {} 31 32 } -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/node_modules/form-data/node_modules/combined-stream/package.json
r484 r516 29 29 }, 30 30 "_id": "combined-stream@0.0.4", 31 "_from": "combined-stream@~0.0.4" 31 "_from": "combined-stream@~0.0.4", 32 "scripts": {} 32 33 } -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/node_modules/form-data/package.json
r484 r516 43 43 "homepage": "https://github.com/felixge/node-form-data", 44 44 "_id": "form-data@0.1.2", 45 "dist": { 46 "shasum": "19a6c063cb6fd24a82ba888616a6105495eda491" 47 }, 48 "_from": "form-data@~0.1.0", 49 "_resolved": "https://registry.npmjs.org/form-data/-/form-data-0.1.2.tgz" 45 "_from": "form-data@~0.1.0" 50 46 } -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/node_modules/hawk/package.json
r484 r516 50 50 "homepage": "https://github.com/hueniverse/hawk", 51 51 "_id": "hawk@1.0.0", 52 "dist": { 53 "shasum": "e938be8d133181ca7b5e05ac7fc6fa5df66be372" 54 }, 55 "_from": "hawk@~1.0.0", 56 "_resolved": "https://registry.npmjs.org/hawk/-/hawk-1.0.0.tgz" 52 "_from": "hawk@~1.0.0" 57 53 } -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/node_modules/http-signature/node_modules/asn1/package.json
r484 r516 31 31 "scripts": { 32 32 "pretest": "which gjslint; if [[ \"$?\" = 0 ]] ; then gjslint --nojsdoc -r lib -r tst; else echo \"Missing gjslint. Skipping lint\"; fi", 33 "test": " ./node_modules/.bin/tap ./tst"33 "test": "tap ./tst" 34 34 }, 35 35 "readme": "node-asn1 is a library for encoding and decoding ASN.1 datatypes in pure JS.\nCurrently BER encoding is supported; at some point I'll likely have to do DER.\n\n## Usage\n\nMostly, if you're *actually* needing to read and write ASN.1, you probably don't\nneed this readme to explain what and why. If you have no idea what ASN.1 is,\nsee this: ftp://ftp.rsa.com/pub/pkcs/ascii/layman.asc\n\nThe source is pretty much self-explanatory, and has read/write methods for the\ncommon types out there.\n\n### Decoding\n\nThe following reads an ASN.1 sequence with a boolean.\n\n var Ber = require('asn1').Ber;\n\n var reader = new Ber.Reader(new Buffer([0x30, 0x03, 0x01, 0x01, 0xff]));\n\n reader.readSequence();\n console.log('Sequence len: ' + reader.length);\n if (reader.peek() === Ber.Boolean)\n console.log(reader.readBoolean());\n\n### Encoding\n\nThe following generates the same payload as above.\n\n var Ber = require('asn1').Ber;\n\n var writer = new Ber.Writer();\n\n writer.startSequence();\n writer.writeBoolean(true);\n writer.endSequence();\n\n console.log(writer.buffer);\n\n## Installation\n\n npm install asn1\n\n## License\n\nMIT.\n\n## Bugs\n\nSee <https://github.com/mcavage/node-asn1/issues>.\n", -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/node_modules/http-signature/node_modules/assert-plus/package.json
r484 r516 17 17 "readmeFilename": "README.md", 18 18 "_id": "assert-plus@0.1.2", 19 "dist": {20 "shasum": "45a89f54ea7c2d3462aba816e3387f5723659c1e"21 },22 19 "_from": "assert-plus@0.1.2", 23 " _resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-0.1.2.tgz"20 "scripts": {} 24 21 } -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/node_modules/http-signature/node_modules/ctype/package.json
r484 r516 15 15 "readmeFilename": "README", 16 16 "_id": "ctype@0.5.2", 17 "_from": "ctype@0.5.2" 17 "_from": "ctype@0.5.2", 18 "scripts": {} 18 19 } -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/node_modules/http-signature/package.json
r484 r516 15 15 "main": "lib/index.js", 16 16 "scripts": { 17 "test": " ./node_modules/.bin/tap tst/*.js"17 "test": "tap tst/*.js" 18 18 }, 19 19 "dependencies": { -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/node_modules/json-stringify-safe/package.json
r484 r516 30 30 "homepage": "https://github.com/isaacs/json-stringify-safe", 31 31 "_id": "json-stringify-safe@5.0.0", 32 "dist": { 33 "shasum": "80bbe7752a7e12735356aeb2dded57a790bc3ec1" 34 }, 35 "_from": "json-stringify-safe@~5.0.0", 36 "_resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.0.tgz" 32 "_from": "json-stringify-safe@~5.0.0" 37 33 } -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/node_modules/node-uuid/package.json
r484 r516 32 32 "homepage": "https://github.com/broofa/node-uuid", 33 33 "_id": "node-uuid@1.4.1", 34 "_from": "node-uuid@~1.4.0" 34 "_from": "node-uuid@~1.4.0", 35 "scripts": {} 35 36 } -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/node_modules/qs/index.js
r484 r516 38 38 var objectKeys = Object.keys || function(obj) { 39 39 var ret = []; 40 for (var key in obj) ret.push(key); 40 for (var key in obj) { 41 if (obj.hasOwnProperty(key)) { 42 ret.push(key); 43 } 44 } 41 45 return ret; 42 46 }; … … 64 68 65 69 /** 66 * Create a nullary object if possible67 */68 69 function createObject() {70 return Object.create71 ? Object.create(null)72 : {};73 }74 75 /**76 70 * Cache non-integer test regexp. 77 71 */ … … 80 74 81 75 function promote(parent, key) { 82 if (parent[key].length == 0) return parent[key] = createObject();83 var t = createObject();76 if (parent[key].length == 0) return parent[key] = {} 77 var t = {}; 84 78 for (var i in parent[key]) { 85 79 if (hasOwnProperty.call(parent[key], i)) { … … 93 87 function parse(parts, parent, key, val) { 94 88 var part = parts.shift(); 89 90 // illegal 91 if (Object.getOwnPropertyDescriptor(Object.prototype, key)) return; 92 95 93 // end 96 94 if (!part) { … … 141 139 } else { 142 140 if (!isint.test(key) && isArray(parent.base)) { 143 var t = createObject();141 var t = {}; 144 142 for (var k in parent.base) t[k] = parent.base[k]; 145 143 parent.base = t; … … 174 172 } 175 173 176 return obj;177 }178 179 /**180 * Restore Object.prototype.181 * see pull-request #58182 */183 184 function restoreProto(obj) {185 if (!Object.create) return obj;186 if (isArray(obj)) return obj;187 if (obj && 'object' != typeof obj) return obj;188 189 for (var key in obj) {190 if (hasOwnProperty.call(obj, key)) {191 obj[key] = restoreProto(obj[key]);192 }193 }194 195 obj.__proto__ = Object.prototype;196 174 return obj; 197 175 } … … 228 206 229 207 return merge(ret, decode(key), decode(val)); 230 }, { base: createObject()}).base;231 232 return restoreProto(compact(ret));208 }, { base: {} }).base; 209 210 return compact(ret); 233 211 } 234 212 … … 342 320 function set(obj, key, val) { 343 321 var v = obj[key]; 322 if (Object.getOwnPropertyDescriptor(Object.prototype, key)) return; 344 323 if (undefined === v) { 345 324 obj[key] = val; -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/node_modules/qs/package.json
r484 r516 2 2 "name": "qs", 3 3 "description": "querystring parser", 4 "version": "0.6. 5",4 "version": "0.6.6", 5 5 "keywords": [ 6 6 "query string", … … 34 34 }, 35 35 "homepage": "https://github.com/visionmedia/node-querystring", 36 "_id": "qs@0.6. 5",36 "_id": "qs@0.6.6", 37 37 "_from": "qs@~0.6.0" 38 38 } -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/node_modules/tunnel-agent/package.json
r484 r516 25 25 "homepage": "https://github.com/mikeal/tunnel-agent", 26 26 "_id": "tunnel-agent@0.3.0", 27 "_from": "tunnel-agent@~0.3.0" 27 "_from": "tunnel-agent@~0.3.0", 28 "scripts": {} 28 29 } -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/package.json
r484 r516 8 8 "utility" 9 9 ], 10 "version": "2. 27.0",10 "version": "2.34.0", 11 11 "author": { 12 12 "name": "Mikeal Rogers", … … 20 20 "url": "http://github.com/mikeal/request/issues" 21 21 }, 22 "license": "Apache, Version 2.0", 22 23 "engines": [ 23 24 "node >= 0.8.0" … … 28 29 "json-stringify-safe": "~5.0.0", 29 30 "forever-agent": "~0.5.0", 31 "node-uuid": "~1.4.0", 32 "mime": "~1.2.9", 33 "tough-cookie": ">=0.12.0", 34 "form-data": "~0.1.0", 30 35 "tunnel-agent": "~0.3.0", 31 36 "http-signature": "~0.10.0", 37 "oauth-sign": "~0.3.0", 32 38 "hawk": "~1.0.0", 33 "aws-sign": "~0.3.0", 39 "aws-sign2": "~0.5.0" 40 }, 41 "optionalDependencies": { 42 "tough-cookie": ">=0.12.0", 43 "form-data": "~0.1.0", 44 "tunnel-agent": "~0.3.0", 45 "http-signature": "~0.10.0", 34 46 "oauth-sign": "~0.3.0", 35 "cookie-jar": "~0.3.0", 36 "node-uuid": "~1.4.0", 37 "mime": "~1.2.9", 38 "form-data": "~0.1.0" 47 "hawk": "~1.0.0", 48 "aws-sign2": "~0.5.0" 39 49 }, 40 50 "scripts": { 41 51 "test": "node tests/run.js" 42 52 }, 43 "readme": "# Request -- Simplified HTTP client\n\n[](https://nodei.co/npm/request/)\n\n## Super simple to use\n\nRequest is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default.\n\n```javascript\nvar request = require('request');\nrequest('http://www.google.com', function (error, response, body) {\n if (!error && response.statusCode == 200) {\n console.log(body) // Print the google web page.\n }\n})\n```\n\n## Streaming\n\nYou can stream any response to a file stream.\n\n```javascript\nrequest('http://google.com/doodle.png').pipe(fs.createWriteStream('doodle.png'))\n```\n\nYou can also stream a file to a PUT or POST request. This method will also check the file extension against a mapping of file extensions to content-types , in this case `application/json`, and use the proper content-type in the PUT request if one is not already provided in the headers.\n\n```javascript\nfs.createReadStream('file.json').pipe(request.put('http://mysite.com/obj.json'))\n```\n\nRequest can also pipe to itself. When doing so the content-type and content-length will be preserved in the PUT headers.\n\n```javascript\nrequest.get('http://google.com/img.png').pipe(request.put('http://mysite.com/img.png'))\n```\n\nNow let's get fancy.\n\n```javascript\nhttp.createServer(function (req, resp) {\n if (req.url === '/doodle.png') {\n if (req.method === 'PUT') {\n req.pipe(request.put('http://mysite.com/doodle.png'))\n } else if (req.method === 'GET' || req.method === 'HEAD') {\n request.get('http://mysite.com/doodle.png').pipe(resp)\n }\n }\n})\n```\n\nYou can also pipe() from a http.ServerRequest instance and to a http.ServerResponse instance. The HTTP method and headers will be sent as well as the entity-body data. Which means that, if you don't really care about security, you can do:\n\n```javascript\nhttp.createServer(function (req, resp) {\n if (req.url === '/doodle.png') {\n var x = request('http://mysite.com/doodle.png')\n req.pipe(x)\n x.pipe(resp)\n }\n})\n```\n\nAnd since pipe() returns the destination stream in node 0.5.x you can do one line proxying :)\n\n```javascript\nreq.pipe(request('http://mysite.com/doodle.png')).pipe(resp)\n```\n\nAlso, none of this new functionality conflicts with requests previous features, it just expands them.\n\n```javascript\nvar r = request.defaults({'proxy':'http://localproxy.com'})\n\nhttp.createServer(function (req, resp) {\n if (req.url === '/doodle.png') {\n r.get('http://google.com/doodle.png').pipe(resp)\n }\n})\n```\nYou can still use intermediate proxies, the requests will still follow HTTP forwards, etc.\n\n## Forms\n\n`request` supports `application/x-www-form-urlencoded` and `multipart/form-data` form uploads. For `multipart/related` refer to the `multipart` API.\n\nUrl encoded forms are simple\n\n```javascript\nrequest.post('http://service.com/upload', {form:{key:'value'}})\n// or\nrequest.post('http://service.com/upload').form({key:'value'})\n```\n\nFor `multipart/form-data` we use the [form-data](https://github.com/felixge/node-form-data) library by [@felixge](https://github.com/felixge). You don't need to worry about piping the form object or setting the headers, `request` will handle that for you.\n\n```javascript\nvar r = request.post('http://service.com/upload')\nvar form = r.form()\nform.append('my_field', 'my_value')\nform.append('my_buffer', new Buffer([1, 2, 3]))\nform.append('my_file', fs.createReadStream(path.join(__dirname, 'doodle.png'))\nform.append('remote_file', request('http://google.com/doodle.png'))\n```\n\n## HTTP Authentication\n\n```javascript\nrequest.get('http://some.server.com/').auth('username', 'password', false);\n// or\nrequest.get('http://some.server.com/', {\n 'auth': {\n 'user': 'username',\n 'pass': 'password',\n 'sendImmediately': false\n }\n});\n```\n\nIf passed as an option, `auth` should be a hash containing values `user` || `username`, `password` || `pass`, and `sendImmediately` (optional). The method form takes parameters `auth(username, password, sendImmediately)`.\n\n`sendImmediately` defaults to true, which will cause a basic authentication header to be sent. If `sendImmediately` is `false`, then `request` will retry with a proper authentication header after receiving a 401 response from the server (which must contain a `WWW-Authenticate` header indicating the required authentication method).\n\nDigest authentication is supported, but it only works with `sendImmediately` set to `false` (otherwise `request` will send basic authentication on the initial request, which will probably cause the request to fail).\n\n## OAuth Signing\n\n```javascript\n// Twitter OAuth\nvar qs = require('querystring')\n , oauth =\n { callback: 'http://mysite.com/callback/'\n , consumer_key: CONSUMER_KEY\n , consumer_secret: CONSUMER_SECRET\n }\n , url = 'https://api.twitter.com/oauth/request_token'\n ;\nrequest.post({url:url, oauth:oauth}, function (e, r, body) {\n // Ideally, you would take the body in the response\n // and construct a URL that a user clicks on (like a sign in button).\n // The verifier is only available in the response after a user has\n // verified with twitter that they are authorizing your app.\n var access_token = qs.parse(body)\n , oauth =\n { consumer_key: CONSUMER_KEY\n , consumer_secret: CONSUMER_SECRET\n , token: access_token.oauth_token\n , verifier: access_token.oauth_verifier\n }\n , url = 'https://api.twitter.com/oauth/access_token'\n ;\n request.post({url:url, oauth:oauth}, function (e, r, body) {\n var perm_token = qs.parse(body)\n , oauth =\n { consumer_key: CONSUMER_KEY\n , consumer_secret: CONSUMER_SECRET\n , token: perm_token.oauth_token\n , token_secret: perm_token.oauth_token_secret\n }\n , url = 'https://api.twitter.com/1/users/show.json?'\n , params =\n { screen_name: perm_token.screen_name\n , user_id: perm_token.user_id\n }\n ;\n url += qs.stringify(params)\n request.get({url:url, oauth:oauth, json:true}, function (e, r, user) {\n console.log(user)\n })\n })\n})\n```\n\n\n\n### request(options, callback)\n\nThe first argument can be either a url or an options object. The only required option is uri, all others are optional.\n\n* `uri` || `url` - fully qualified uri or a parsed url object from url.parse()\n* `qs` - object containing querystring values to be appended to the uri\n* `method` - http method, defaults to GET\n* `headers` - http headers, defaults to {}\n* `body` - entity body for PATCH, POST and PUT requests. Must be buffer or string.\n* `form` - when passed an object this will set `body` but to a querystring representation of value and adds `Content-type: application/x-www-form-urlencoded; charset=utf-8` header. When passed no option a FormData instance is returned that will be piped to request.\n* `auth` - A hash containing values `user` || `username`, `password` || `pass`, and `sendImmediately` (optional). See documentation above.\n* `json` - sets `body` but to JSON representation of value and adds `Content-type: application/json` header. Additionally, parses the response body as json.\n* `multipart` - (experimental) array of objects which contains their own headers and `body` attribute. Sends `multipart/related` request. See example below.\n* `followRedirect` - follow HTTP 3xx responses as redirects. defaults to true.\n* `followAllRedirects` - follow non-GET HTTP 3xx responses as redirects. defaults to false.\n* `maxRedirects` - the maximum number of redirects to follow, defaults to 10.\n* `encoding` - Encoding to be used on `setEncoding` of response data. If set to `null`, the body is returned as a Buffer.\n* `pool` - A hash object containing the agents for these requests. If omitted this request will use the global pool which is set to node's default maxSockets.\n* `pool.maxSockets` - Integer containing the maximum amount of sockets in the pool.\n* `timeout` - Integer containing the number of milliseconds to wait for a request to respond before aborting the request\n* `proxy` - An HTTP proxy to be used. Support proxy Auth with Basic Auth the same way it's supported with the `url` parameter by embedding the auth info in the uri.\n* `oauth` - Options for OAuth HMAC-SHA1 signing, see documentation above.\n* `hawk` - Options for [Hawk signing](https://github.com/hueniverse/hawk). The `credentials` key must contain the necessary signing info, [see hawk docs for details](https://github.com/hueniverse/hawk#usage-example).\n* `strictSSL` - Set to `true` to require that SSL certificates be valid. Note: to use your own certificate authority, you need to specify an agent that was created with that ca as an option.\n* `jar` - Set to `true` if you want cookies to be remembered for future use, or define your custom cookie jar (see examples section)\n* `aws` - object containing aws signing information, should have the properties `key` and `secret` as well as `bucket` unless you're specifying your bucket as part of the path, or you are making a request that doesn't use a bucket (i.e. GET Services)\n* `httpSignature` - Options for the [HTTP Signature Scheme](https://github.com/joyent/node-http-signature/blob/master/http_signing.md) using [Joyent's library](https://github.com/joyent/node-http-signature). The `keyId` and `key` properties must be specified. See the docs for other options.\n* `localAddress` - Local interface to bind for network connections.\n\n\nThe callback argument gets 3 arguments. The first is an error when applicable (usually from the http.Client option not the http.ClientRequest object). The second is an http.ClientResponse object. The third is the response body String or Buffer.\n\n## Convenience methods\n\nThere are also shorthand methods for different HTTP METHODs and some other conveniences.\n\n### request.defaults(options)\n\nThis method returns a wrapper around the normal request API that defaults to whatever options you pass in to it.\n\n### request.put\n\nSame as request() but defaults to `method: \"PUT\"`.\n\n```javascript\nrequest.put(url)\n```\n\n### request.patch\n\nSame as request() but defaults to `method: \"PATCH\"`.\n\n```javascript\nrequest.patch(url)\n```\n\n### request.post\n\nSame as request() but defaults to `method: \"POST\"`.\n\n```javascript\nrequest.post(url)\n```\n\n### request.head\n\nSame as request() but defaults to `method: \"HEAD\"`.\n\n```javascript\nrequest.head(url)\n```\n\n### request.del\n\nSame as request() but defaults to `method: \"DELETE\"`.\n\n```javascript\nrequest.del(url)\n```\n\n### request.get\n\nAlias to normal request method for uniformity.\n\n```javascript\nrequest.get(url)\n```\n### request.cookie\n\nFunction that creates a new cookie.\n\n```javascript\nrequest.cookie('cookie_string_here')\n```\n### request.jar\n\nFunction that creates a new cookie jar.\n\n```javascript\nrequest.jar()\n```\n\n\n## Examples:\n\n```javascript\n var request = require('request')\n , rand = Math.floor(Math.random()*100000000).toString()\n ;\n request(\n { method: 'PUT'\n , uri: 'http://mikeal.iriscouch.com/testjs/' + rand\n , multipart:\n [ { 'content-type': 'application/json'\n , body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}})\n }\n , { body: 'I am an attachment' }\n ]\n }\n , function (error, response, body) {\n if(response.statusCode == 201){\n console.log('document saved as: http://mikeal.iriscouch.com/testjs/'+ rand)\n } else {\n console.log('error: '+ response.statusCode)\n console.log(body)\n }\n }\n )\n```\nCookies are disabled by default (else, they would be used in subsequent requests). To enable cookies set jar to true (either in defaults or in the options sent).\n\n```javascript\nvar request = request.defaults({jar: true})\nrequest('http://www.google.com', function () {\n request('http://images.google.com')\n})\n```\n\nIf you to use a custom cookie jar (instead of letting request use its own global cookie jar) you do so by setting the jar default or by specifying it as an option:\n\n```javascript\nvar j = request.jar()\nvar request = request.defaults({jar:j})\nrequest('http://www.google.com', function () {\n request('http://images.google.com')\n})\n```\nOR\n\n```javascript\nvar j = request.jar()\nvar cookie = request.cookie('your_cookie_here')\nj.add(cookie)\nrequest({url: 'http://www.google.com', jar: j}, function () {\n request('http://images.google.com')\n})\n```\n",53 "readme": "# Request -- Simplified HTTP client\n\n[](https://nodei.co/npm/request/)\n\n## Super simple to use\n\nRequest is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default.\n\n```javascript\nvar request = require('request');\nrequest('http://www.google.com', function (error, response, body) {\n if (!error && response.statusCode == 200) {\n console.log(body) // Print the google web page.\n }\n})\n```\n\n## Streaming\n\nYou can stream any response to a file stream.\n\n```javascript\nrequest('http://google.com/doodle.png').pipe(fs.createWriteStream('doodle.png'))\n```\n\nYou can also stream a file to a PUT or POST request. This method will also check the file extension against a mapping of file extensions to content-types (in this case `application/json`) and use the proper `content-type` in the PUT request (if the headers donât already provide one).\n\n```javascript\nfs.createReadStream('file.json').pipe(request.put('http://mysite.com/obj.json'))\n```\n\nRequest can also `pipe` to itself. When doing so, `content-type` and `content-length` are preserved in the PUT headers.\n\n```javascript\nrequest.get('http://google.com/img.png').pipe(request.put('http://mysite.com/img.png'))\n```\n\nNow letâs get fancy.\n\n```javascript\nhttp.createServer(function (req, resp) {\n if (req.url === '/doodle.png') {\n if (req.method === 'PUT') {\n req.pipe(request.put('http://mysite.com/doodle.png'))\n } else if (req.method === 'GET' || req.method === 'HEAD') {\n request.get('http://mysite.com/doodle.png').pipe(resp)\n }\n }\n})\n```\n\nYou can also `pipe()` from `http.ServerRequest` instances, as well as to `http.ServerResponse` instances. The HTTP method, headers, and entity-body data will be sent. Which means that, if you don't really care about security, you can do:\n\n```javascript\nhttp.createServer(function (req, resp) {\n if (req.url === '/doodle.png') {\n var x = request('http://mysite.com/doodle.png')\n req.pipe(x)\n x.pipe(resp)\n }\n})\n```\n\nAnd since `pipe()` returns the destination stream in ⥠Node 0.5.x you can do one line proxying. :)\n\n```javascript\nreq.pipe(request('http://mysite.com/doodle.png')).pipe(resp)\n```\n\nAlso, none of this new functionality conflicts with requests previous features, it just expands them.\n\n```javascript\nvar r = request.defaults({'proxy':'http://localproxy.com'})\n\nhttp.createServer(function (req, resp) {\n if (req.url === '/doodle.png') {\n r.get('http://google.com/doodle.png').pipe(resp)\n }\n})\n```\n\nYou can still use intermediate proxies, the requests will still follow HTTP forwards, etc.\n\n## UNIX Socket \n\n`request` supports the `unix://` protocol for all requests. The path is assumed to be absolute to the root of the host file system. \n\nHTTP paths are extracted from the supplied URL by testing each level of the full URL against net.connect for a socket response.\n\nThus the following request will GET `/httppath` from the HTTP server listening on `/tmp/unix.socket`\n\n```javascript\nrequest.get('unix://tmp/unix.socket/httppath')\n```\n\n## Forms\n\n`request` supports `application/x-www-form-urlencoded` and `multipart/form-data` form uploads. For `multipart/related` refer to the `multipart` API.\n\nURL-encoded forms are simple.\n\n```javascript\nrequest.post('http://service.com/upload', {form:{key:'value'}})\n// or\nrequest.post('http://service.com/upload').form({key:'value'})\n```\n\nFor `multipart/form-data` we use the [form-data](https://github.com/felixge/node-form-data) library by [@felixge](https://github.com/felixge). You donât need to worry about piping the form object or setting the headers, `request` will handle that for you.\n\n```javascript\nvar r = request.post('http://service.com/upload')\nvar form = r.form()\nform.append('my_field', 'my_value')\nform.append('my_buffer', new Buffer([1, 2, 3]))\nform.append('my_file', fs.createReadStream(path.join(__dirname, 'doodle.png'))\nform.append('remote_file', request('http://google.com/doodle.png'))\n```\n\n## HTTP Authentication\n\n```javascript\nrequest.get('http://some.server.com/').auth('username', 'password', false);\n// or\nrequest.get('http://some.server.com/', {\n 'auth': {\n 'user': 'username',\n 'pass': 'password',\n 'sendImmediately': false\n }\n});\n```\n\nIf passed as an option, `auth` should be a hash containing values `user` || `username`, `password` || `pass`, and `sendImmediately` (optional). The method form takes parameters `auth(username, password, sendImmediately)`.\n\n`sendImmediately` defaults to `true`, which causes a basic authentication header to be sent. If `sendImmediately` is `false`, then `request` will retry with a proper authentication header after receiving a `401` response from the server (which must contain a `WWW-Authenticate` header indicating the required authentication method).\n\nDigest authentication is supported, but it only works with `sendImmediately` set to `false`; otherwise `request` will send basic authentication on the initial request, which will probably cause the request to fail.\n\n## OAuth Signing\n\n```javascript\n// Twitter OAuth\nvar qs = require('querystring')\n , oauth =\n { callback: 'http://mysite.com/callback/'\n , consumer_key: CONSUMER_KEY\n , consumer_secret: CONSUMER_SECRET\n }\n , url = 'https://api.twitter.com/oauth/request_token'\n ;\nrequest.post({url:url, oauth:oauth}, function (e, r, body) {\n // Ideally, you would take the body in the response\n // and construct a URL that a user clicks on (like a sign in button).\n // The verifier is only available in the response after a user has\n // verified with twitter that they are authorizing your app.\n var access_token = qs.parse(body)\n , oauth =\n { consumer_key: CONSUMER_KEY\n , consumer_secret: CONSUMER_SECRET\n , token: access_token.oauth_token\n , verifier: access_token.oauth_verifier\n }\n , url = 'https://api.twitter.com/oauth/access_token'\n ;\n request.post({url:url, oauth:oauth}, function (e, r, body) {\n var perm_token = qs.parse(body)\n , oauth =\n { consumer_key: CONSUMER_KEY\n , consumer_secret: CONSUMER_SECRET\n , token: perm_token.oauth_token\n , token_secret: perm_token.oauth_token_secret\n }\n , url = 'https://api.twitter.com/1.1/users/show.json?'\n , params =\n { screen_name: perm_token.screen_name\n , user_id: perm_token.user_id\n }\n ;\n url += qs.stringify(params)\n request.get({url:url, oauth:oauth, json:true}, function (e, r, user) {\n console.log(user)\n })\n })\n})\n```\n\n### Custom HTTP Headers\n\nHTTP Headers, such as `User-Agent`, can be set in the `options` object.\nIn the example below, we call the github API to find out the number\nof stars and forks for the request repository. This requires a\ncustom `User-Agent` header as well as https.\n\n```javascript\nvar request = require('request');\n\nvar options = {\n\turl: 'https://api.github.com/repos/mikeal/request',\n\theaders: {\n\t\t'User-Agent': 'request'\n\t}\n};\n\nfunction callback(error, response, body) {\n\tif (!error && response.statusCode == 200) {\n\t\tvar info = JSON.parse(body);\n\t\tconsole.log(info.stargazers_count + \" Stars\");\n\t\tconsole.log(info.forks_count + \" Forks\");\n\t}\n}\n\nrequest(options, callback);\n```\n\n### request(options, callback)\n\nThe first argument can be either a `url` or an `options` object. The only required option is `uri`; all others are optional.\n\n* `uri` || `url` - fully qualified uri or a parsed url object from `url.parse()`\n* `qs` - object containing querystring values to be appended to the `uri`\n* `method` - http method (default: `\"GET\"`)\n* `headers` - http headers (default: `{}`)\n* `body` - entity body for PATCH, POST and PUT requests. Must be a `Buffer` or `String`.\n* `form` - when passed an object, this sets `body` to a querystring representation of value, and adds `Content-type: application/x-www-form-urlencoded; charset=utf-8` header. When passed no options, a `FormData` instance is returned (and is piped to request).\n* `auth` - A hash containing values `user` || `username`, `password` || `pass`, and `sendImmediately` (optional). See documentation above.\n* `json` - sets `body` but to JSON representation of value and adds `Content-type: application/json` header. Additionally, parses the response body as JSON.\n* `multipart` - (experimental) array of objects which contains their own headers and `body` attribute. Sends `multipart/related` request. See example below.\n* `followRedirect` - follow HTTP 3xx responses as redirects (default: `true`)\n* `followAllRedirects` - follow non-GET HTTP 3xx responses as redirects (default: `false`)\n* `maxRedirects` - the maximum number of redirects to follow (default: `10`)\n* `encoding` - Encoding to be used on `setEncoding` of response data. If `null`, the `body` is returned as a `Buffer`.\n* `pool` - A hash object containing the agents for these requests. If omitted, the request will use the global pool (which is set to node's default `maxSockets`)\n* `pool.maxSockets` - Integer containing the maximum amount of sockets in the pool.\n* `timeout` - Integer containing the number of milliseconds to wait for a request to respond before aborting the request\n* `proxy` - An HTTP proxy to be used. Supports proxy Auth with Basic Auth, identical to support for the `url` parameter (by embedding the auth info in the `uri`)\n* `oauth` - Options for OAuth HMAC-SHA1 signing. See documentation above.\n* `hawk` - Options for [Hawk signing](https://github.com/hueniverse/hawk). The `credentials` key must contain the necessary signing info, [see hawk docs for details](https://github.com/hueniverse/hawk#usage-example).\n* `strictSSL` - If `true`, requires SSL certificates be valid. **Note:** to use your own certificate authority, you need to specify an agent that was created with that CA as an option.\n* `jar` - If `true`, remember cookies for future use (or define your custom cookie jar; see examples section)\n* `aws` - `object` containing AWS signing information. Should have the properties `key`, `secret`. Also requires the property `bucket`, unless youâre specifying your `bucket` as part of the path, or the request doesnât use a bucket (i.e. GET Services)\n* `httpSignature` - Options for the [HTTP Signature Scheme](https://github.com/joyent/node-http-signature/blob/master/http_signing.md) using [Joyent's library](https://github.com/joyent/node-http-signature). The `keyId` and `key` properties must be specified. See the docs for other options.\n* `localAddress` - Local interface to bind for network connections.\n\n\nThe callback argument gets 3 arguments: \n\n1. An `error` when applicable (usually from [`http.ClientRequest`](http://nodejs.org/api/http.html#http_class_http_clientrequest) object)\n2. An [`http.IncomingMessage`](http://nodejs.org/api/http.html#http_http_incomingmessage) object\n3. The third is the `response` body (`String` or `Buffer`, or JSON object if the `json` option is supplied)\n\n## Convenience methods\n\nThere are also shorthand methods for different HTTP METHODs and some other conveniences.\n\n### request.defaults(options)\n\nThis method returns a wrapper around the normal request API that defaults to whatever options you pass in to it.\n\n### request.put\n\nSame as `request()`, but defaults to `method: \"PUT\"`.\n\n```javascript\nrequest.put(url)\n```\n\n### request.patch\n\nSame as `request()`, but defaults to `method: \"PATCH\"`.\n\n```javascript\nrequest.patch(url)\n```\n\n### request.post\n\nSame as `request()`, but defaults to `method: \"POST\"`.\n\n```javascript\nrequest.post(url)\n```\n\n### request.head\n\nSame as request() but defaults to `method: \"HEAD\"`.\n\n```javascript\nrequest.head(url)\n```\n\n### request.del\n\nSame as `request()`, but defaults to `method: \"DELETE\"`.\n\n```javascript\nrequest.del(url)\n```\n\n### request.get\n\nSame as `request()` (for uniformity).\n\n```javascript\nrequest.get(url)\n```\n### request.cookie\n\nFunction that creates a new cookie.\n\n```javascript\nrequest.cookie('cookie_string_here')\n```\n### request.jar\n\nFunction that creates a new cookie jar.\n\n```javascript\nrequest.jar()\n```\n\n\n## Examples:\n\n```javascript\n var request = require('request')\n , rand = Math.floor(Math.random()*100000000).toString()\n ;\n request(\n { method: 'PUT'\n , uri: 'http://mikeal.iriscouch.com/testjs/' + rand\n , multipart:\n [ { 'content-type': 'application/json'\n , body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}})\n }\n , { body: 'I am an attachment' }\n ]\n }\n , function (error, response, body) {\n if(response.statusCode == 201){\n console.log('document saved as: http://mikeal.iriscouch.com/testjs/'+ rand)\n } else {\n console.log('error: '+ response.statusCode)\n console.log(body)\n }\n }\n )\n```\n\nCookies are disabled by default (else, they would be used in subsequent requests). To enable cookies, set `jar` to `true` (either in `defaults` or `options`).\n\n```javascript\nvar request = request.defaults({jar: true})\nrequest('http://www.google.com', function () {\n request('http://images.google.com')\n})\n```\n\nTo use a custom cookie jar (instead `request`âs global cookie jar), set `jar` to an instance of `request.jar()` (either in `defaults` or `options`)\n\n```javascript\nvar j = request.jar()\nvar request = request.defaults({jar:j})\nrequest('http://www.google.com', function () {\n request('http://images.google.com')\n})\n```\n\nOR\n\n```javascript\nvar j = request.jar()\nvar cookie = request.cookie('your_cookie_here')\nj.setCookie(cookie, uri);\nrequest({url: 'http://www.google.com', jar: j}, function () {\n request('http://images.google.com')\n})\n```\n", 44 54 "readmeFilename": "README.md", 45 55 "homepage": "https://github.com/mikeal/request", 46 "_id": "request@2. 27.0",56 "_id": "request@2.34.0", 47 57 "dist": { 48 "shasum": " b7f67055f69980e50629f486c4f511f73503644e"58 "shasum": "fd3b7ba1c3598ca8b8a9173ed5bd33546104f8bb" 49 59 }, 50 60 "_from": "request@>=2.12.0", 51 "_resolved": "https://registry.npmjs.org/request/-/request-2. 27.0.tgz"61 "_resolved": "https://registry.npmjs.org/request/-/request-2.34.0.tgz" 52 62 } -
Dev/trunk/node_modules/grunt-contrib-less/node_modules/less/node_modules/request/request.js
r484 r516 1 var http = require('http') 2 , https = false 3 , tls = false 1 var optional = require('./lib/optional') 2 , http = require('http') 3 , https = optional('https') 4 , tls = optional('tls') 4 5 , url = require('url') 5 6 , util = require('util') … … 9 10 , crypto = require('crypto') 10 11 11 , oauth = require('oauth-sign')12 , hawk = require('hawk')13 , aws = require('aws-sign')14 , httpSignature = require('http-signature')12 , oauth = optional('oauth-sign') 13 , hawk = optional('hawk') 14 , aws = optional('aws-sign2') 15 , httpSignature = optional('http-signature') 15 16 , uuid = require('node-uuid') 16 17 , mime = require('mime') 17 , tunnel = require('tunnel-agent')18 , tunnel = optional('tunnel-agent') 18 19 , _safeStringify = require('json-stringify-safe') 19 20 20 21 , ForeverAgent = require('forever-agent') 21 , FormData = require('form-data') 22 23 , Cookie = require('cookie-jar') 24 , CookieJar = Cookie.Jar 25 , cookieJar = new CookieJar 22 , FormData = optional('form-data') 23 24 , cookies = require('./lib/cookies') 25 , globalCookieJar = cookies.jar() 26 26 27 27 , copy = require('./lib/copy') 28 28 , debug = require('./lib/debug') 29 29 , getSafe = require('./lib/getSafe') 30 , net = require('net') 30 31 ; 31 32 … … 38 39 39 40 var globalPool = {} 40 var isUrl = /^https?:/i 41 42 try { 43 https = require('https') 44 } catch (e) {} 45 46 try { 47 tls = require('tls') 48 } catch (e) {} 49 41 var isUrl = /^https?:|^unix:/ 50 42 51 43 … … 66 58 67 59 function isReadStream (rs) { 68 if (rs.readable && rs.path && rs.mode) { 69 return true 70 } 60 return rs.readable && rs.path && rs.mode; 71 61 } 72 62 … … 103 93 } 104 94 95 this.canTunnel = options.tunnel !== false && tunnel; 96 105 97 this.init(options) 106 98 } … … 154 146 155 147 // do the HTTP CONNECT dance using koichik/node-tunnel 156 if (http.globalAgent && self.uri.protocol === "https:" ) {148 if (http.globalAgent && self.uri.protocol === "https:" && self.canTunnel) { 157 149 var tunnelFn = self.proxy.protocol === "http:" 158 150 ? tunnel.httpsOverHttp : tunnel.httpsOverHttps … … 173 165 if (!self.uri.pathname) {self.uri.pathname = '/'} 174 166 175 if (!self.uri.host ) {167 if (!self.uri.host && !self.protocol=='unix:') { 176 168 // Invalid URI: it may generate lot of bad errors, like "TypeError: Cannot call method 'indexOf' of undefined" in CookieJar 177 169 // Detect and reject it as soon as possible … … 180 172 if (Object.keys(options).length === 0) { 181 173 // No option ? This can be the sign of a redirect 182 // As this is a case where the user cannot do anything ( hedidn't call request directly with this URL)183 // heshould be warned that it can be caused by a redirection (can save some hair)174 // As this is a case where the user cannot do anything (they didn't call request directly with this URL) 175 // they should be warned that it can be caused by a redirection (can save some hair) 184 176 message += '. This can be caused by a crappy redirection.' 185 177 } … … 225 217 self.clientErrorHandler = function (error) { 226 218 if (self._aborted) return 227 228 219 if (self.req && self.req._reusedSocket && error.code === 'ECONNRESET' 229 220 && self.agent.addRequestNoreuse) { … … 252 243 } 253 244 254 if (options.form) { 255 self.form(options.form) 256 } 257 258 if (options.qs) self.qs(options.qs) 259 260 if (self.uri.path) { 261 self.path = self.uri.path 245 self._buildRequest = function(){ 246 var self = this; 247 248 if (options.form) { 249 self.form(options.form) 250 } 251 252 if (options.qs) self.qs(options.qs) 253 254 if (self.uri.path) { 255 self.path = self.uri.path 256 } else { 257 self.path = self.uri.pathname + (self.uri.search || "") 258 } 259 260 if (self.path.length === 0) self.path = '/' 261 262 263 // Auth must happen last in case signing is dependent on other headers 264 if (options.oauth) { 265 self.oauth(options.oauth) 266 } 267 268 if (options.aws) { 269 self.aws(options.aws) 270 } 271 272 if (options.hawk) { 273 self.hawk(options.hawk) 274 } 275 276 if (options.httpSignature) { 277 self.httpSignature(options.httpSignature) 278 } 279 280 if (options.auth) { 281 if (Object.prototype.hasOwnProperty.call(options.auth, 'username')) options.auth.user = options.auth.username 282 if (Object.prototype.hasOwnProperty.call(options.auth, 'password')) options.auth.pass = options.auth.password 283 284 self.auth( 285 options.auth.user, 286 options.auth.pass, 287 options.auth.sendImmediately 288 ) 289 } 290 291 if (self.uri.auth && !self.hasHeader('authorization')) { 292 var authPieces = self.uri.auth.split(':').map(function(item){ return querystring.unescape(item) }) 293 self.auth(authPieces[0], authPieces.slice(1).join(':'), true) 294 } 295 if (self.proxy && self.proxy.auth && !self.hasHeader('proxy-authorization') && !self.tunnel) { 296 self.setHeader('proxy-authorization', "Basic " + toBase64(self.proxy.auth.split(':').map(function(item){ return querystring.unescape(item)}).join(':'))) 297 } 298 299 300 if (self.proxy && !self.tunnel) self.path = (self.uri.protocol + '//' + self.uri.host + self.path) 301 302 if (options.json) { 303 self.json(options.json) 304 } else if (options.multipart) { 305 self.boundary = uuid() 306 self.multipart(options.multipart) 307 } 308 309 if (self.body) { 310 var length = 0 311 if (!Buffer.isBuffer(self.body)) { 312 if (Array.isArray(self.body)) { 313 for (var i = 0; i < self.body.length; i++) { 314 length += self.body[i].length 315 } 316 } else { 317 self.body = new Buffer(self.body) 318 length = self.body.length 319 } 320 } else { 321 length = self.body.length 322 } 323 if (length) { 324 if (!self.hasHeader('content-length')) self.setHeader('content-length', length) 325 } else { 326 throw new Error('Argument error, options.body.') 327 } 328 } 329 330 var protocol = self.proxy && !self.tunnel ? self.proxy.protocol : self.uri.protocol 331 , defaultModules = {'http:':http, 'https:':https, 'unix:':http} 332 , httpModules = self.httpModules || {} 333 ; 334 self.httpModule = httpModules[protocol] || defaultModules[protocol] 335 336 if (!self.httpModule) return this.emit('error', new Error("Invalid protocol")) 337 338 if (options.ca) self.ca = options.ca 339 340 if (!self.agent) { 341 if (options.agentOptions) self.agentOptions = options.agentOptions 342 343 if (options.agentClass) { 344 self.agentClass = options.agentClass 345 } else if (options.forever) { 346 self.agentClass = protocol === 'http:' ? ForeverAgent : ForeverAgent.SSL 347 } else { 348 self.agentClass = self.httpModule.Agent 349 } 350 } 351 352 if (self.pool === false) { 353 self.agent = false 354 } else { 355 self.agent = self.agent || self.getAgent() 356 if (self.maxSockets) { 357 // Don't use our pooling if node has the refactored client 358 self.agent.maxSockets = self.maxSockets 359 } 360 if (self.pool.maxSockets) { 361 // Don't use our pooling if node has the refactored client 362 self.agent.maxSockets = self.pool.maxSockets 363 } 364 } 365 366 self.on('pipe', function (src) { 367 if (self.ntick && self._started) throw new Error("You cannot pipe to this stream after the outbound request has started.") 368 self.src = src 369 if (isReadStream(src)) { 370 if (!self.hasHeader('content-type')) self.setHeader('content-type', mime.lookup(src.path)) 371 } else { 372 if (src.headers) { 373 for (var i in src.headers) { 374 if (!self.hasHeader(i)) { 375 self.setHeader(i, src.headers[i]) 376 } 377 } 378 } 379 if (self._json && !self.hasHeader('content-type')) 380 self.setHeader('content-type', 'application/json') 381 if (src.method && !self.explicitMethod) { 382 self.method = src.method 383 } 384 } 385 386 // self.on('pipe', function () { 387 // console.error("You have already piped to this stream. Pipeing twice is likely to break the request.") 388 // }) 389 }) 390 391 process.nextTick(function () { 392 if (self._aborted) return 393 394 if (self._form) { 395 self.setHeaders(self._form.getHeaders()) 396 try { 397 var length = self._form.getLengthSync() 398 self.setHeader('content-length', length) 399 } catch(e){} 400 self._form.pipe(self) 401 } 402 if (self.body) { 403 if (Array.isArray(self.body)) { 404 self.body.forEach(function (part) { 405 self.write(part) 406 }) 407 } else { 408 self.write(self.body) 409 } 410 self.end() 411 } else if (self.requestBodyStream) { 412 console.warn("options.requestBodyStream is deprecated, please pass the request object to stream.pipe.") 413 self.requestBodyStream.pipe(self) 414 } else if (!self.src) { 415 if (self.method !== 'GET' && typeof self.method !== 'undefined') { 416 self.setHeader('content-length', 0) 417 } 418 self.end() 419 } 420 self.ntick = true 421 }) 422 423 } // End _buildRequest 424 425 self._handleUnixSocketURI = function(self){ 426 // Parse URI and extract a socket path (tested as a valid socket using net.connect), and a http style path suffix 427 // Thus http requests can be made to a socket using the uri unix://tmp/my.socket/urlpath 428 // and a request for '/urlpath' will be sent to the unix socket at /tmp/my.socket 429 430 self.unixsocket = true; 431 432 var full_path = self.uri.href.replace(self.uri.protocol+'/', ''); 433 434 var lookup = full_path.split('/'); 435 var error_connecting = true; 436 437 var lookup_table = {}; 438 do { lookup_table[lookup.join('/')]={} } while(lookup.pop()) 439 for (r in lookup_table){ 440 try_next(r); 441 } 442 443 function try_next(table_row){ 444 var client = net.connect( table_row ); 445 client.path = table_row 446 client.on('error', function(){ lookup_table[this.path].error_connecting=true; this.end(); }); 447 client.on('connect', function(){ lookup_table[this.path].error_connecting=false; this.end(); }); 448 table_row.client = client; 449 } 450 451 wait_for_socket_response(); 452 453 response_counter = 0; 454 455 function wait_for_socket_response(){ 456 var detach; 457 if('undefined' == typeof setImmediate ) detach = process.nextTick 458 else detach = setImmediate; 459 detach(function(){ 460 // counter to prevent infinite blocking waiting for an open socket to be found. 461 response_counter++; 462 var trying = false; 463 for (r in lookup_table){ 464 //console.log(r, lookup_table[r], lookup_table[r].error_connecting) 465 if('undefined' == typeof lookup_table[r].error_connecting) 466 trying = true; 467 } 468 if(trying && response_counter<1000) 469 wait_for_socket_response() 470 else 471 set_socket_properties(); 472 }) 473 } 474 475 function set_socket_properties(){ 476 var host; 477 for (r in lookup_table){ 478 if(lookup_table[r].error_connecting === false){ 479 host = r 480 } 481 } 482 if(!host){ 483 self.emit('error', new Error("Failed to connect to any socket in "+full_path)) 484 } 485 var path = full_path.replace(host, '') 486 487 self.socketPath = host 488 self.uri.pathname = path 489 self.uri.href = path 490 self.uri.path = path 491 self.host = '' 492 self.hostname = '' 493 delete self.host 494 delete self.hostname 495 self._buildRequest(); 496 } 497 } 498 499 // Intercept UNIX protocol requests to change properties to match socket 500 if(/^unix:/.test(self.uri.protocol)){ 501 self._handleUnixSocketURI(self); 262 502 } else { 263 self.path = self.uri.pathname + (self.uri.search || "") 264 } 265 266 if (self.path.length === 0) self.path = '/' 267 268 269 // Auth must happen last in case signing is dependent on other headers 270 if (options.oauth) { 271 self.oauth(options.oauth) 272 } 273 274 if (options.aws) { 275 self.aws(options.aws) 276 } 277 278 if (options.hawk) { 279 self.hawk(options.hawk) 280 } 281 282 if (options.httpSignature) { 283 self.httpSignature(options.httpSignature) 284 } 285 286 if (options.auth) { 287 self.auth( 288 (options.auth.user==="") ? options.auth.user : (options.auth.user || options.auth.username ), 289 options.auth.pass || options.auth.password, 290 options.auth.sendImmediately) 291 } 292 293 if (self.uri.auth && !self.hasHeader('authorization')) { 294 var authPieces = self.uri.auth.split(':').map(function(item){ return querystring.unescape(item) }) 295 self.auth(authPieces[0], authPieces.slice(1).join(':'), true) 296 } 297 if (self.proxy && self.proxy.auth && !self.hasHeader('proxy-authorization') && !self.tunnel) { 298 self.setHeader('proxy-authorization', "Basic " + toBase64(self.proxy.auth.split(':').map(function(item){ return querystring.unescape(item)}).join(':'))) 299 } 300 301 302 if (self.proxy && !self.tunnel) self.path = (self.uri.protocol + '//' + self.uri.host + self.path) 303 304 if (options.json) { 305 self.json(options.json) 306 } else if (options.multipart) { 307 self.boundary = uuid() 308 self.multipart(options.multipart) 309 } 310 311 if (self.body) { 312 var length = 0 313 if (!Buffer.isBuffer(self.body)) { 314 if (Array.isArray(self.body)) { 315 for (var i = 0; i < self.body.length; i++) { 316 length += self.body[i].length 317 } 318 } else { 319 self.body = new Buffer(self.body) 320 length = self.body.length 321 } 322 } else { 323 length = self.body.length 324 } 325 if (length) { 326 if (!self.hasHeader('content-length')) self.setHeader('content-length', length) 327 } else { 328 throw new Error('Argument error, options.body.') 329 } 330 } 331 332 var protocol = self.proxy && !self.tunnel ? self.proxy.protocol : self.uri.protocol 333 , defaultModules = {'http:':http, 'https:':https} 334 , httpModules = self.httpModules || {} 335 ; 336 self.httpModule = httpModules[protocol] || defaultModules[protocol] 337 338 if (!self.httpModule) return this.emit('error', new Error("Invalid protocol")) 339 340 if (options.ca) self.ca = options.ca 341 342 if (!self.agent) { 343 if (options.agentOptions) self.agentOptions = options.agentOptions 344 345 if (options.agentClass) { 346 self.agentClass = options.agentClass 347 } else if (options.forever) { 348 self.agentClass = protocol === 'http:' ? ForeverAgent : ForeverAgent.SSL 349 } else { 350 self.agentClass = self.httpModule.Agent 351 } 352 } 353 354 if (self.pool === false) { 355 self.agent = false 356 } else { 357 self.agent = self.agent || self.getAgent() 358 if (self.maxSockets) { 359 // Don't use our pooling if node has the refactored client 360 self.agent.maxSockets = self.maxSockets 361 } 362 if (self.pool.maxSockets) { 363 // Don't use our pooling if node has the refactored client 364 self.agent.maxSockets = self.pool.maxSockets 365 } 366 } 367 368 self.on('pipe', function (src) { 369 if (self.ntick && self._started) throw new Error("You cannot pipe to this stream after the outbound request has started.") 370 self.src = src 371 if (isReadStream(src)) { 372 if (!self.hasHeader('content-type')) self.setHeader('content-type', mime.lookup(src.path)) 373 } else { 374 if (src.headers) { 375 for (var i in src.headers) { 376 if (!self.hasHeader(i)) { 377 self.setHeader(i, src.headers[i]) 378 } 379 } 380 } 381 if (self._json && !self.hasHeader('content-type')) 382 self.setHeader('content-type', 'application/json') 383 if (src.method && !self.explicitMethod) { 384 self.method = src.method 385 } 386 } 387 388 // self.on('pipe', function () { 389 // console.error("You have already piped to this stream. Pipeing twice is likely to break the request.") 390 // }) 391 }) 392 393 process.nextTick(function () { 394 if (self._aborted) return 395 396 if (self._form) { 397 self.setHeaders(self._form.getHeaders()) 398 self._form.pipe(self) 399 } 400 if (self.body) { 401 if (Array.isArray(self.body)) { 402 self.body.forEach(function (part) { 403 self.write(part) 404 }) 405 } else { 406 self.write(self.body) 407 } 408 self.end() 409 } else if (self.requestBodyStream) { 410 console.warn("options.requestBodyStream is deprecated, please pass the request object to stream.pipe.") 411 self.requestBodyStream.pipe(self) 412 } else if (!self.src) { 413 if (self.method !== 'GET' && typeof self.method !== 'undefined') { 414 self.setHeader('content-length', 0) 415 } 416 self.end() 417 } 418 self.ntick = true 419 }) 503 self._buildRequest(); 504 } 505 420 506 } 421 507 … … 430 516 // previously was doing http, now doing https 431 517 // if it's https, then we might need to tunnel now. 432 if (self.proxy ) {518 if (self.proxy && self.canTunnel) { 433 519 self.tunnel = true 434 520 var tunnelFn = self.proxy.protocol === 'http:' … … 493 579 } 494 580 if (this.ca) options.ca = this.ca 581 if (this.ciphers) options.ciphers = this.ciphers 582 if (this.secureProtocol) options.secureProtocol = this.secureProtocol 495 583 if (typeof this.rejectUnauthorized !== 'undefined') options.rejectUnauthorized = this.rejectUnauthorized 496 584 … … 538 626 } 539 627 540 if (options.secure Options) {628 if (options.secureProtocol) { 541 629 if (poolKey) poolKey += ':' 542 poolKey += options.secure Options630 poolKey += options.secureProtocol 543 631 } 544 632 } … … 653 741 } 654 742 743 var targetCookieJar = (self._jar && self._jar.setCookie)?self._jar:globalCookieJar; 655 744 var addCookie = function (cookie) { 656 if (self._jar){ 657 if(self._jar.add){ 658 self._jar.add(new Cookie(cookie)) 659 } 660 else cookieJar.add(new Cookie(cookie)) 661 } 662 745 //set the cookie if it's domain in the href's domain. 746 try { 747 targetCookieJar.setCookie(cookie, self.uri.href, {ignoreError: true}); 748 } catch (e) { 749 self.emit('error', e); 750 } 663 751 } 664 752 … … 691 779 } else if (response.statusCode == 401 && self._hasAuth && !self._sentAuth) { 692 780 var authHeader = response.headers[hasHeader('www-authenticate', response.headers)] 693 var authVerb = authHeader && authHeader.split(' ')[0] 781 var authVerb = authHeader && authHeader.split(' ')[0].toLowerCase() 694 782 debug('reauth', authVerb) 695 783 696 784 switch (authVerb) { 697 case ' Basic':785 case 'basic': 698 786 self.auth(self._user, self._pass, true) 699 787 redirectTo = self.uri 700 788 break 701 789 702 case 'Digest': 703 // TODO: More complete implementation of RFC 2617. For reference: 790 case 'digest': 791 // TODO: More complete implementation of RFC 2617. 792 // - check challenge.algorithm 793 // - support algorithm="MD5-sess" 794 // - handle challenge.domain 795 // - support qop="auth-int" only 796 // - handle Authentication-Info (not necessarily?) 797 // - check challenge.stale (not necessarily?) 798 // - increase nc (not necessarily?) 799 // For reference: 704 800 // http://tools.ietf.org/html/rfc2617#section-3 705 801 // https://github.com/bagder/curl/blob/master/lib/http_digest.c 706 802 707 var matches = authHeader.match(/([a-z0-9_-]+)="([^"]+)"/gi)708 803 var challenge = {} 709 710 for (var i = 0; i < matches.length; i++) { 711 var eqPos = matches[i].indexOf('=') 712 var key = matches[i].substring(0, eqPos) 713 var quotedValue = matches[i].substring(eqPos + 1) 714 challenge[key] = quotedValue.substring(1, quotedValue.length - 1) 804 var re = /([a-z0-9_-]+)=(?:"([^"]+)"|([a-z0-9_-]+))/gi 805 for (;;) { 806 var match = re.exec(authHeader) 807 if (!match) break 808 challenge[match[1]] = match[2] || match[3]; 715 809 } 716 810 717 811 var ha1 = md5(self._user + ':' + challenge.realm + ':' + self._pass) 718 812 var ha2 = md5(self.method + ':' + self.uri.path) 719 var digestResponse = md5(ha1 + ':' + challenge.nonce + ':1::auth:' + ha2) 813 var qop = /(^|,)\s*auth\s*($|,)/.test(challenge.qop) && 'auth' 814 var nc = qop && '00000001' 815 var cnonce = qop && uuid().replace(/-/g, '') 816 var digestResponse = qop ? md5(ha1 + ':' + challenge.nonce + ':' + nc + ':' + cnonce + ':' + qop + ':' + ha2) : md5(ha1 + ':' + challenge.nonce + ':' + ha2) 720 817 var authValues = { 721 818 username: self._user, … … 723 820 nonce: challenge.nonce, 724 821 uri: self.uri.path, 725 qop: challenge.qop,822 qop: qop, 726 823 response: digestResponse, 727 nc: 1, 728 cnonce: '' 824 nc: nc, 825 cnonce: cnonce, 826 algorithm: challenge.algorithm, 827 opaque: challenge.opaque 729 828 } 730 829 731 830 authHeader = [] 732 831 for (var k in authValues) { 733 authHeader.push(k + '="' + authValues[k] + '"') 832 if (!authValues[k]) { 833 //ignore 834 } else if (k === 'qop' || k === 'nc' || k === 'algorithm') { 835 authHeader.push(k + '=' + authValues[k]) 836 } else { 837 authHeader.push(k + '="' + authValues[k] + '"') 838 } 734 839 } 735 840 authHeader = 'Digest ' + authHeader.join(', ') … … 986 1091 self.setHeader('content-type', 'multipart/related; boundary=' + self.boundary) 987 1092 } else { 988 self.setHeader('content-type', self.headers['content-type'].split(';')[0] + '; boundary=' + self.boundary) 1093 var headerName = self.hasHeader('content-type'); 1094 self.setHeader(headerName, self.headers[headerName].split(';')[0] + '; boundary=' + self.boundary) 989 1095 } 990 1096 … … 1020 1126 if (typeof this.body === 'object') { 1021 1127 this.body = safeStringify(this.body) 1022 self.setHeader('content-type', 'application/json') 1128 if (!self.hasHeader('content-type')) 1129 self.setHeader('content-type', 'application/json') 1023 1130 } 1024 1131 } else { 1025 1132 this.body = safeStringify(val) 1026 self.setHeader('content-type', 'application/json') 1027 } 1133 if (!self.hasHeader('content-type')) 1134 self.setHeader('content-type', 'application/json') 1135 } 1136 1028 1137 return this 1029 1138 } … … 1161 1270 cookies = false 1162 1271 this._disableCookies = true 1163 } else if (jar && jar.get) {1164 // fetch cookie from the user defined cookie jar1165 cookies = jar.get({ url: this.uri.href })1166 1272 } else { 1167 // fetch cookie from the global cookie jar 1168 cookies = cookieJar.get({ url: this.uri.href }) 1169 } 1170 1273 var targetCookieJar = (jar && jar.getCookieString)?jar:globalCookieJar; 1274 var urihref = this.uri.href 1275 //fetch cookie in the Specified host 1276 if (targetCookieJar) { 1277 cookies = targetCookieJar.getCookieString(urihref); 1278 } 1279 } 1280 1281 //if need cookie and cookie is not empty 1171 1282 if (cookies && cookies.length) { 1172 var cookieString = cookies.map(function (c) {1173 return c.name + "=" + c.value1174 }).join("; ")1175 1176 1283 if (this.originalCookieHeader) { 1177 1284 // Don't overwrite existing Cookie header 1178 this.setHeader('cookie', this.originalCookieHeader + '; ' + cookie String)1285 this.setHeader('cookie', this.originalCookieHeader + '; ' + cookies) 1179 1286 } else { 1180 this.setHeader('cookie', cookie String)1287 this.setHeader('cookie', cookies) 1181 1288 } 1182 1289 }
Note: See TracChangeset
for help on using the changeset viewer.