printf.js 1.9 KB

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
  3. function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
  4. function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
  5. function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
  6. function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
  7. function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
  8. var _require = require('triple-beam'),
  9. MESSAGE = _require.MESSAGE;
  10. var Printf = /*#__PURE__*/function () {
  11. function Printf(templateFn) {
  12. _classCallCheck(this, Printf);
  13. this.template = templateFn;
  14. }
  15. return _createClass(Printf, [{
  16. key: "transform",
  17. value: function transform(info) {
  18. info[MESSAGE] = this.template(info);
  19. return info;
  20. }
  21. }]);
  22. }();
  23. /*
  24. * function printf (templateFn)
  25. * Returns a new instance of the printf Format that creates an
  26. * intermediate prototype to store the template string-based formatter
  27. * function.
  28. */
  29. module.exports = function (opts) {
  30. return new Printf(opts);
  31. };
  32. module.exports.Printf = module.exports.Format = Printf;