https://github.com/vitorluizc/object-descriptors
A pretty well typed function to get object property descriptors. `Object.getOwnPropertyDescriptors` polyfill.
https://github.com/vitorluizc/object-descriptors
ava bili descriptor es2017 es7 javascript object-property polyfill property property-descriptor property-descriptors shim typescript
Last synced: 3 months ago
JSON representation
A pretty well typed function to get object property descriptors. `Object.getOwnPropertyDescriptors` polyfill.
- Host: GitHub
- URL: https://github.com/vitorluizc/object-descriptors
- Owner: VitorLuizC
- License: mit
- Created: 2018-08-08T14:51:25.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T06:55:25.000Z (over 2 years ago)
- Last Synced: 2025-04-12T17:05:31.411Z (3 months ago)
- Topics: ava, bili, descriptor, es2017, es7, javascript, object-property, polyfill, property, property-descriptor, property-descriptors, shim, typescript
- Language: TypeScript
- Homepage:
- Size: 641 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# object-descriptors
[](https://travis-ci.org/VitorLuizC/object-descriptors)
A pretty well typed `Object.getOwnPropertyDescriptors` polyfill.
## Install
This module is published under NPM registry, so you can install from any package manager.
```sh
npm install object-descriptors --save# Use the command below if you're using Yarn.
yarn add object-descriptors
```## Usage
Import `getDescriptors` function and get property descriptors from any object.
> I'm exporting `PropertyDescriptors` type too, so you can use on your TypeScript/JSDoc types.
```ts
import getDescriptors, { PropertyDescriptors } from 'object-descriptors';const value = {
name: 'Ryan',
sayName() {
console.log(this.name);
},
};let descriptors: PropertyDescriptors<{ name: string; sayName: () => void }>;
descriptors = getDescriptors(value);
console.log(descriptors);
// => {
// name: {
// value: 'Ryan',
// writable: true,
// enumerable: true,
// configurable: true
// },
// sayName: {
// value: ƒ sayName(),
// writable: true,
// enumerable: true,
// configurable: true
// }
// }
```## License
Released under [MIT License](./LICENSE).