object.omit icon indicating copy to clipboard operation
object.omit copied to clipboard

Returning empty object where it should not

Open imsamdez opened this issue 7 years ago • 5 comments

Hi, I'm having some troubles with this package.

I have a RowDataPacket Object that I passed into the omit module.

RowDataPacket {
  id: 38,
  uuid: '9fb0f6b1-9b9b-56eb-a06e-963011a7c22f',
  name: 'Test',
  club_id: null,
  calendar_id: 42
 }

I'm doing the following thing (where team is the RowDataPacket Object) console.log(ObjectOmit(team, ['id']));

The result is {}

I got an empty object where it should be the original RowDataPacket Object without his id attribute.

Any chance to have some help here ? Thanks!

imsamdez avatar Mar 22 '18 00:03 imsamdez

I think it come from the first If statement in the module: if (!isObject(obj)) return {};

The RowDataPacket Object seems to not be an object but I don't see how I could make this If statement being true.

imsamdez avatar Mar 22 '18 00:03 imsamdez

I have found a fix but don't think if it's smart, can you provide a feedback about this ? I added those 3 lines

module.exports = function omit(obj, props, fn) {
  var copy = {};                           // Added line #1
  ObjectCopy(copy, obj)                    // Added line #2
  obj = copy;                              // Added line #3
  if (!isObject(obj)) return {};

And now the isObject(obj) return true !

P.S: Yes I have used your object-copy module ;-)

imsamdez avatar Mar 22 '18 00:03 imsamdez

Sorry for the late reply, and thanks for the detail. I'll try to take a look today.

Yes I have used your object-copy module ;-)

lol very cool, thank you!

jonschlinkert avatar Mar 26 '18 15:03 jonschlinkert

@sdubrez can you add a complete code snippet that demonstrates the bug so I can easily reproduce? thanks!

jonschlinkert avatar Mar 26 '18 16:03 jonschlinkert

I believe we should not use is-extendable library in order to check whether a value is an object as it's simply confusing and not valid. is-extendable checks whether object is plain, function or array so the whole library won't work on any objects coming from custom class.

wookieb avatar Sep 16 '18 07:09 wookieb