forked from orbit-oss/chalk
Require Node.js 10
This commit is contained in:
parent
f0f4638a92
commit
61999a4e77
8 changed files with 32 additions and 26 deletions
|
|
@ -2,6 +2,5 @@ language: node_js
|
|||
node_js:
|
||||
- '12'
|
||||
- '10'
|
||||
- '8'
|
||||
after_success:
|
||||
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'
|
||||
|
|
|
|||
|
|
@ -4,15 +4,15 @@ const chalk = require('..');
|
|||
|
||||
// Generates screenshot
|
||||
for (const key of Object.keys(styles)) {
|
||||
let ret = key;
|
||||
let returnValue = key;
|
||||
|
||||
if (key === 'reset' || key === 'hidden' || key === 'grey') {
|
||||
continue;
|
||||
}
|
||||
|
||||
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
10
index.d.ts
vendored
|
|
@ -91,12 +91,10 @@ declare namespace chalk {
|
|||
level?: Level;
|
||||
}
|
||||
|
||||
interface Instance {
|
||||
/**
|
||||
Return a new Chalk instance.
|
||||
*/
|
||||
new (options?: Options): Chalk;
|
||||
}
|
||||
/**
|
||||
Return a new Chalk instance.
|
||||
*/
|
||||
type Instance = new (options?: Options) => Chalk;
|
||||
|
||||
/**
|
||||
Detect whether the terminal supports color.
|
||||
|
|
|
|||
|
|
@ -6,16 +6,20 @@ type colorReturn = chalk.Chalk & {supportsColor?: never};
|
|||
|
||||
// - supportsColor -
|
||||
expectType<chalk.ColorSupport | false>(chalk.supportsColor);
|
||||
expectType<boolean>((chalk.supportsColor as chalk.ColorSupport).hasBasic);
|
||||
expectType<boolean>((chalk.supportsColor as chalk.ColorSupport).has256);
|
||||
expectType<boolean>((chalk.supportsColor as chalk.ColorSupport).has16m);
|
||||
if (chalk.supportsColor) {
|
||||
expectType<boolean>(chalk.supportsColor.hasBasic);
|
||||
expectType<boolean>(chalk.supportsColor.has256);
|
||||
expectType<boolean>(chalk.supportsColor.has16m);
|
||||
}
|
||||
|
||||
// - stderr -
|
||||
expectType<chalk.Chalk>(chalk.stderr);
|
||||
expectType<chalk.ColorSupport | false>(chalk.stderr.supportsColor);
|
||||
expectType<boolean>((chalk.stderr.supportsColor as chalk.ColorSupport).hasBasic);
|
||||
expectType<boolean>((chalk.stderr.supportsColor as chalk.ColorSupport).has256);
|
||||
expectType<boolean>((chalk.stderr.supportsColor as chalk.ColorSupport).has16m);
|
||||
if (chalk.stderr.supportsColor) {
|
||||
expectType<boolean>(chalk.stderr.supportsColor.hasBasic);
|
||||
expectType<boolean>(chalk.stderr.supportsColor.has256);
|
||||
expectType<boolean>(chalk.stderr.supportsColor.has16m);
|
||||
}
|
||||
|
||||
// -- `stderr` is not a member of the Chalk interface --
|
||||
expectError(chalk.reset.stderr);
|
||||
|
|
|
|||
12
package.json
12
package.json
|
|
@ -7,7 +7,7 @@
|
|||
"funding": "https://github.com/chalk/chalk?sponsor=1",
|
||||
"main": "source",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
"node": ">=10"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && nyc ava && tsd",
|
||||
|
|
@ -47,18 +47,22 @@
|
|||
"devDependencies": {
|
||||
"ava": "^2.4.0",
|
||||
"coveralls": "^3.0.7",
|
||||
"execa": "^3.2.0",
|
||||
"execa": "^4.0.0",
|
||||
"import-fresh": "^3.1.0",
|
||||
"matcha": "^0.7.0",
|
||||
"nyc": "^15.0.0",
|
||||
"resolve-from": "^5.0.0",
|
||||
"tsd": "^0.7.4",
|
||||
"xo": "^0.25.3"
|
||||
"xo": "^0.28.2"
|
||||
},
|
||||
"xo": {
|
||||
"rules": {
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ const levelMapping = [
|
|||
const styles = Object.create(null);
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
|
|
@ -28,6 +28,7 @@ const applyOptions = (object, options = {}) => {
|
|||
|
||||
class ChalkClass {
|
||||
constructor(options) {
|
||||
// eslint-disable-next-line no-constructor-return
|
||||
return chalkFactory(options);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
|
||||
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([
|
||||
['n', '\n'],
|
||||
|
|
@ -126,8 +126,8 @@ module.exports = (chalk, temporary) => {
|
|||
chunks.push(chunk.join(''));
|
||||
|
||||
if (styles.length > 0) {
|
||||
const errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
|
||||
throw new Error(errMsg);
|
||||
const errMessage = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
|
||||
throw new Error(errMessage);
|
||||
}
|
||||
|
||||
return chunks.join('');
|
||||
|
|
|
|||
|
|
@ -121,8 +121,8 @@ test('correctly parse newline escapes (bug #177)', t => {
|
|||
|
||||
test('correctly parse escape in parameters (bug #177 comment 318622809)', t => {
|
||||
const instance = new chalk.Instance({level: 0});
|
||||
const str = '\\';
|
||||
t.is(instance`{blue ${str}}`, '\\');
|
||||
const string = '\\';
|
||||
t.is(instance`{blue ${string}}`, '\\');
|
||||
});
|
||||
|
||||
test('correctly parses unicode/hex escapes', t => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue