RFC: add deep-omit
Checklist
Please ensure the following tasks are completed before filing an issue.
- [x] Read and understood the Code of Conduct.
- [x] Searched for existing issues and pull requests.
- [x] If this is a general question, searched the FAQ for an existing answer.
- [x] If this is a feature request, the issue name begins with
RFC:.
Description
Description of the issue (or feature request).
This proposal recommends adding the utility @stdlib/utils/deep-omit. The utility would extend the behavior of @stdlib/utils/omit to deeply nested object properties, as well as provide support for deep copying. The current @stdlib/utils/omit only supports shallow copy of first-level properties.
Related Issues
Does this issue (or feature request) have any related issues?
No.
Questions
Any questions for reviewers?
No.
Other
Any other information relevant to this issue (or feature request)? This may include screenshots, references, stack traces, sample output, and/or implementation notes.
No.
How should I approach this I think recursively would be a better option. WDYT?
As touched on in the OP it would be similar to @stdlib/utils/omit, so a list of nested key paths and maybe something like @stdlib/utils/deep-pluck, which supports an options object.
I suppose one could either use or borrow from @stdlib/utils/flatten-object.
Hmm...I'm actually not the best approach here. But in thinking about this, yes, will probably need recursion. Maybe something along the lines of
- For nested key (e.g.,
a.b.c)... - Split the nested key path:
[ 'a', 'b', 'c' ]. - Call
@stdlib/utils/keys. - Copy over everything which is not in the list of top-level key paths (e.g.,
'a'). - If a provided key path has only one level, we're done with that level.
- If a provided key path has more than one level, proceed into the tree and repeat 2-4.
There may be gaps in the above. Not sure.
I will think about this like how we want to approach this.