Possible to allow key's with '.'s in them?
- Dominant language
- JavaScript
- Stars
- 1.8k
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
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:
```js
// 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:
```js
const flatData = flatten(data, {
transformKey: key => (key.includes('.') ? `['${key}']` : key),
});
```
But the output looks like this. (extra `.` after `some`)
```js
{
some.['key.with.dots']: value
}
```
I've worked around the issue for now by looping through the flattend data and doing a string replace on `.[` with `[`.
```js
const fixedData = Object.entries(flatData).reduce((acc, [key, value]) => {
const newKey = key.includes('.[') ? key.replace('.[', '[') : key;
acc[newKey] = value;
return acc;
}, {});
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.