printf.js 515 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. const { MESSAGE } = require('triple-beam');
  3. class Printf {
  4. constructor(templateFn) {
  5. this.template = templateFn;
  6. }
  7. transform(info) {
  8. info[MESSAGE] = this.template(info);
  9. return info;
  10. }
  11. }
  12. /*
  13. * function printf (templateFn)
  14. * Returns a new instance of the printf Format that creates an
  15. * intermediate prototype to store the template string-based formatter
  16. * function.
  17. */
  18. module.exports = opts => new Printf(opts);
  19. module.exports.Printf
  20. = module.exports.Format
  21. = Printf;