Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

object-descriptors

VitorLuizC140MIT0.2.1TypeScript support: included

A pretty well typed Object.getOwnPropertyDescriptors polyfill.

Object.getOwnPropertyDescriptors, descriptor, property descriptor, property-descriptor, property-descriptors, properties, property, own-keys, keys, object, ES8, ES2017, shim, polyfill, getOwnPropertyDescriptor, es-shim API

readme

object-descriptors

Build Status

A pretty well typed Object.getOwnPropertyDescriptors polyfill.

Install

This module is published under NPM registry, so you can install from any package manager.

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.

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.