mesqueeb / flatten-anything

Flatten objects and replace nested props with 'prop.subprop'. A simple and small integration.
https://npmjs.com/flatten-anything
MIT License
30 stars 1 forks source link

Can't use `constructor` key in the object #15

Closed Rigidoont closed 1 year ago

Rigidoont commented 2 years ago

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

mesqueeb commented 2 years ago

@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!

Rigidoont commented 2 years ago

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.

Rigidoont commented 2 years ago

@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.

Rigidoont commented 2 years ago

PR - https://github.com/mesqueeb/is-what/pull/24

mesqueeb commented 1 year ago

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