Skip to content

Possible to allow key's with '.'s in them? #4

Description

@sorahn

I'm looking for a way to preserve keys that have .s in to use the same syntax as lodash's set/get.

Ideally something like this:

// Input
{
  some: {
    'key.with.dots': value
  }
}

// Output
{
  some['key.with.dots']: value
}

The problem I've found with using the transformKey option is they still get the . joining them.

I have this:

const flatData = flatten(data, {
  transformKey: key => (key.includes('.') ? `['${key}']` : key),
});

But the output looks like this. (extra . after some)

{
  some.['key.with.dots']: value
}

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