Open abdavid opened 4 years ago
For omit
need a function because the name of properties comes from users.
For
omit
need a function because the name of properties comes from users.
So we are actually talking about https://lodash.com/docs/4.17.15#omitBy ?
No, it's the _.omit
but the list of properties comes from another variable, so not static.
No, it's the
_.omit
but the list of properties comes from another variable, so not static.
This one here you are thinking about? https://github.com/moleculerjs/moleculer/blob/07dbf1c0ead1038d157ec6616ac76509b6974549/src/service.js#L197
Yeah, e.g.
We could do an inverse of suggestion from #748 then maybe?
const omit = (o, xs) => {
if(!Array.isArray(xs))
xs = [xs];
const objectPropertyNames = Object.getOwnPropertyNames(o)
.filter(n => !xs.includes(n));
return objectPropertyNames.reduce((acc,x) => {
if(o.hasOwnProperty(x))
acc[x] = o[x]
return acc;
}, {})
};
By the way, omit
& pick
should work with nested paths as well :) _.pick(obj, ["a.b", "a.c"]);
Noted :) I belive we then might be able to reuse #753 implementation there
See #433 for context.
Describe the solution you'd like Remove usage of
_.omit
throughout Moleculer.Describe alternatives you've considered Source: https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_omit
Additional context https://github.com/moleculerjs/moleculer/search?q=_.omit&unscoped_q=_.omit