From 4e65299e7bc54949d00ec0c963daf08635d83bc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kh=E1=BA=A3i?= Date: Fri, 27 Sep 2019 10:53:54 +0700 Subject: [PATCH] Fix const enum for TypeScript (#364) --- source/index.js | 12 ++++++++++++ test/level.js | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/source/index.js b/source/index.js index 686758b..6fee0f8 100644 --- a/source/index.js +++ b/source/index.js @@ -223,4 +223,16 @@ chalk.supportsColor = stdoutColor; chalk.stderr = Chalk({level: stderrColor ? stderrColor.level : 0}); // eslint-disable-line new-cap chalk.stderr.supportsColor = stderrColor; +// For TypeScript +chalk.Level = { + None: 0, + Basic: 1, + Ansi256: 2, + TrueColor: 3, + 0: 'None', + 1: 'Basic', + 2: 'Ansi256', + 3: 'TrueColor' +}; + module.exports = chalk; diff --git a/test/level.js b/test/level.js index 65d4720..4fe8fae 100644 --- a/test/level.js +++ b/test/level.js @@ -43,3 +43,15 @@ test('disable colors if they are not supported', async t => { const {stdout} = await execa.node(path.join(__dirname, '_fixture')); t.is(stdout, 'testout testerr'); }); + +test('chalk.Level enum object', t => { + const {Level} = chalk; + t.is(Level.None, 0); + t.is(Level.Basic, 1); + t.is(Level.Ansi256, 2); + t.is(Level.TrueColor, 3); + t.is(Level[Level.None], 'None'); + t.is(Level[Level.Basic], 'Basic'); + t.is(Level[Level.Ansi256], 'Ansi256'); + t.is(Level[Level.TrueColor], 'TrueColor'); +});