From 066c38a685b98ca64e7da5c10bc29120375ee16e Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 22 Sep 2019 16:18:07 +0700 Subject: [PATCH 1/6] TypeScript: Change `const enum` to `enum Because Babel doesn't support it... Fixes #363 --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 52dd5ae..4fb132f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,4 @@ -declare const enum LevelEnum { +declare enum LevelEnum { /** All colors disabled. */ From 095d11ac15a32d2fd6dea07d25be554958b60e24 Mon Sep 17 00:00:00 2001 From: khai96_ Date: Sun, 22 Sep 2019 18:56:29 +0700 Subject: [PATCH 2/6] Add enum Level to JavaScript Fix https://github.com/chalk/chalk/issues/363 --- source/index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/source/index.js b/source/index.js index 686758b..c9c8f75 100644 --- a/source/index.js +++ b/source/index.js @@ -223,4 +223,15 @@ chalk.supportsColor = stdoutColor; chalk.stderr = Chalk({level: stderrColor ? stderrColor.level : 0}); // eslint-disable-line new-cap chalk.stderr.supportsColor = stderrColor; +chalk.Level = { + None: 0, + Basic: 1, + Ansi256: 2, + TrueColor: 3, + 0: 'None', + 1: 'Basic', + 2: 'Ansi256', + 3: 'TrueColor' +} + module.exports = chalk; From 3405e41d4b8ae50b3c018df9af006ba61bdf80af Mon Sep 17 00:00:00 2001 From: khai96_ Date: Sun, 22 Sep 2019 18:58:46 +0700 Subject: [PATCH 3/6] Revert 'enum LevelEnum' to 'const enum LevelEnum' --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 4fb132f..52dd5ae 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,4 @@ -declare enum LevelEnum { +declare const enum LevelEnum { /** All colors disabled. */ From 4ee1692c3e051098801c820bf413bcde89ce396e Mon Sep 17 00:00:00 2001 From: khai96_ Date: Sun, 22 Sep 2019 19:02:05 +0700 Subject: [PATCH 4/6] Fix linter --- source/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/index.js b/source/index.js index c9c8f75..e057dab 100644 --- a/source/index.js +++ b/source/index.js @@ -232,6 +232,6 @@ chalk.Level = { 1: 'Basic', 2: 'Ansi256', 3: 'TrueColor' -} +}; module.exports = chalk; From cd58420ca542f1f27134f73082a65296272640b8 Mon Sep 17 00:00:00 2001 From: khai96_ Date: Sun, 22 Sep 2019 19:06:13 +0700 Subject: [PATCH 5/6] Add test for chalk.Level --- test/level.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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'); +}); From 4f31d2d685808f487090d827122d91471f0f05b2 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 27 Sep 2019 10:53:25 +0700 Subject: [PATCH 6/6] Update index.js --- source/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/source/index.js b/source/index.js index e057dab..6fee0f8 100644 --- a/source/index.js +++ b/source/index.js @@ -223,6 +223,7 @@ 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,