Big update!Introducing GitHub Bot Commands. Learn more
Log inBook a demo


Package Overview
File Explorer

Advanced tools


Property descriptor factory


Version published
Weekly downloads
decreased by-9.96%

Weekly downloads



1.0.1 (2019-06-14)

Changelog for previous versions

See CHANGES file




Property descriptor factory

Originally derived from es5-ext package.

Defining properties with descriptors is very verbose:

var Account = function () {}; Object.defineProperties(Account.prototype, { deposit: { value: function () { /* ... */ }, configurable: true, enumerable: false, writable: true }, withdraw: { value: function () { /* ... */ }, configurable: true, enumerable: false, writable: true }, balance: { get: function () { /* ... */ }, configurable: true, enumerable: false } });

D cuts that to:

var d = require("d"); var Account = function () {}; Object.defineProperties(Account.prototype, { deposit: d(function () { /* ... */ }), withdraw: d(function () { /* ... */ }), balance: () { /* ... */ }) });

By default, created descriptor follow characteristics of native ES5 properties, and defines values as:

{ configurable: true, enumerable: false, writable: true }

You can overwrite it by preceding value argument with instruction:

d("c", value); // { configurable: true, enumerable: false, writable: false } d("ce", value); // { configurable: true, enumerable: true, writable: false } d("e", value); // { configurable: false, enumerable: true, writable: false } // Same way for get/set:"e", value); // { configurable: false, enumerable: true }


$ npm install d

To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: Browserify, Webmake or Webpack

Other utilities

autoBind(obj, props) (d/auto-bind)

Define methods which will be automatically bound to its instances

var d = require('d'); var autoBind = require('d/auto-bind'); var Foo = function () { this._count = 0; }; Object.defineProperties(Foo.prototype, autoBind({ increment: d(function () { ++this._count; }); })); var foo = new Foo(); // Increment foo counter on each domEl click domEl.addEventListener('click', foo.increment, false);
lazy(obj, props) (d/lazy)

Define lazy properties, which will be resolved on first access

var d = require("d"); var lazy = require("d/lazy"); var Foo = function () {}; Object.defineProperties(Foo.prototype, lazy({ items: d(function () { return []; }) })); var foo = new Foo(); foo.items.push(1, 2); // foo.items array created and defined directly on foo

Tests Build Status

$ npm test

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

Get professional support for d with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.



What is d?

Property descriptor factory

Is d popular?

The npm package d receives a total of 8,930,632 weekly downloads. As such, d popularity was classified as popular.

Is d well maintained?

We found that d demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 1 open source maintainer collaborating on the project.

Last updated on 14 Jun 2019

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket


Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc