npm

npm’s 2019 JavaScript ecosystem survey analysis is now available!Get your copy here »

decoratable

0.0.2 • Public • Published

decoratable

define decoratable function. like connect middleware.

example

var decoratable = require('decoratable');
 
/**
 * define class.
 */
function SomeClass(values) {
  this._values = values;
}
 
/**
 * get value.
 */
SomeClass.prototype.get = decoratable(function(key) {
  return this._values[key];
});
 
/**
 * decorate default value.
 */
SomeClass.prototype.get.use(function(key, next) {
  var v = next(key);
  if ((key === 'created' || key === 'updated') && v === undefined) {
    return Date.now();
  }
  return v;
});
 
/**
 * instantiate.
 */
var ins = new SomeClass({ created: 1234567890 });
ins.get('created'); //=> 1234567890
ins.get('updated'); //=> Date.now() results.

install

npm i decoratable

Downloadsweekly downloads

1

version

0.0.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability