machinepack-arrays
Advanced tools
Comparing version 4.1.0 to 4.2.0
@@ -52,2 +52,5 @@ module.exports = { | ||
}, | ||
skip: { | ||
friendlyName: 'skip item' | ||
}, | ||
success: { | ||
@@ -106,7 +109,14 @@ friendlyName: 'next item', | ||
// Track the index of all iterations which trigger the `exclude` exit. | ||
var excludedIndices = []; | ||
// Start iterating... | ||
iteratorFn(inputs.array, function enumerator(item, next) { | ||
var indices = _.keys(inputs.array); | ||
iteratorFn(indices, function enumerator(currentIndex, next) { | ||
// Increment iterations counter and track current index | ||
var currentIndex = numIterationsStarted; | ||
// We iterate over indices instead of the items themselves to avoid | ||
// parallel execution throwing us off. | ||
var item = inputs.array[currentIndex]; | ||
// Increment iterations counter | ||
numIterationsStarted++; | ||
@@ -129,2 +139,9 @@ | ||
// Exclude (skip item) exit | ||
// (implies that we should exclude this item from the result set) | ||
exclude: function (){ | ||
excludedIndices.push(currentIndex); | ||
next(); | ||
}, | ||
// Default (success) exit | ||
@@ -140,2 +157,9 @@ // (implies that we should continue iterating) | ||
} | ||
// Remove items that were skipped above. | ||
if (excludedIndices.length > 0) { | ||
var retainedIndices = _.difference(indices, excludedIndices); | ||
transformedArray = _.at(transformedArray, retainedIndices); | ||
} | ||
return exits.success(transformedArray); | ||
@@ -142,0 +166,0 @@ }); |
{ | ||
"name": "machinepack-arrays", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "Work with arrays.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -85,4 +85,19 @@ { | ||
] | ||
}, | ||
{ | ||
"using": { | ||
"array": [ | ||
10, | ||
20, | ||
30 | ||
], | ||
"itemExample": 1, | ||
"iteratee": "if (inputs.index % 2 === 0) { /* exclude even-numbered indices */ return exits.exclude(); } return exits.success(inputs.item+inputs.index);" | ||
}, | ||
"outcome": "success", | ||
"returns": [ | ||
21 | ||
] | ||
} | ||
] | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
75873
2834