printf.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334
  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(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. 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, _toPropertyKey(descriptor.key), descriptor); } }
  5. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  6. function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
  7. function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
  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. _createClass(Printf, [{
  16. key: "transform",
  17. value: function transform(info) {
  18. info[MESSAGE] = this.template(info);
  19. return info;
  20. }
  21. }]);
  22. return Printf;
  23. }();
  24. /*
  25. * function printf (templateFn)
  26. * Returns a new instance of the printf Format that creates an
  27. * intermediate prototype to store the template string-based formatter
  28. * function.
  29. */
  30. module.exports = function (opts) {
  31. return new Printf(opts);
  32. };
  33. module.exports.Printf = module.exports.Format = Printf;