Skip to content

Commit 61999a4

Browse files
committed
Require Node.js 10
1 parent f0f4638 commit 61999a4

8 files changed

Lines changed: 32 additions & 26 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
- '12'
44
- '10'
5-
- '8'
65
after_success:
76
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'

examples/screenshot.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ const chalk = require('..');
44

55
// Generates screenshot
66
for (const key of Object.keys(styles)) {
7-
let ret = key;
7+
let returnValue = key;
88

99
if (key === 'reset' || key === 'hidden' || key === 'grey') {
1010
continue;
1111
}
1212

1313
if (/^bg[^B]/.test(key)) {
14-
ret = chalk.black(ret);
14+
returnValue = chalk.black(returnValue);
1515
}
1616

17-
process.stdout.write(chalk[key](ret) + ' ');
17+
process.stdout.write(chalk[key](returnValue) + ' ');
1818
}

index.d.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,10 @@ declare namespace chalk {
9191
level?: Level;
9292
}
9393

94-
interface Instance {
95-
/**
96-
Return a new Chalk instance.
97-
*/
98-
new (options?: Options): Chalk;
99-
}
94+
/**
95+
Return a new Chalk instance.
96+
*/
97+
type Instance = new (options?: Options) => Chalk;
10098

10199
/**
102100
Detect whether the terminal supports color.

index.test-d.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@ type colorReturn = chalk.Chalk & {supportsColor?: never};
66

77
// - supportsColor -
88
expectType<chalk.ColorSupport | false>(chalk.supportsColor);
9-
expectType<boolean>((chalk.supportsColor as chalk.ColorSupport).hasBasic);
10-
expectType<boolean>((chalk.supportsColor as chalk.ColorSupport).has256);
11-
expectType<boolean>((chalk.supportsColor as chalk.ColorSupport).has16m);
9+
if (chalk.supportsColor) {
10+
expectType<boolean>(chalk.supportsColor.hasBasic);
11+
expectType<boolean>(chalk.supportsColor.has256);
12+
expectType<boolean>(chalk.supportsColor.has16m);
13+
}
1214

1315
// - stderr -
1416
expectType<chalk.Chalk>(chalk.stderr);
1517
expectType<chalk.ColorSupport | false>(chalk.stderr.supportsColor);
16-
expectType<boolean>((chalk.stderr.supportsColor as chalk.ColorSupport).hasBasic);
17-
expectType<boolean>((chalk.stderr.supportsColor as chalk.ColorSupport).has256);
18-
expectType<boolean>((chalk.stderr.supportsColor as chalk.ColorSupport).has16m);
18+
if (chalk.stderr.supportsColor) {
19+
expectType<boolean>(chalk.stderr.supportsColor.hasBasic);
20+
expectType<boolean>(chalk.stderr.supportsColor.has256);
21+
expectType<boolean>(chalk.stderr.supportsColor.has16m);
22+
}
1923

2024
// -- `stderr` is not a member of the Chalk interface --
2125
expectError(chalk.reset.stderr);

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"funding": "https://github.com/chalk/chalk?sponsor=1",
88
"main": "source",
99
"engines": {
10-
"node": ">=8"
10+
"node": ">=10"
1111
},
1212
"scripts": {
1313
"test": "xo && nyc ava && tsd",
@@ -47,18 +47,22 @@
4747
"devDependencies": {
4848
"ava": "^2.4.0",
4949
"coveralls": "^3.0.7",
50-
"execa": "^3.2.0",
50+
"execa": "^4.0.0",
5151
"import-fresh": "^3.1.0",
5252
"matcha": "^0.7.0",
5353
"nyc": "^15.0.0",
5454
"resolve-from": "^5.0.0",
5555
"tsd": "^0.7.4",
56-
"xo": "^0.25.3"
56+
"xo": "^0.28.2"
5757
},
5858
"xo": {
5959
"rules": {
6060
"unicorn/prefer-string-slice": "off",
61-
"unicorn/prefer-includes": "off"
61+
"unicorn/prefer-includes": "off",
62+
"@typescript-eslint/member-ordering": "off",
63+
"no-redeclare": "off",
64+
"unicorn/string-content": "off",
65+
"unicorn/better-regex": "off"
6266
}
6367
}
6468
}

source/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const levelMapping = [
1717
const styles = Object.create(null);
1818

1919
const applyOptions = (object, options = {}) => {
20-
if (!Number.isInteger(options.level) || options.level > 3 || options.level < 0) {
20+
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
2121
throw new Error('The `level` option should be an integer from 0 to 3');
2222
}
2323

@@ -28,6 +28,7 @@ const applyOptions = (object, options = {}) => {
2828

2929
class ChalkClass {
3030
constructor(options) {
31+
// eslint-disable-next-line no-constructor-return
3132
return chalkFactory(options);
3233
}
3334
}

source/templates.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const TEMPLATE_REGEX = /(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
33
const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
44
const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
5-
const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|([^\\])/gi;
5+
const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi;
66

77
const ESCAPES = new Map([
88
['n', '\n'],
@@ -126,8 +126,8 @@ module.exports = (chalk, temporary) => {
126126
chunks.push(chunk.join(''));
127127

128128
if (styles.length > 0) {
129-
const errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
130-
throw new Error(errMsg);
129+
const errMessage = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
130+
throw new Error(errMessage);
131131
}
132132

133133
return chunks.join('');

test/template-literal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ test('correctly parse newline escapes (bug #177)', t => {
121121

122122
test('correctly parse escape in parameters (bug #177 comment 318622809)', t => {
123123
const instance = new chalk.Instance({level: 0});
124-
const str = '\\';
125-
t.is(instance`{blue ${str}}`, '\\');
124+
const string = '\\';
125+
t.is(instance`{blue ${string}}`, '\\');
126126
});
127127

128128
test('correctly parses unicode/hex escapes', t => {

0 commit comments

Comments
 (0)