diff --git a/.travis.yml b/.travis.yml index f3a8e90..ea5900d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ -sudo: false language: node_js node_js: + - '8' - '6' - '4' after_success: npm run coveralls diff --git a/benchmark.js b/benchmark.js index 5c26a87..af90c06 100644 --- a/benchmark.js +++ b/benchmark.js @@ -1,24 +1,24 @@ /* globals set bench */ 'use strict'; -var chalk = require('./'); +const chalk = require('.'); -suite('chalk', function () { +suite('chalk', () => { set('iterations', 100000); - bench('single style', function () { + bench('single style', () => { chalk.red('the fox jumps over the lazy dog'); }); - bench('several styles', function () { + bench('several styles', () => { chalk.blue.bgRed.bold('the fox jumps over the lazy dog'); }); - var cached = chalk.blue.bgRed.bold; - bench('cached styles', function () { + const cached = chalk.blue.bgRed.bold; + bench('cached styles', () => { cached('the fox jumps over the lazy dog'); }); - bench('nested styles', function () { + bench('nested styles', () => { chalk.red('the fox jumps', chalk.underline.bgBlue('over the lazy dog') + '!'); }); }); diff --git a/index.js b/index.js index 351253f..9abe28b 100644 --- a/index.js +++ b/index.js @@ -1,118 +1,124 @@ 'use strict'; -var escapeStringRegexp = require('escape-string-regexp'); -var ansiStyles = require('ansi-styles'); -var supportsColor = require('supports-color'); +const escapeStringRegexp = require('escape-string-regexp'); +const ansiStyles = require('ansi-styles'); +const supportsColor = require('supports-color'); -var defineProps = Object.defineProperties; -var isSimpleWindowsTerm = process.platform === 'win32' && !/^xterm/i.test(process.env.TERM); +const defineProps = Object.defineProperties; +const isSimpleWindowsTerm = process.platform === 'win32' && !process.env.TERM.toLowerCase().startsWith('xterm'); -// supportsColor.level -> ansiStyles.color[name] mapping -var levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; -// color-convert models to exclude from the Chalk API due to conflicts and such. -var skipModels = ['gray']; +// `supportsColor.level` → `ansiStyles.color[name]` mapping +const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; +// `color-convert` models to exclude from the Chalk API due to conflicts and such +const skipModels = ['gray']; function Chalk(options) { - // detect level if not set manually + // Detect level if not set manually this.level = !options || options.level === undefined ? supportsColor.level : options.level; } -// use bright blue on Windows as the normal blue color is illegible +// Use bright blue on Windows as the normal blue color is illegible if (isSimpleWindowsTerm) { - ansiStyles.blue.open = '\u001b[94m'; + ansiStyles.blue.open = '\u001B[94m'; } -var styles = {}; +const styles = Object.create(null); -Object.keys(ansiStyles).forEach(function (key) { +for (const key of Object.keys(ansiStyles)) { ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g'); styles[key] = { - get: function () { - var codes = ansiStyles[key]; + get() { + const codes = ansiStyles[key]; return build.call(this, this._styles ? this._styles.concat(codes) : [codes], key); } }; -}); +} ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g'); -Object.keys(ansiStyles.color.ansi).forEach(function (model) { +for (const model of Object.keys(ansiStyles.color.ansi)) { if (skipModels.indexOf(model) !== -1) { - return; + continue; } styles[model] = { - get: function () { - var level = this.level; + get() { + const level = this.level; return function () { - var open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments); - var codes = {open: open, close: ansiStyles.color.close, closeRe: ansiStyles.color.closeRe}; + const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments); + const codes = { + open, + close: ansiStyles.color.close, + closeRe: ansiStyles.color.closeRe + }; return build.call(this, this._styles ? this._styles.concat(codes) : [codes], model); }; } }; -}); +} ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g'); -Object.keys(ansiStyles.bgColor.ansi).forEach(function (model) { +for (const model of Object.keys(ansiStyles.bgColor.ansi)) { if (skipModels.indexOf(model) !== -1) { - return; + continue; } - var bgModel = 'bg' + model.charAt(0).toUpperCase() + model.substring(1); + const bgModel = 'bg' + model.charAt(0).toUpperCase() + model.slice(1); styles[bgModel] = { - get: function () { - var level = this.level; + get() { + const level = this.level; return function () { - var open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments); - var codes = {open: open, close: ansiStyles.bgColor.close, closeRe: ansiStyles.bgColor.closeRe}; + const open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments); + const codes = { + open, + close: ansiStyles.bgColor.close, + closeRe: ansiStyles.bgColor.closeRe + }; return build.call(this, this._styles ? this._styles.concat(codes) : [codes], model); }; } }; -}); +} // eslint-disable-next-line func-names -var proto = defineProps(function chalk() {}, styles); +const proto = defineProps(() => {}, styles); function build(_styles, key) { - var builder = function () { + const builder = function () { return applyStyle.apply(builder, arguments); }; - var self = this; - builder._styles = _styles; + const self = this; Object.defineProperty(builder, 'level', { enumerable: true, - get: function () { + get() { return self.level; }, - set: function (level) { + set(level) { self.level = level; } }); - // see below for fix regarding invisible grey/dim combination on windows. + // See below for fix regarding invisible grey/dim combination on Windows builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; - // __proto__ is used because we must return a function, but there is + // `__proto__` is used because we must return a function, but there is // no way to create a function with a different prototype. - /* eslint-disable no-proto */ - builder.__proto__ = proto; + builder.__proto__ = proto; // eslint-disable-line no-proto return builder; } function applyStyle() { - // support varags, but simply cast to string in case there's only one arg - var args = arguments; - var argsLen = args.length; - var str = argsLen !== 0 && String(arguments[0]); + // Support varags, but simply cast to string in case there's only one arg + const args = arguments; + const argsLen = args.length; + let str = argsLen !== 0 && String(arguments[0]); if (argsLen > 1) { - // don't slice `arguments`, it prevents v8 optimizations - for (var a = 1; a < argsLen; a++) { + // Don't slice `arguments`, it prevents V8 optimizations + for (let a = 1; a < argsLen; a++) { str += ' ' + args[a]; } } @@ -121,19 +127,19 @@ function applyStyle() { return str; } - var nestedStyles = this._styles; - var i = nestedStyles.length; + const nestedStyles = this._styles; + let i = nestedStyles.length; // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe, // see https://github.com/chalk/chalk/issues/58 // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop. - var originalDim = ansiStyles.dim.open; + const originalDim = ansiStyles.dim.open; if (isSimpleWindowsTerm && this.hasGrey) { ansiStyles.dim.open = ''; } while (i--) { - var code = nestedStyles[i]; + const code = nestedStyles[i]; // Replace any instances already present with a re-opening code // otherwise only the part of the string until said closing code @@ -143,10 +149,10 @@ function applyStyle() { // Close the styling before a linebreak and reopen // after next line to fix a bleed issue on macOS // https://github.com/chalk/chalk/pull/92 - str = str.replace(/\r?\n/g, code.close + '$&' + code.open); + str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`); } - // Reset the original 'dim' if we changed it to work around the Windows dimmed gray issue. + // Reset the original 'dim' if we changed it to work around the Windows dimmed gray issue ansiStyles.dim.open = originalDim; return str; diff --git a/license b/license index 654d0bf..e7af2f7 100644 --- a/license +++ b/license @@ -1,21 +1,9 @@ -The MIT License (MIT) +MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/package.json b/package.json index f8d2344..ce879be 100644 --- a/package.json +++ b/package.json @@ -1,70 +1,61 @@ { - "name": "chalk", - "version": "1.1.1", - "description": "Terminal string styling done right. Much color.", - "license": "MIT", - "repository": "chalk/chalk", - "maintainers": [ - "Sindre Sorhus (sindresorhus.com)", - "Joshua Boy Nicolai Appelman (jbna.nl)", - "JD Ballard (github.com/qix-)" - ], - "engines": { - "node": ">=4" - }, - "scripts": { - "test": "xo && nyc mocha", - "bench": "matcha benchmark.js", - "coveralls": "nyc report --reporter=text-lcov | coveralls" - }, - "files": [ - "index.js" - ], - "keywords": [ - "color", - "colour", - "colors", - "terminal", - "console", - "cli", - "string", - "str", - "ansi", - "style", - "styles", - "tty", - "formatting", - "rgb", - "256", - "shell", - "xterm", - "log", - "logging", - "command-line", - "text" - ], - "dependencies": { - "ansi-styles": "^3.0.0", - "escape-string-regexp": "^1.0.2", - "supports-color": "^3.2.3" - }, - "devDependencies": { - "coveralls": "^2.11.2", - "import-fresh": "^2.0.0", - "matcha": "^0.7.0", - "mocha": "*", - "nyc": "^10.3.2", - "resolve-from": "^3.0.0", - "semver": "^5.1.0", - "xo": "^0.16.0" - }, - "xo": { - "envs": [ - "node", - "mocha" - ], - "ignores": [ - "example.js" - ] - } + "name": "chalk", + "version": "1.1.1", + "description": "Terminal string styling done right. Much color", + "license": "MIT", + "repository": "chalk/chalk", + "engines": { + "node": ">=4" + }, + "scripts": { + "test": "xo && nyc mocha", + "bench": "matcha benchmark.js", + "coveralls": "nyc report --reporter=text-lcov | coveralls" + }, + "files": [ + "index.js" + ], + "keywords": [ + "color", + "colour", + "colors", + "terminal", + "console", + "cli", + "string", + "str", + "ansi", + "style", + "styles", + "tty", + "formatting", + "rgb", + "256", + "shell", + "xterm", + "log", + "logging", + "command-line", + "text" + ], + "dependencies": { + "ansi-styles": "^3.0.0", + "escape-string-regexp": "^1.0.2", + "supports-color": "^3.2.3" + }, + "devDependencies": { + "coveralls": "^2.11.2", + "import-fresh": "^2.0.0", + "matcha": "^0.7.0", + "mocha": "*", + "nyc": "^11.0.2", + "resolve-from": "^3.0.0", + "xo": "*" + }, + "xo": { + "envs": [ + "node", + "mocha" + ] + } } diff --git a/readme.md b/readme.md index a6d5544..d06e842 100644 --- a/readme.md +++ b/readme.md @@ -227,6 +227,7 @@ As of this writing, these are the supported color models that are exposed in Cha For a complete list of color models, see [`color-convert`'s list of conversions](https://github.com/Qix-/color-convert/blob/master/conversions.js). + ## Windows If you're on Windows, do yourself a favor and use [`cmder`](http://cmder.net/) instead of `cmd.exe`. @@ -245,6 +246,12 @@ If you're on Windows, do yourself a favor and use [`cmder`](http://cmder.net/) i - [color-convert](https://github.com/qix-/color-convert) - Converts colors between different models +## Maintainers + +- [Sindre Sorhus](https://github.com/sindresorhus) +- [Josh Junon](https://github.com/qix-) + + ## License -MIT © [Sindre Sorhus](https://sindresorhus.com) +MIT diff --git a/test.js b/test.js index 144efaf..e4df628 100644 --- a/test.js +++ b/test.js @@ -1,179 +1,173 @@ 'use strict'; -var assert = require('assert'); -var importFresh = require('import-fresh'); -var resolveFrom = require('resolve-from'); -var semver = require('semver'); -var chalk = require('.'); +const assert = require('assert'); +const importFresh = require('import-fresh'); +const resolveFrom = require('resolve-from'); +const chalk = require('.'); -describe('chalk', function () { - it('should style string', function () { - assert.equal(chalk.underline('foo'), '\u001b[4mfoo\u001b[24m'); - assert.equal(chalk.red('foo'), '\u001b[31mfoo\u001b[39m'); - assert.equal(chalk.bgRed('foo'), '\u001b[41mfoo\u001b[49m'); +describe('chalk', () => { + it('should style string', () => { + assert.equal(chalk.underline('foo'), '\u001B[4mfoo\u001B[24m'); + assert.equal(chalk.red('foo'), '\u001B[31mfoo\u001B[39m'); + assert.equal(chalk.bgRed('foo'), '\u001B[41mfoo\u001B[49m'); }); - it('should support applying multiple styles at once', function () { - assert.equal(chalk.red.bgGreen.underline('foo'), '\u001b[31m\u001b[42m\u001b[4mfoo\u001b[24m\u001b[49m\u001b[39m'); - assert.equal(chalk.underline.red.bgGreen('foo'), '\u001b[4m\u001b[31m\u001b[42mfoo\u001b[49m\u001b[39m\u001b[24m'); + it('should support applying multiple styles at once', () => { + assert.equal(chalk.red.bgGreen.underline('foo'), '\u001B[31m\u001B[42m\u001B[4mfoo\u001B[24m\u001B[49m\u001B[39m'); + assert.equal(chalk.underline.red.bgGreen('foo'), '\u001B[4m\u001B[31m\u001B[42mfoo\u001B[49m\u001B[39m\u001B[24m'); }); - it('should support nesting styles', function () { + it('should support nesting styles', () => { assert.equal( chalk.red('foo' + chalk.underline.bgBlue('bar') + '!'), - '\u001b[31mfoo\u001b[4m\u001b[44mbar\u001b[49m\u001b[24m!\u001b[39m' + '\u001B[31mfoo\u001B[4m\u001B[44mbar\u001B[49m\u001B[24m!\u001B[39m' ); }); - it('should support nesting styles of the same type (color, underline, bg)', function () { + it('should support nesting styles of the same type (color, underline, bg)', () => { assert.equal( chalk.red('a' + chalk.yellow('b' + chalk.green('c') + 'b') + 'c'), - '\u001b[31ma\u001b[33mb\u001b[32mc\u001b[33mb\u001b[31mc\u001b[39m' + '\u001B[31ma\u001B[33mb\u001B[32mc\u001B[33mb\u001B[31mc\u001B[39m' ); }); - it('should reset all styles with `.reset()`', function () { - assert.equal(chalk.reset(chalk.red.bgGreen.underline('foo') + 'foo'), '\u001b[0m\u001b[31m\u001b[42m\u001b[4mfoo\u001b[24m\u001b[49m\u001b[39mfoo\u001b[0m'); + it('should reset all styles with `.reset()`', () => { + assert.equal(chalk.reset(chalk.red.bgGreen.underline('foo') + 'foo'), '\u001B[0m\u001B[31m\u001B[42m\u001B[4mfoo\u001B[24m\u001B[49m\u001B[39mfoo\u001B[0m'); }); - it('should be able to cache multiple styles', function () { - var red = chalk.red; - var green = chalk.green; - var redBold = red.bold; - var greenBold = green.bold; + it('should be able to cache multiple styles', () => { + const red = chalk.red; + const green = chalk.green; + const redBold = red.bold; + const greenBold = green.bold; assert.notEqual(red('foo'), green('foo')); assert.notEqual(redBold('bar'), greenBold('bar')); assert.notEqual(green('baz'), greenBold('baz')); }); - it('should alias gray to grey', function () { - assert.equal(chalk.grey('foo'), '\u001b[90mfoo\u001b[39m'); + it('should alias gray to grey', () => { + assert.equal(chalk.grey('foo'), '\u001B[90mfoo\u001B[39m'); }); - it('should support variable number of arguments', function () { - assert.equal(chalk.red('foo', 'bar'), '\u001b[31mfoo bar\u001b[39m'); + it('should support variable number of arguments', () => { + assert.equal(chalk.red('foo', 'bar'), '\u001B[31mfoo bar\u001B[39m'); }); - it('should support falsy values', function () { - assert.equal(chalk.red(0), '\u001b[31m0\u001b[39m'); + it('should support falsy values', () => { + assert.equal(chalk.red(0), '\u001B[31m0\u001B[39m'); }); - it('shouldn\'t output escape codes if the input is empty', function () { + it('shouldn\'t output escape codes if the input is empty', () => { assert.equal(chalk.red(), ''); assert.equal(chalk.red.blue.black(), ''); }); - it('should keep Function.prototype methods', function () { - assert.equal(chalk.grey.apply(null, ['foo']), '\u001b[90mfoo\u001b[39m'); - assert.equal(chalk.reset(chalk.red.bgGreen.underline.bind(null)('foo') + 'foo'), '\u001b[0m\u001b[31m\u001b[42m\u001b[4mfoo\u001b[24m\u001b[49m\u001b[39mfoo\u001b[0m'); + it('should keep Function.prototype methods', () => { + assert.equal(chalk.grey.apply(null, ['foo']), '\u001B[90mfoo\u001B[39m'); + assert.equal(chalk.reset(chalk.red.bgGreen.underline.bind(null)('foo') + 'foo'), '\u001B[0m\u001B[31m\u001B[42m\u001B[4mfoo\u001B[24m\u001B[49m\u001B[39mfoo\u001B[0m'); assert.equal(chalk.red.blue.black.call(null), ''); }); - it('line breaks should open and close colors', function () { - assert.equal(chalk.grey('hello\nworld'), '\u001b[90mhello\u001b[39m\n\u001b[90mworld\u001b[39m'); + it('line breaks should open and close colors', () => { + assert.equal(chalk.grey('hello\nworld'), '\u001B[90mhello\u001B[39m\n\u001B[90mworld\u001B[39m'); }); - it('should properly convert RGB to 16 colors on basic color terminals', function () { - assert.equal(new chalk.constructor({level: 1}).hex('#FF0000')('hello'), '\u001b[91mhello\u001b[39m'); - assert.equal(new chalk.constructor({level: 1}).bgHex('#FF0000')('hello'), '\u001b[101mhello\u001b[49m'); + it('should properly convert RGB to 16 colors on basic color terminals', () => { + assert.equal(new chalk.constructor({level: 1}).hex('#FF0000')('hello'), '\u001B[91mhello\u001B[39m'); + assert.equal(new chalk.constructor({level: 1}).bgHex('#FF0000')('hello'), '\u001B[101mhello\u001B[49m'); }); - it('should properly convert RGB to 256 colors on basic color terminals', function () { - assert.equal(new chalk.constructor({level: 2}).hex('#FF0000')('hello'), '\u001b[38;5;196mhello\u001b[39m'); - assert.equal(new chalk.constructor({level: 2}).bgHex('#FF0000')('hello'), '\u001b[48;5;196mhello\u001b[49m'); + it('should properly convert RGB to 256 colors on basic color terminals', () => { + assert.equal(new chalk.constructor({level: 2}).hex('#FF0000')('hello'), '\u001B[38;5;196mhello\u001B[39m'); + assert.equal(new chalk.constructor({level: 2}).bgHex('#FF0000')('hello'), '\u001B[48;5;196mhello\u001B[49m'); }); - it('should properly convert RGB to 256 colors on basic color terminals', function () { - assert.equal(new chalk.constructor({level: 3}).hex('#FF0000')('hello'), '\u001b[38;2;255;0;0mhello\u001b[39m'); - assert.equal(new chalk.constructor({level: 3}).bgHex('#FF0000')('hello'), '\u001b[48;2;255;0;0mhello\u001b[49m'); + it('should properly convert RGB to 256 colors on basic color terminals', () => { + assert.equal(new chalk.constructor({level: 3}).hex('#FF0000')('hello'), '\u001B[38;2;255;0;0mhello\u001B[39m'); + assert.equal(new chalk.constructor({level: 3}).bgHex('#FF0000')('hello'), '\u001B[48;2;255;0;0mhello\u001B[49m'); }); - it('should not emit RGB codes if level is 0', function () { + it('should not emit RGB codes if level is 0', () => { assert.equal(new chalk.constructor({level: 0}).hex('#FF0000')('hello'), 'hello'); assert.equal(new chalk.constructor({level: 0}).bgHex('#FF0000')('hello'), 'hello'); }); }); -describe('chalk on windows', function () { - var originalEnv; - var originalPlatform; +describe('chalk on windows', () => { + let originalEnv; + let originalPlatform; - // in node versions older than 0.12.x process.platform cannot be overridden - if (semver.lt(process.version, '0.12.0')) { - return; - } - - before(function () { + before(() => { originalEnv = process.env; originalPlatform = process.platform; }); - after(function () { + after(() => { process.env = originalEnv; Object.defineProperty(process, 'platform', {value: originalPlatform}); }); - beforeEach(function () { + beforeEach(() => { process.env = {}; Object.defineProperty(process, 'platform', {value: 'win32'}); - // since chalk internally modifies ansiStyles.blue.open, ansi-styles needs - // to be removed from the require cache for require-uncached to work + // Since chalk internally modifies `ansiStyles.blue.open`, `ansi-styles` needs + // to be removed from the require cache for `require-uncached` to work delete require.cache[resolveFrom(__dirname, 'ansi-styles')]; }); - it('should replace blue foreground color in cmd.exe', function () { + it('should replace blue foreground color in cmd.exe', () => { process.env.TERM = 'dumb'; - var chalkCtx = importFresh('.'); - assert.equal(chalkCtx.blue('foo'), '\u001b[94mfoo\u001b[39m'); + const chalkCtx = importFresh('.'); + assert.equal(chalkCtx.blue('foo'), '\u001B[94mfoo\u001B[39m'); }); - it('shouldn\'t replace blue foreground color in xterm based terminals', function () { + it('shouldn\'t replace blue foreground color in xterm based terminals', () => { process.env.TERM = 'xterm-256color'; - var chalkCtx = importFresh('.'); - assert.equal(chalkCtx.blue('foo'), '\u001b[34mfoo\u001b[39m'); + const chalkCtx = importFresh('.'); + assert.equal(chalkCtx.blue('foo'), '\u001B[34mfoo\u001B[39m'); }); - it('should not apply dimmed styling on gray strings, see https://github.com/chalk/chalk/issues/58', function () { + it('should not apply dimmed styling on gray strings, see https://github.com/chalk/chalk/issues/58', () => { process.env.TERM = 'dumb'; - var chalkCtx = importFresh('.'); - assert.equal(chalkCtx.gray.dim('foo'), '\u001b[90mfoo\u001b[22m\u001b[39m'); + const chalkCtx = importFresh('.'); + assert.equal(chalkCtx.gray.dim('foo'), '\u001B[90mfoo\u001B[22m\u001B[39m'); }); - it('should apply dimmed styling on xterm compatible terminals', function () { + it('should apply dimmed styling on xterm compatible terminals', () => { process.env.TERM = 'xterm'; - var chalkCtx = importFresh('.'); - assert.equal(chalkCtx.gray.dim('foo'), '\u001b[90m\u001b[2mfoo\u001b[22m\u001b[39m'); + const chalkCtx = importFresh('.'); + assert.equal(chalkCtx.gray.dim('foo'), '\u001B[90m\u001B[2mfoo\u001B[22m\u001B[39m'); }); - it('should apply dimmed styling on strings of other colors', function () { + it('should apply dimmed styling on strings of other colors', () => { process.env.TERM = 'dumb'; - var chalkCtx = importFresh('.'); - assert.equal(chalkCtx.blue.dim('foo'), '\u001b[94m\u001b[2mfoo\u001b[22m\u001b[39m'); + const chalkCtx = importFresh('.'); + assert.equal(chalkCtx.blue.dim('foo'), '\u001B[94m\u001B[2mfoo\u001B[22m\u001B[39m'); }); }); -describe('chalk.level', function () { - it('should not output colors when manually disabled', function () { - var oldLevel = chalk.level; +describe('chalk.level', () => { + it('should not output colors when manually disabled', () => { + const oldLevel = chalk.level; chalk.level = 0; assert.equal(chalk.red('foo'), 'foo'); chalk.level = oldLevel; }); - it('should enable/disable colors based on overall chalk enabled property, not individual instances', function () { - var oldLevel = chalk.level; + it('should enable/disable colors based on overall chalk enabled property, not individual instances', () => { + const oldLevel = chalk.level; chalk.level = 1; - var red = chalk.red; + const red = chalk.red; assert.equal(red.level, 1); chalk.level = 0; assert.equal(red.level, chalk.level); chalk.level = oldLevel; }); - it('should propagate enable/disable changes from child colors', function () { - var oldLevel = chalk.level; + it('should propagate enable/disable changes from child colors', () => { + const oldLevel = chalk.level; chalk.level = 1; - var red = chalk.red; + const red = chalk.red; assert.equal(red.level, 1); assert.equal(chalk.level, 1); red.level = 0; @@ -186,16 +180,16 @@ describe('chalk.level', function () { }); }); -describe('chalk.constructor', function () { - it('should create a isolated context where colors can be disabled', function () { - var ctx = new chalk.constructor({level: 0}); +describe('chalk.constructor', () => { + it('should create a isolated context where colors can be disabled', () => { + const ctx = new chalk.constructor({level: 0}); assert.equal(ctx.red('foo'), 'foo'); - assert.equal(chalk.red('foo'), '\u001b[31mfoo\u001b[39m'); + assert.equal(chalk.red('foo'), '\u001B[31mfoo\u001B[39m'); }); }); -describe('chalk.styles', function () { - it('should expose the styles as ANSI escape codes', function () { - assert.equal(chalk.styles.red.open, '\u001b[31m'); +describe('chalk.styles', () => { + it('should expose the styles as ANSI escape codes', () => { + assert.equal(chalk.styles.red.open, '\u001B[31m'); }); });