1.0.2 • Published 11 months ago

d v1.0.2

Weekly downloads
10,969,706
License
ISC
Repository
github
Last release
11 months ago

Build status Tests coverage npm version

d

Property descriptor factory

Originally derived from d 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: d.gs(function () { /* ... */ })
});

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:
d.gs("e", value); // { configurable: false, enumerable: true }

Installation

$ 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

$ npm test

Security contact information

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


es6-symboles6-iteratores6-weak-mapevent-emittermemoizeecli-colores6-setes6-map@remote.it/serverlesscomponennenttcli-color-cserverless-fork-upload-iocthpb-plugin-socialunblock-block-save-variables@infinitebrahmanuniverse/nolb-d@everything-registry/sub-chunk-1436tadtest-deadendweb-elements-iconswow.js-juzixlintshowgalleryserverless-heybitrestakebotreactive-valuereactive-mapreactive-setreactive-arraysearch-input-reactsearch-list-reactthomaschaaf-serverlessthreestagesvcloudcam-playkit-js-hlsvideo-multi-uploader3.0.0@brucearmstrong/sass-librarylayui-customdfeuk-frontenddfeuk-frontend-manualmiguelcostero-ng2-toastymemoizee-2loading-animatedlog-nodeloglog-aws-lambdahelp-widgetgit-repo-initgix-cli-colorjeuxuijs-utils-jll2i18n2log4log4-aws-lambdalog4-nodejsm2m-chartjs-plugin-crosshairkafirchain-tetriskoa-class-serverhuateng-ui-plushtml-dom-event-exthtml-site-treehcm-jsmusical-componentsm-class-serverlrbceshioslsoutils-renpost-controller-routerplaykit-js-hls-sondqpincushionpixiu-swap-corepixiuswap-libs-sdkn8n-nodes-caldavn8n-nodes-cobaltreact-cool-uineural_compressor_ext_lab_customizedneural_compressor_ext_lab_customized_2observable-valueobservable-setobservable-mapobservable-multi-setobservable-arrayquadratic-sdkrangoli-cssreact-misc-toolboxqudratic-uiregression-external-dtosingle-lettersimply-uiserverless-rabbitserverless-plugin-vpc-eni-cleanupslsplussite-treesite-tree-routersolregex2tinymce-plugin-toyuimoutils-test-22@artiso-solutions/vue-html-to-paper@amuslija/serverless@ashish-hurix/event-emitter
1.0.2

11 months ago

1.0.1

6 years ago

1.0.0

9 years ago

0.1.1

11 years ago

0.1.0

12 years ago