volume.js 705 B

12345678910111213141516171819202122232425
  1. const { format } = require('../');
  2. const volume = format((info, opts) => {
  3. if (opts.yell) {
  4. info.message = info.message.toUpperCase();
  5. } else if (opts.whisper) {
  6. info.message = info.message.toLowerCase();
  7. }
  8. return info;
  9. });
  10. // `volume` is now a function that returns instances of the format.
  11. const scream = volume({ yell: true });
  12. console.dir(scream.transform({
  13. level: 'info',
  14. message: `sorry for making you YELL in your head!`
  15. }, scream.options));
  16. // `volume` can be used multiple times to create different formats.
  17. const whisper = volume({ whisper: true });
  18. console.dir(whisper.transform({
  19. level: 'info',
  20. message: `WHY ARE THEY MAKING US YELL SO MUCH!`
  21. }, whisper.options));