Chalarangelo / 30-seconds-of-code

Short code snippets for all your development needs

Home Page:https://30secondsofcode.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

js - unflattenObject: fails to correctly restore nested properties

tbasse opened this issue · comments

The unflattenObject function works fine with the provided example

unflattenObject({ 'a.b.c': 1, d: 1 }); // { a: { b: { c: 1 } }, d: 1 }

But it won't work as expected on { 'a.b': 1, 'a.c': 2, d: 3 }, returns an object with a.b. missing.
It also throws on nested values that are not numbers like { 'a.b': 'foo', d: 3 }, results in Unexpected token in JSON.

See https://runkit.com/tbasse/5f2a9929c9b5c9001a4d3a6e for some tests

I'll like to take a look at this issue.

@Sparkadelic177 Sure, go ahead! 👌

@pachbrasil you can go for it if you want.

@Sparkadelic177 can I please take this?

@Chalarangelo I have opened a pull request for this.
Thankyou !