Skip to content

feat(micro-utilities): add copy-descriptor to replacements - #1227

Merged
43081j merged 1 commit into
e18e:mainfrom
maksimgm:feat/copy-descriptor
Nov 15, 2026
Merged

43081j merged 1 commit into
e18e:mainfrom
maksimgm:feat/copy-descriptor

Conversation

@maksimgm

Copy link
Copy Markdown
Contributor

Closes #1210

Adds copy-descriptor (~9.7M weekly downloads) to the micro-utilities manifest, with a new snippet::copy-descriptor:

const copyDescriptor = (target, source, fromKey, toKey = fromKey) =>
  Object.defineProperty(target, toKey, Object.getOwnPropertyDescriptor(source, fromKey))

This is the one-liner from the issue, wrapped so the optional rename (to) works the same way as in the package.

I checked it against copy-descriptor@1.0.0, copying plain values, getters and non-writable properties, with and without a new key name. The resulting descriptors were identical in all cases.

Differences in edge cases:

  • A missing key throws a TypeError instead of the package's Error.
  • A property that is only inherited (not an own property) makes the snippet throw, while the package silently does nothing.
  • The package's 3-argument form copy(obj, from, to) (copying within one object) is just copyDescriptor(obj, obj, from, to).

@43081j
43081j merged commit a458979 into e18e:main Nov 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Replacement]: copy-descriptor

2 participants