Skip to content

Keeping non-enumerable properties #28

@ehmicky

Description

@ehmicky

At the moment, non-enumerable properties are removed from the return value.

On one hand:

  • Most functional utilities iterate on objects using standard for ... in, Object.keys(...), etc. which ignore non-enumerable properties. Object spreading { ...object } itself removes non-enumerable properties.
  • The concept of a property being non-enumerable implies that it should not be iterated when being copied over.
  • Non-enumerable properties are much less common on plain objects than on class instances, and this library is meant for plain objects.

On the other hand, some users might not expect non-enumerable properties removal as a side effect of this library. For example:

  • excludeKeys(object, ['one']): this would remove object.two if it is non-enumerable, even though the user operation only intended to exclude object.one.
  • includeKeys(object, ['one']): this would not include object.own if it is non-enumerable, even though the user explicitly requested to include it.
  • For predicate functions, the user intent is less clear.

@sindresorhus What are your thoughts on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions