feat: support for 'chalk/stderr'

fix #301
This commit is contained in:
Pavel Lang 2018-12-27 18:21:46 +01:00
parent 587a5fbcbb
commit 85f99bb677
No known key found for this signature in database
GPG key ID: 623A223A57974B55
4 changed files with 43 additions and 1 deletions

View file

@ -15,7 +15,9 @@
"index.js",
"templates.js",
"index.d.ts",
"index.js.flow"
"index.js.flow",
"stderr.js",
"stderr.d.ts"
],
"keywords": [
"color",

6
stderr.d.ts vendored Normal file
View file

@ -0,0 +1,6 @@
import Chalk from '.';
declare const chalk: Chalk;
export * from '.';
export default chalk;

7
stderr.js Normal file
View file

@ -0,0 +1,7 @@
'use strict';
const {stderr: stderrColor} = require('supports-color');
const {constructor: Chalk} = require('.');
module.exports = new Chalk({level: stderrColor ? stderrColor.level : 0});
module.exports.supportsColor = stderrColor;
module.exports.default = module.exports; // For TypeScript

27
stderr.test-d.ts Normal file
View file

@ -0,0 +1,27 @@
import {expectType} from 'tsd-check';
import cherr, {Level, Chalk, ColorSupport} from './stderr';
// - Helpers -
type colorReturn = Chalk & {supportsColor: ColorSupport};
// - supportsColor -
expectType<boolean>(cherr.supportsColor.hasBasic);
expectType<boolean>(cherr.supportsColor.has256);
expectType<boolean>(cherr.supportsColor.has16m);
// - Chalk -
// -- Constructor --
expectType<Chalk>(new cherr.constructor({level: 1}));
// -- Properties --
expectType<boolean>(cherr.enabled);
expectType<Level>(cherr.level);
// -- Template literal --
expectType<string>(cherr``);
// -- Color methods --
expectType<colorReturn>(cherr.hex('#DEADED'));
// -- Complex --
expectType<string>(cherr.underline.red.bgGreen('foo'));