Closed andreas4all closed 6 years ago
Thank you for the pull request! This is a good idea. I am wondering if we could make this a little easier using Lodash _.omitBy.
I tried to refactored with omitBy
, but I have problem with nested object. Can you help me with that?
I was thinking something like:
module.exports = function (...fields) {
const regExps = fields.filter(isRegExp);
const fieldNames = fields.filter(field => !isRegExp(field));
const omitRegex = (value, key) => regExps.some(r => r.test(key));
return function protect (context) {
// ...
const omitted = omit(data, fieldNames);
// For performance reasons only omit when there are regular expressions
return regExps.length ? omitBy(omitted, omitRegex) : omitted;
}
}
Thanks again for the PR @andreas4all. I am going to close this one for now since this repository will be moved into a monorepo at https://github.com/feathersjs/feathers and I haven't heard back about the changes I proposed.
If you are still interested in getting this in, please reopen the pull request there.
Fields name can contain a regular expression. No open issue for this. No depends PR.