@mintlab/kitchen-sink
Advanced tools
Comparing version 2.0.2 to 2.1.0
@@ -10,5 +10,5 @@ const expose = require('./expose'); | ||
*/ | ||
function passOrGet(value) { | ||
function passOrGet(value, argumentList = []) { | ||
if (typeof value === 'function') { | ||
return value(); | ||
return value(...argumentList); | ||
} | ||
@@ -15,0 +15,0 @@ |
@@ -8,3 +8,3 @@ // Modules exposed in the entry file are for DLL pre-builds. | ||
const { bind } = require('./instance'); | ||
const { traverseMap } = require('./iterable'); | ||
const { reduceMap } = require('./iterable'); | ||
const { | ||
@@ -35,4 +35,4 @@ cloneWithout, | ||
purge, | ||
traverseMap, | ||
reduceMap, | ||
unique, | ||
}); |
@@ -0,24 +1,35 @@ | ||
const { passOrGet } = require('./function'); | ||
const expose = require('./expose'); | ||
/** | ||
* Traverse the map, and return the output of the | ||
* first value function where the key function is truthy | ||
* Iterate a `Map` of key/value functions until the first *key* | ||
* that produces a truthy result when called and return the outcome | ||
* of calling the associated *value*. | ||
* | ||
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map | ||
* | ||
* @param {Map} map | ||
* @param {Array} [keyArgs=[]] | ||
* @param {Array} [functionArgs=[]] | ||
* @param {Object} options | ||
* @param {Map} options.map | ||
* @param {Array} [options.keyArguments=[]] | ||
* @param {Array} [options.valueArguments=[]] | ||
* @param {*} [options.fallback] | ||
* @return {*} | ||
*/ | ||
function traverseMap(map, keyArgs = [], functionArgs = []) { | ||
for (const [mapKey, mapFunction] of map) { | ||
if (mapKey(...keyArgs)) { | ||
return mapFunction(...functionArgs); | ||
function reduceMap({ | ||
map, | ||
keyArguments = [], | ||
valueArguments = [], | ||
fallback, | ||
}) { | ||
for (const [mapKey, mapValue] of map) { | ||
if (mapKey(...keyArguments)) { | ||
return mapValue(...valueArguments); | ||
} | ||
} | ||
return passOrGet(fallback, valueArguments); | ||
} | ||
module.exports = expose({ | ||
traverseMap, | ||
reduceMap, | ||
}); |
{ | ||
"name": "@mintlab/kitchen-sink", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"license": "EUPL-1.1", | ||
@@ -5,0 +5,0 @@ "description": "Mintlab utility functions.", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
24394
294
0