From 01063d5bc4440d8729085e96537d793be69cfdc6 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Mon, 11 Nov 2019 20:53:15 -0500 Subject: [PATCH] emojify all the console logs ... that is, if `{emojy: true}` is enabled. --- examples/list.js | 2 +- src/reporters/base-reporter.js | 5 +++++ src/reporters/console/console-reporter.js | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/list.js b/examples/list.js index 73ee074..1cda617 100644 --- a/examples/list.js +++ b/examples/list.js @@ -8,7 +8,7 @@ report.list('dunno', someList); const hints = { bananas: 'for baking', - tulips: 'because it makes you happy', + tulips: 'because it makes you :joy:', eggs: 'not the cheap ones though', bamischijf: 'if they have it', }; diff --git a/src/reporters/base-reporter.js b/src/reporters/base-reporter.js index cca782f..4b19755 100644 --- a/src/reporters/base-reporter.js +++ b/src/reporters/base-reporter.js @@ -14,6 +14,7 @@ import type { } from './types.js'; import type {LanguageKeys} from './lang/en.js'; import type {Formatter} from './format.js'; +import { emojify as nodeEmojify } from 'node-emoji'; // import type {AuditMetadata, AuditActionRecommendation, AuditAdvisory, AuditResolution} from '../cli/commands/audit'; import {defaultFormatter} from './format.js'; @@ -100,6 +101,10 @@ export default class BaseReporter { peakMemory: number; startTime: number; + emojify( s: string ): string { + return this.emoji ? nodeEmojify(s) : s; + } + lang(key: LanguageKeys, ...args: Array): string { const msg = languages[this.language][key] || languages.en[key]; if (!msg) { diff --git a/src/reporters/console/console-reporter.js b/src/reporters/console/console-reporter.js index c5bb5a0..b031cfb 100644 --- a/src/reporters/console/console-reporter.js +++ b/src/reporters/console/console-reporter.js @@ -174,7 +174,7 @@ export default class ConsoleReporter extends BaseReporter { return; } clearLine(this.stdout); - this.stdout.write(`${msg}\n`); + this.stdout.write(this.emojify(`${msg}\n`)); } success(msg: string) {