Skip to content

[BUG] Incorrect source argument passed to the mapper function #44

@leonardoraele

Description

@leonardoraele

Right now, the source argument passed to the mapper function is not the actual original source argument the user passed to mapObject, but the "owner" object of the key/value pair for the current iteration.

Example:

const { default: mapObject } = await import('./index.js');
const subject = { nestedA: { one: 1, two: 2 }, nestedB: { three: 3, four: 4 } };
const mapper = (key, value, source) => source !== subject ? [key + '_different', value] : [key + '_same', value];
console.log(mapObject(subject, mapper, { deep: true }));
{
  nestedA_same: { one_different: 1, two_different: 2 },
  nestedB_same: { three_different: 3, four_different: 4 }
}

Notice source is only equal to subject for the top level keys.

Fixing this would be a breaking change, so should probably be released as v6.0.0?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions