printf.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict';
  2. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  3. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. var _require = require('triple-beam'),
  5. MESSAGE = _require.MESSAGE;
  6. var Printf = function () {
  7. function Printf(templateFn) {
  8. _classCallCheck(this, Printf);
  9. this.template = templateFn;
  10. }
  11. _createClass(Printf, [{
  12. key: 'transform',
  13. value: function transform(info) {
  14. info[MESSAGE] = this.template(info);
  15. return info;
  16. }
  17. }]);
  18. return Printf;
  19. }();
  20. /*
  21. * function printf (templateFn)
  22. * Returns a new instance of the printf Format that creates an
  23. * intermediate prototype to store the template string-based formatter
  24. * function.
  25. */
  26. module.exports = function (opts) {
  27. return new Printf(opts);
  28. };
  29. module.exports.Printf = module.exports.Format = Printf;