Skip to content

Commit 3ef170b

Browse files
committed
Require Node.js 8
1 parent de2f4cd commit 3ef170b

6 files changed

Lines changed: 56 additions & 54 deletions

File tree

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ language: node_js
22
node_js:
33
- '10'
44
- '8'
5-
- '6'
65
after_success:
76
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'

examples/rainbow.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,39 @@ const chalk = require('..');
33

44
const ignoreChars = /[^!-~]/g;
55

6-
function rainbow(str, offset) {
7-
if (!str || str.length === 0) {
8-
return str;
6+
const delay = milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds));
7+
8+
function rainbow(string, offset) {
9+
if (!string || string.length === 0) {
10+
return string;
911
}
1012

11-
const hueStep = 360 / str.replace(ignoreChars, '').length;
13+
const hueStep = 360 / string.replace(ignoreChars, '').length;
1214

1315
let hue = offset % 360;
14-
const chars = [];
15-
for (const c of str) {
16-
if (c.match(ignoreChars)) {
17-
chars.push(c);
16+
const characters = [];
17+
for (const character of string) {
18+
if (character.match(ignoreChars)) {
19+
characters.push(character);
1820
} else {
19-
chars.push(chalk.hsl(hue, 100, 50)(c));
21+
characters.push(chalk.hsl(hue, 100, 50)(character));
2022
hue = (hue + hueStep) % 360;
2123
}
2224
}
2325

24-
return chars.join('');
26+
return characters.join('');
2527
}
2628

27-
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
28-
29-
async function animateString(str) {
29+
async function animateString(string) {
3030
console.log();
3131
for (let i = 0; i < 360 * 5; i++) {
32-
console.log('\u001B[1F\u001B[G ', rainbow(str, i));
33-
await sleep(2); // eslint-disable-line no-await-in-loop
32+
console.log('\u001B[1F\u001B[G', rainbow(string, i));
33+
await delay(2); // eslint-disable-line no-await-in-loop
3434
}
3535
}
3636

37-
console.log();
38-
animateString('We hope you enjoy the new version of Chalk 2! <3').then(() => console.log());
37+
(async () => {
38+
console.log();
39+
await animateString('We hope you enjoy Chalk! <3');
40+
console.log();
41+
})();

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,6 @@ export interface Chalk {
271271
* Order doesn't matter, and later styles take precedent in case of a conflict.
272272
* This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`.
273273
*/
274-
declare const chalk: Chalk & { supportsColor: ColorSupport };
274+
declare const chalk: Chalk & {supportsColor: ColorSupport};
275275

276276
export default chalk;

index.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ const template = require('./templates.js');
77
const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm');
88

99
// `supportsColor.level` → `ansiStyles.color[name]` mapping
10-
const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m'];
10+
const levelMapping = [
11+
'ansi',
12+
'ansi',
13+
'ansi256',
14+
'ansi16m'
15+
];
1116

1217
// `color-convert` models to exclude from the Chalk API due to conflicts and such
1318
const skipModels = new Set(['gray']);
@@ -35,14 +40,15 @@ function chalkFactory(options) {
3540
const chalk = {};
3641
applyOptions(chalk, options);
3742

38-
chalk.template = (...args) => chalkTag(chalk.template, ...args);
43+
chalk.template = (...arguments_) => chalkTag(chalk.template, ...arguments_);
3944

4045
Object.setPrototypeOf(chalk, Chalk.prototype);
4146
Object.setPrototypeOf(chalk.template, chalk);
4247

4348
chalk.template.constructor = () => {
4449
throw new Error('`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.');
4550
};
51+
4652
chalk.template.Instance = ChalkClass;
4753

4854
return chalk.template;
@@ -57,13 +63,12 @@ if (isSimpleWindowsTerm) {
5763
ansiStyles.blue.open = '\u001B[94m';
5864
}
5965

60-
for (const key of Object.keys(ansiStyles)) {
61-
ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
66+
for (const [styleName, style] of Object.entries(ansiStyles)) {
67+
style.closeRe = new RegExp(escapeStringRegexp(style.close), 'g');
6268

63-
styles[key] = {
69+
styles[styleName] = {
6470
get() {
65-
const codes = ansiStyles[key];
66-
return build.call(this, [...(this._styles || []), codes], this._empty, key);
71+
return build.call(this, [...(this._styles || []), style], this._empty, styleName);
6772
}
6873
};
6974
}
@@ -106,8 +111,8 @@ for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
106111
styles[bgModel] = {
107112
get() {
108113
const {level} = this;
109-
return function (...args) {
110-
const open = ansiStyles.bgColor[levelMapping[level]][model](...args);
114+
return function (...arguments_) {
115+
const open = ansiStyles.bgColor[levelMapping[level]][model](...arguments_);
111116
const codes = {
112117
open,
113118
close: ansiStyles.bgColor.close,
@@ -122,7 +127,7 @@ for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
122127
const proto = Object.defineProperties(() => {}, styles);
123128

124129
function build(_styles, _empty, key) {
125-
const builder = (...args) => applyStyle.call(builder, ...args);
130+
const builder = (...arguments_) => applyStyle.call(builder, ...arguments_);
126131
builder._styles = _styles;
127132
builder._empty = _empty;
128133

@@ -158,8 +163,8 @@ function build(_styles, _empty, key) {
158163
return builder;
159164
}
160165

161-
function applyStyle(...args) {
162-
let string = args.join(' ');
166+
function applyStyle(...arguments_) {
167+
let string = arguments_.join(' ');
163168

164169
if (!this.enabled || this.level <= 0 || !string) {
165170
return this._empty ? '' : string;
@@ -200,12 +205,12 @@ function chalkTag(chalk, ...strings) {
200205
return strings.join(' ');
201206
}
202207

203-
const args = strings.slice(1);
208+
const arguments_ = strings.slice(1);
204209
const parts = [firstString.raw[0]];
205210

206211
for (let i = 1; i < firstString.length; i++) {
207212
parts.push(
208-
String(args[i - 1]).replace(/[{}\\]/g, '\\$&'),
213+
String(arguments_[i - 1]).replace(/[{}\\]/g, '\\$&'),
209214
String(firstString.raw[i])
210215
);
211216
}

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": "MIT",
66
"repository": "chalk/chalk",
77
"engines": {
8-
"node": ">=6"
8+
"node": ">=8"
99
},
1010
"scripts": {
1111
"test": "xo && nyc ava && tsd-check && flow",
@@ -43,20 +43,20 @@
4343
"dependencies": {
4444
"ansi-styles": "^3.2.1",
4545
"escape-string-regexp": "^1.0.5",
46-
"supports-color": "^6.0.0"
46+
"supports-color": "^6.1.0"
4747
},
4848
"devDependencies": {
49-
"@sindresorhus/tsconfig": "^0.1.1",
50-
"ava": "^1.0.1",
51-
"coveralls": "^3.0.2",
49+
"@sindresorhus/tsconfig": "^0.2.1",
50+
"ava": "^1.3.1",
51+
"coveralls": "^3.0.3",
5252
"execa": "^1.0.0",
53-
"flow-bin": "^0.89.0",
53+
"flow-bin": "^0.94.0",
5454
"import-fresh": "^3.0.0",
5555
"matcha": "^0.7.0",
56-
"nyc": "^13.1.0",
56+
"nyc": "^13.3.0",
5757
"resolve-from": "^4.0.0",
5858
"tsd-check": "^0.3.0",
59-
"xo": "^0.23.0"
59+
"xo": "^0.24.0"
6060
},
6161
"types": "index.d.ts",
6262
"xo": {

templates.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ function unescape(c) {
2525
return ESCAPES.get(c) || c;
2626
}
2727

28-
function parseArguments(name, args) {
28+
function parseArguments(name, arguments_) {
2929
const results = [];
30-
const chunks = args.trim().split(/\s*,\s*/g);
30+
const chunks = arguments_.trim().split(/\s*,\s*/g);
3131
let matches;
3232

3333
for (const chunk of chunks) {
@@ -51,7 +51,7 @@ function parseStyle(style) {
5151
let matches;
5252

5353
while ((matches = STYLE_REGEX.exec(style)) !== null) {
54-
const name = matches[1]; // eslint-disable-line prefer-destructuring
54+
const name = matches[1];
5555

5656
if (matches[2]) {
5757
const args = parseArguments(name, matches[2]);
@@ -74,33 +74,28 @@ function buildStyle(chalk, styles) {
7474
}
7575

7676
let current = chalk;
77-
// TODO: Use `Object.entries` when targeting Node.js 8
78-
for (const styleName of Object.keys(enabled)) {
79-
if (!Array.isArray(enabled[styleName])) {
77+
for (const [styleName, styles] of Object.entries(enabled)) {
78+
if (!Array.isArray(styles)) {
8079
continue;
8180
}
8281

8382
if (!(styleName in current)) {
8483
throw new Error(`Unknown Chalk style: ${styleName}`);
8584
}
8685

87-
if (enabled[styleName].length > 0) {
88-
current = current[styleName](...enabled[styleName]);
89-
} else {
90-
current = current[styleName];
91-
}
86+
current = styles.length > 0 ? current[styleName](...styles) : current[styleName];
9287
}
9388

9489
return current;
9590
}
9691

97-
module.exports = (chalk, tmp) => {
92+
module.exports = (chalk, temporary) => {
9893
const styles = [];
9994
const chunks = [];
10095
let chunk = [];
10196

10297
// eslint-disable-next-line max-params
103-
tmp.replace(TEMPLATE_REGEX, (m, escapeCharacter, inverse, style, close, character) => {
98+
temporary.replace(TEMPLATE_REGEX, (m, escapeCharacter, inverse, style, close, character) => {
10499
if (escapeCharacter) {
105100
chunk.push(unescape(escapeCharacter));
106101
} else if (style) {

0 commit comments

Comments
 (0)