diff --git a/index.d.ts b/index.d.ts index 7e22c45..2f8271b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,25 +1,3 @@ -declare const enum LevelEnum { - /** - All colors disabled. - */ - None = 0, - - /** - Basic 16 colors support. - */ - Basic = 1, - - /** - ANSI 256 colors support. - */ - Ansi256 = 2, - - /** - Truecolor 16 million colors support. - */ - TrueColor = 3 -} - /** Basic foreground colors. @@ -89,12 +67,26 @@ declare type Modifiers = | 'visible'; declare namespace chalk { - type Level = LevelEnum; + /** + Levels: + - `0` - All colors disabled. + - `1` - Basic 16 colors support. + - `2` - ANSI 256 colors support. + - `3` - Truecolor 16 million colors support. + */ + type Level = 0 | 1 | 2 | 3; interface Options { /** Specify the color support for Chalk. + By default, color support is automatically detected based on the environment. + + Levels: + - `0` - All colors disabled. + - `1` - Basic 16 colors support. + - `2` - ANSI 256 colors support. + - `3` - Truecolor 16 million colors support. */ level?: Level; } @@ -161,7 +153,14 @@ declare namespace chalk { /** The color support for Chalk. + By default, color support is automatically detected based on the environment. + + Levels: + - `0` - All colors disabled. + - `1` - Basic 16 colors support. + - `2` - ANSI 256 colors support. + - `3` - Truecolor 16 million colors support. */ level: Level; @@ -400,7 +399,7 @@ This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`. */ declare const chalk: chalk.Chalk & chalk.ChalkFunction & { supportsColor: chalk.ColorSupport | false; - Level: typeof LevelEnum; + Level: chalk.Level; Color: Color; ForegroundColor: ForegroundColor; BackgroundColor: BackgroundColor; diff --git a/index.test-d.ts b/index.test-d.ts index 177d6de..0b26797 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -4,12 +4,6 @@ import chalk = require('.'); // - Helpers - type colorReturn = chalk.Chalk & {supportsColor?: never}; -// - Level - -expectType(chalk.Level.None); -expectType(chalk.Level.Basic); -expectType(chalk.Level.Ansi256); -expectType(chalk.Level.TrueColor); - // - supportsColor - expectType(chalk.supportsColor); expectType((chalk.supportsColor as chalk.ColorSupport).hasBasic); diff --git a/source/index.js b/source/index.js index 28d529a..203b1b3 100644 --- a/source/index.js +++ b/source/index.js @@ -218,16 +218,4 @@ 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 4fe8fae..65d4720 100644 --- a/test/level.js +++ b/test/level.js @@ -43,15 +43,3 @@ 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'); -});