Package: node-gulp / 4.0.2-8

update-now-and-later-to-2.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
Description: Update now and later to 2
--- a/now-and-later/README.md
+++ b/now-and-later/README.md
@@ -15,8 +15,9 @@
 ```js
 var nal = require('now-and-later');
 
-function iterator(value, cb){
+function iterator(value, key, cb){
   // called with each value in sequence
+  // also passes the key
   cb(null, value * 2)
 }
 
@@ -86,11 +87,11 @@
 
 If `values` is an array, the results of each iteration will be mapped to an array. If `values` is an object, the results of each iteration will be mapped to an object with corresponding keys.
 
-#### `iterator(value, done)`
+#### `iterator(value, key, done)`
 
 An async function called per iteration. All iterations are run in parallel.
 
-The `iterator` function is called once with each `value` and a function (`done(error, result)`) to call when the async work is complete.
+The `iterator` function is called once with each `value`, `key` and a function (`done(error, result)`) to call when the async work is complete.
 
 If `done` is passed an error as the first argument, the iteration will fail and the sequence will be ended; however, any iterations in progress will still complete. If `done` is passed a `result` value as the second argument, it will be added to the final results array or object.
 
@@ -141,11 +142,11 @@
 
 If `values` is an array, the results of each iteration will be mapped to an array. If `values` is an object, the results of each iteration will be mapped to an object with corresponding keys.
 
-#### `iterator(value, done)`
+#### `iterator(value, key, done)`
 
 An async function called per iteration. All iterations are run in serial.
 
-The `iterator` function is called once with each `value` and a function (`done(error, result)`) to call when the async work is complete.
+The `iterator` function is called once with each `value`, `key` and a function (`done(error, result)`) to call when the async work is complete.
 
 If `done` is passed an error as the first argument, the iteration will fail and the sequence will be ended without executing any more iterations. If `done` is passed a `result` value as the second argument, it will be added to the final results array or object.
 
--- a/now-and-later/lib/map.js
+++ b/now-and-later/lib/map.js
@@ -28,6 +28,10 @@
 
   var exts = helpers.defaultExtensions(extensions);
 
+  if (length === 0) {
+    return done(null, results);
+  }
+
   for (idx = 0; idx < length; idx++) {
     var key = keys[idx];
     next(key);
@@ -39,7 +43,7 @@
     var storage = exts.create(value, key) || {};
 
     exts.before(storage);
-    iterator(value, once(handler));
+    iterator(value, key, once(handler));
 
     function handler(err, result) {
       if (err) {
--- a/now-and-later/lib/mapSeries.js
+++ b/now-and-later/lib/mapSeries.js
@@ -27,6 +27,10 @@
 
   var exts = helpers.defaultExtensions(extensions);
 
+  if (length === 0) {
+    return done(null, results);
+  }
+
   var key = keys[idx];
   next(key);
 
@@ -36,7 +40,7 @@
     var storage = exts.create(value, key) || {};
 
     exts.before(storage);
-    iterator(value, once(handler));
+    iterator(value, key, once(handler));
 
     function handler(err, result) {
       if (err) {
--- a/now-and-later/package.json
+++ b/now-and-later/package.json
@@ -1,6 +1,6 @@
 {
   "name": "now-and-later",
-  "version": "1.0.0",
+  "version": "2.0.1",
   "description": "Map over an array or object of values in parallel or series, passing each through the async iterator, with optional lifecycle hooks.",
   "author": "Gulp Team <team@gulpjs.com> (http://gulpjs.com/)",
   "contributors": [