stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

RFC: add deep-omit

Open kgryte opened this issue 9 years ago • 3 comments

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.

kgryte avatar Dec 30 '16 04:12 kgryte

How should I approach this I think recursively would be a better option. WDYT?

saisrikardumpeti avatar Apr 06 '24 08:04 saisrikardumpeti

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

  1. For nested key (e.g., a.b.c)...
  2. Split the nested key path: [ 'a', 'b', 'c' ].
  3. Call @stdlib/utils/keys.
  4. Copy over everything which is not in the list of top-level key paths (e.g., 'a').
  5. If a provided key path has only one level, we're done with that level.
  6. 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.

kgryte avatar Apr 06 '24 09:04 kgryte

I will think about this like how we want to approach this.

saisrikardumpeti avatar Apr 06 '24 14:04 saisrikardumpeti