Require Node.js 10

This commit is contained in:
Sindre Sorhus 2020-04-02 15:56:21 +08:00
parent f0f4638a92
commit 61999a4e77
8 changed files with 32 additions and 26 deletions

View file

@ -2,6 +2,5 @@ language: node_js
node_js: node_js:
- '12' - '12'
- '10' - '10'
- '8'
after_success: after_success:
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls' - './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'

View file

@ -4,15 +4,15 @@ const chalk = require('..');
// Generates screenshot // Generates screenshot
for (const key of Object.keys(styles)) { for (const key of Object.keys(styles)) {
let ret = key; let returnValue = key;
if (key === 'reset' || key === 'hidden' || key === 'grey') { if (key === 'reset' || key === 'hidden' || key === 'grey') {
continue; continue;
} }
if (/^bg[^B]/.test(key)) { if (/^bg[^B]/.test(key)) {
ret = chalk.black(ret); returnValue = chalk.black(returnValue);
} }
process.stdout.write(chalk[key](ret) + ' '); process.stdout.write(chalk[key](returnValue) + ' ');
} }

10
index.d.ts vendored
View file

@ -91,12 +91,10 @@ declare namespace chalk {
level?: Level; level?: Level;
} }
interface Instance { /**
/** Return a new Chalk instance.
Return a new Chalk instance. */
*/ type Instance = new (options?: Options) => Chalk;
new (options?: Options): Chalk;
}
/** /**
Detect whether the terminal supports color. Detect whether the terminal supports color.

View file

@ -6,16 +6,20 @@ type colorReturn = chalk.Chalk & {supportsColor?: never};
// - supportsColor - // - supportsColor -
expectType<chalk.ColorSupport | false>(chalk.supportsColor); expectType<chalk.ColorSupport | false>(chalk.supportsColor);
expectType<boolean>((chalk.supportsColor as chalk.ColorSupport).hasBasic); if (chalk.supportsColor) {
expectType<boolean>((chalk.supportsColor as chalk.ColorSupport).has256); expectType<boolean>(chalk.supportsColor.hasBasic);
expectType<boolean>((chalk.supportsColor as chalk.ColorSupport).has16m); expectType<boolean>(chalk.supportsColor.has256);
expectType<boolean>(chalk.supportsColor.has16m);
}
// - stderr - // - stderr -
expectType<chalk.Chalk>(chalk.stderr); expectType<chalk.Chalk>(chalk.stderr);
expectType<chalk.ColorSupport | false>(chalk.stderr.supportsColor); expectType<chalk.ColorSupport | false>(chalk.stderr.supportsColor);
expectType<boolean>((chalk.stderr.supportsColor as chalk.ColorSupport).hasBasic); if (chalk.stderr.supportsColor) {
expectType<boolean>((chalk.stderr.supportsColor as chalk.ColorSupport).has256); expectType<boolean>(chalk.stderr.supportsColor.hasBasic);
expectType<boolean>((chalk.stderr.supportsColor as chalk.ColorSupport).has16m); expectType<boolean>(chalk.stderr.supportsColor.has256);
expectType<boolean>(chalk.stderr.supportsColor.has16m);
}
// -- `stderr` is not a member of the Chalk interface -- // -- `stderr` is not a member of the Chalk interface --
expectError(chalk.reset.stderr); expectError(chalk.reset.stderr);

View file

@ -7,7 +7,7 @@
"funding": "https://github.com/chalk/chalk?sponsor=1", "funding": "https://github.com/chalk/chalk?sponsor=1",
"main": "source", "main": "source",
"engines": { "engines": {
"node": ">=8" "node": ">=10"
}, },
"scripts": { "scripts": {
"test": "xo && nyc ava && tsd", "test": "xo && nyc ava && tsd",
@ -47,18 +47,22 @@
"devDependencies": { "devDependencies": {
"ava": "^2.4.0", "ava": "^2.4.0",
"coveralls": "^3.0.7", "coveralls": "^3.0.7",
"execa": "^3.2.0", "execa": "^4.0.0",
"import-fresh": "^3.1.0", "import-fresh": "^3.1.0",
"matcha": "^0.7.0", "matcha": "^0.7.0",
"nyc": "^15.0.0", "nyc": "^15.0.0",
"resolve-from": "^5.0.0", "resolve-from": "^5.0.0",
"tsd": "^0.7.4", "tsd": "^0.7.4",
"xo": "^0.25.3" "xo": "^0.28.2"
}, },
"xo": { "xo": {
"rules": { "rules": {
"unicorn/prefer-string-slice": "off", "unicorn/prefer-string-slice": "off",
"unicorn/prefer-includes": "off" "unicorn/prefer-includes": "off",
"@typescript-eslint/member-ordering": "off",
"no-redeclare": "off",
"unicorn/string-content": "off",
"unicorn/better-regex": "off"
} }
} }
} }

View file

@ -17,7 +17,7 @@ const levelMapping = [
const styles = Object.create(null); const styles = Object.create(null);
const applyOptions = (object, options = {}) => { const applyOptions = (object, options = {}) => {
if (!Number.isInteger(options.level) || options.level > 3 || options.level < 0) { if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
throw new Error('The `level` option should be an integer from 0 to 3'); throw new Error('The `level` option should be an integer from 0 to 3');
} }
@ -28,6 +28,7 @@ const applyOptions = (object, options = {}) => {
class ChalkClass { class ChalkClass {
constructor(options) { constructor(options) {
// eslint-disable-next-line no-constructor-return
return chalkFactory(options); return chalkFactory(options);
} }
} }

View file

@ -2,7 +2,7 @@
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; 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;
const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g; const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/; const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|([^\\])/gi; const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi;
const ESCAPES = new Map([ const ESCAPES = new Map([
['n', '\n'], ['n', '\n'],
@ -126,8 +126,8 @@ module.exports = (chalk, temporary) => {
chunks.push(chunk.join('')); chunks.push(chunk.join(''));
if (styles.length > 0) { if (styles.length > 0) {
const errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`; const errMessage = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
throw new Error(errMsg); throw new Error(errMessage);
} }
return chunks.join(''); return chunks.join('');

View file

@ -121,8 +121,8 @@ test('correctly parse newline escapes (bug #177)', t => {
test('correctly parse escape in parameters (bug #177 comment 318622809)', t => { test('correctly parse escape in parameters (bug #177 comment 318622809)', t => {
const instance = new chalk.Instance({level: 0}); const instance = new chalk.Instance({level: 0});
const str = '\\'; const string = '\\';
t.is(instance`{blue ${str}}`, '\\'); t.is(instance`{blue ${string}}`, '\\');
}); });
test('correctly parses unicode/hex escapes', t => { test('correctly parses unicode/hex escapes', t => {