articulate/funky

renameAll deleting keys

jesspoemape opened this issue · 4 comments

Take the following:

const originalObject = {
  title: 'My Title',
  flavor: 'bbq',
  latestTitle: 'hahahahahaha (business)',
}

renameAll({
  latestTitle: 'title',
  title: 'updatedTitle',
})(originalObject)

Expected Result:

{
  flavor: "bbq", 
  title: "hahahahahaha (business)",
  updatedTitle: "My Title",
}

Actual Result:

{
  flavor: "bbq",
  updatedTitle: "hahahahahaha (business)",
}

I believe this is happening because of this line that deletes the item from the original object.

Confirmed this is an issue

Argh. Just hit this issue hard. 😿

Didn't this get patched in #39 ?

We seem to have missed a use case. Here's what I'm seeing:

const originalObject = {
  authorId: "auth0|598dda141589ce5dcace749a"
  collaborators: [{…}]
  id: "ckpx3b37n00023g6d6j95l0lj"
  parentId: null
  title: "Priv3"
  type: "private"
}

const renames = {
  authorId: "author_id"
  collaborators: "collaborators"
  id: "id"
  parentId: "parent_id"
  title: "title"
  type: "type"
}

const result = renameAll(renames, originalObject)

Expected Result:

{
  author_id: "auth0|598dda141589ce5dcace749a"
  collaborators: [{…}]
  id: "ckpx3b37n00023g6d6j95l0lj"
  parent_id: null
  title: "Priv3"
  type: "private"
}

Actual Result:

{
  author_id: "auth0|598dda141589ce5dcace749a"
  parent_id: null
}

It's happening because of the isObject check here: https://github.com/articulate/funky/blob/master/src/renameAll.js#L8. Maybe it doesn't play nicely with nulls.

I can try to get up a fix for this, since I need this to work. I'm trying to convert an entire object from camel case prop names to snake case.