muze-nl / jaqt

GraphQL-style Array.select() and Array.where() for javascript
MIT License
231 stars 9 forks source link

Possibility to support treating custom objects like plain objects in where({}) #14

Closed saviola777 closed 1 month ago

saviola777 commented 1 month ago

Hello,

great little library. Currently it seems that properties of custom (i.e. not "plain") objects cannot be filtered using where({ someProp: "someValue" }) (I guess because of jaqt.mjs#L135). I'm assuming this is because we would lose the ability to match custom objects as a whole?

To make the example / use case clearer, I have an array of objects of a custom class. I can select() properties of these objects without problems, but filtering them with where({ someProp: "someValue" }) does not seem to work (I suppose it would work with a matcher function).

If this is intentional and supporting this use case is not planned (or too complicated) that's fine, I just thought maybe there is a simple way to support this (or add an option to support it).

I'm willing to try my hand at a PR if you think it would be useful and feasible to support this use case.

poef commented 1 month ago

Hmm... no this is an unintended consequence of isPlainOject(). I made it to filter our Number, String and Boolean objects. But I should probably then strictly check for those instead. I would like to support custom classes, it just never came up in my use-cases so far. So, the approach is probably to change isPlainObject() into isNotNumberStringOrBoolean() ... needs a better name :) I'd love to see your take on this.