Skip to content

Commit 04b45dc

Browse files
committed
Bug fix
1 parent 62c7507 commit 04b45dc

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ const getMappingFilter = (type, types) => {
6666
return id
6767
}
6868

69-
const keep = current => next => (next === undefined ? current : next)
70-
7169
const getKey = reduce((accum, k) => (accum ? accum[k] : undefined))
7270

7371
const get = (key, delimiter = DEFAULTS.objDelimiter) => obj =>
@@ -101,8 +99,10 @@ class Mapper {
10199
)
102100

103101
const fn = compose(
104-
keep(accum),
105-
assign(targetField, this.config.objDelimiter).bind(this, accum),
102+
v =>
103+
v === undefined
104+
? accum
105+
: assign(targetField, this.config.objDelimiter)(accum, v),
106106
/* End user-land transforms */
107107
...this.config.postFilters,
108108
getMappingFilter(mapping.type, this.config.types),

test/index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ it('should not override fields that already exist', () => {
7575
expect(mapped.user.name).toBe('Nick')
7676
})
7777

78+
it('should not set key if undefined is returned', () => {
79+
const o = {}
80+
expect(mapper.map([{ field: 'key', type: () => undefined }], o)).toEqual(o)
81+
})
82+
7883
it('should work with basic string mappings', () => {
7984
const curr = {
8085
map: true,

0 commit comments

Comments
 (0)