dot-helpers
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -9,3 +9,3 @@ const check = require('check-types'); | ||
Object.assign(acc, { | ||
[key]: runModifiers(modifiers[key], value), | ||
[key]: runModifiers(modifiers[key], value, values), | ||
}), | ||
@@ -12,0 +12,0 @@ {}, |
@@ -11,3 +11,9 @@ const modify = require('./modify'); | ||
{ | ||
foo: [(v) => v + 4], | ||
foo: [ | ||
(v, args) => { | ||
expect(v).toBe(1); | ||
expect(args).toHaveProperty('bar'); | ||
return v + 4; | ||
}, | ||
], | ||
bar: [ | ||
@@ -14,0 +20,0 @@ (v) => v.trim(), |
@@ -12,3 +12,3 @@ const set = require('lodash.set'); | ||
if (Array.isArray(value)) { | ||
newValue = runModifiers(value, a[key]); | ||
newValue = runModifiers(value, a[key], a); | ||
} else { | ||
@@ -15,0 +15,0 @@ newValue = extract(a, value); |
@@ -9,3 +9,8 @@ const translateAndModify = require('./translateAndModify'); | ||
quuz: 'qux.quux', | ||
bongo: [() => 'OVERRIDE'], | ||
bongo: [ | ||
(value, state) => { | ||
expect(state).toHaveProperty('waldo'); | ||
return 'OVERRIDE'; | ||
}, | ||
], | ||
}); | ||
@@ -12,0 +17,0 @@ |
@@ -21,7 +21,8 @@ const check = require('check-types'); | ||
const runModifiers = (modifiers, originalValue) => { | ||
const runModifiers = (modifiers, originalValue, context) => { | ||
let newValue = originalValue; | ||
if (check.nonEmptyArray(modifiers)) | ||
modifiers.forEach((fn) => { | ||
if (typeof fn === 'function') newValue = fn(originalValue); | ||
if (typeof fn === 'function') | ||
newValue = fn(originalValue, context); | ||
}); | ||
@@ -28,0 +29,0 @@ |
{ | ||
"name": "dot-helpers", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "Object mapping helpers", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
11203
305