mesqueeb / flatten-anything

Flatten objects and replace nested props with 'prop.subprop'. A simple and small integration.

Home Page:https://npmjs.com/flatten-anything

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't use `constructor` key in the object

Rigidoont opened this issue · comments

commented

Presence of the constructor key in the object seems to break flattening. No errors are produced, the object simply does not get flattened.

@Gidoont it might be a reserved keyword for JS to know how an object was made, as a plain object or as a class instance.

I'd advice you to not use the key called constructor but if you must then..... I'm not sure how to fix it yet :P PRs welcome though!

commented

Unfortunately, it's not up to me whether to use such key or not. I'm receiving a JSON and have to do some work on it.

commented

@mesqueeb I think here's the issue - https://github.com/mesqueeb/is-what/blob/production/src/index.ts#L46

isPlainObject method is used in https://github.com/mesqueeb/flatten-anything/blob/production/src/index.ts#L11

It does not recognize the object as a plain one if the constructor property is overridden.

@Gidoont thank you very much! it's released in latest version v3.0.3