[Pkg-javascript-commits] [node-chalk] 01/03: New upstream version 2.3.0

Praveen Arimbrathodiyil praveen at moszumanska.debian.org
Mon Oct 30 18:08:18 UTC 2017


This is an automated email from the git hooks/post-receive script.

praveen pushed a commit to branch master
in repository node-chalk.

commit 8562f1c9a1f9a66666b05ea6da8a8ed309526eb3
Author: Pirate Praveen <praveen at debian.org>
Date:   Mon Oct 30 13:17:57 2017 +0530

    New upstream version 2.3.0
---
 index.js            | 18 +++++++---
 package.json        | 15 +++++----
 readme.md           |  5 ++-
 templates.js        | 32 +++++++++---------
 test/visible.js     | 47 ++++++++++++++++++++++++++
 types/index.d.ts    | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 types/test.ts       | 56 +++++++++++++++++++++++++++++++
 types/tsconfig.json |  9 +++++
 8 files changed, 251 insertions(+), 28 deletions(-)

diff --git a/index.js b/index.js
index 4c81d6d..05e62b3 100644
--- a/index.js
+++ b/index.js
@@ -58,11 +58,17 @@ for (const key of Object.keys(ansiStyles)) {
 	styles[key] = {
 		get() {
 			const codes = ansiStyles[key];
-			return build.call(this, this._styles ? this._styles.concat(codes) : [codes], key);
+			return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
 		}
 	};
 }
 
+styles.visible = {
+	get() {
+		return build.call(this, this._styles || [], true, 'visible');
+	}
+};
+
 ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
 for (const model of Object.keys(ansiStyles.color.ansi)) {
 	if (skipModels.has(model)) {
@@ -79,7 +85,7 @@ for (const model of Object.keys(ansiStyles.color.ansi)) {
 					close: ansiStyles.color.close,
 					closeRe: ansiStyles.color.closeRe
 				};
-				return build.call(this, this._styles ? this._styles.concat(codes) : [codes], model);
+				return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
 			};
 		}
 	};
@@ -102,7 +108,7 @@ for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
 					close: ansiStyles.bgColor.close,
 					closeRe: ansiStyles.bgColor.closeRe
 				};
-				return build.call(this, this._styles ? this._styles.concat(codes) : [codes], model);
+				return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
 			};
 		}
 	};
@@ -110,12 +116,13 @@ for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
 
 const proto = Object.defineProperties(() => {}, styles);
 
-function build(_styles, key) {
+function build(_styles, _empty, key) {
 	const builder = function () {
 		return applyStyle.apply(builder, arguments);
 	};
 
 	builder._styles = _styles;
+	builder._empty = _empty;
 
 	const self = this;
 
@@ -167,7 +174,7 @@ function applyStyle() {
 	}
 
 	if (!this.enabled || this.level <= 0 || !str) {
-		return str;
+		return this._empty ? '' : str;
 	}
 
 	// Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
@@ -218,3 +225,4 @@ Object.defineProperties(Chalk.prototype, styles);
 
 module.exports = Chalk(); // eslint-disable-line new-cap
 module.exports.supportsColor = supportsColor;
+module.exports.default = module.exports; // For TypeScript
diff --git a/package.json b/package.json
index a257127..69889f0 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
 	"name": "chalk",
-	"version": "2.1.0",
+	"version": "2.3.0",
 	"description": "Terminal string styling done right",
 	"license": "MIT",
 	"repository": "chalk/chalk",
@@ -8,13 +8,14 @@
 		"node": ">=4"
 	},
 	"scripts": {
-		"test": "xo && nyc ava",
+		"test": "xo && tsc --project types && nyc ava",
 		"bench": "matcha benchmark.js",
 		"coveralls": "nyc report --reporter=text-lcov | coveralls"
 	},
 	"files": [
 		"index.js",
-		"templates.js"
+		"templates.js",
+		"types/index.d.ts"
 	],
 	"keywords": [
 		"color",
@@ -46,14 +47,16 @@
 	},
 	"devDependencies": {
 		"ava": "*",
-		"coveralls": "^2.11.2",
-		"execa": "^0.7.0",
+		"coveralls": "^3.0.0",
+		"execa": "^0.8.0",
 		"import-fresh": "^2.0.0",
 		"matcha": "^0.7.0",
 		"nyc": "^11.0.2",
-		"resolve-from": "^3.0.0",
+		"resolve-from": "^4.0.0",
+		"typescript": "^2.5.3",
 		"xo": "*"
 	},
+	"types": "types/index.d.ts",
 	"xo": {
 		"envs": [
 			"node",
diff --git a/readme.md b/readme.md
index dfcfdf2..9bb2e65 100644
--- a/readme.md
+++ b/readme.md
@@ -9,7 +9,7 @@
 
 > Terminal string styling done right
 
-[![Build Status](https://travis-ci.org/chalk/chalk.svg?branch=master)](https://travis-ci.org/chalk/chalk) [![Coverage Status](https://coveralls.io/repos/github/chalk/chalk/badge.svg?branch=master)](https://coveralls.io/github/chalk/chalk?branch=master) [![](https://img.shields.io/badge/unicorn-approved-ff69b4.svg)](https://www.youtube.com/watch?v=9auOCbH5Ns4) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)
+[![Build Status](https://travis-ci.org/chalk/chalk.svg?branch=master)](https://travis-ci.org/chalk/chalk) [![Coverage Status](https://coveralls.io/repos/github/chalk/chalk/badge.svg?branch=master)](https://coveralls.io/github/chalk/chalk?branch=master) [![](https://img.shields.io/badge/unicorn-approved-ff69b4.svg)](https://www.youtube.com/watch?v=9auOCbH5Ns4) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo) [![Mentioned in Awes [...]
 
 ### [See what's new in Chalk 2](https://github.com/chalk/chalk/releases/tag/v2.0.0)
 
@@ -170,6 +170,7 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=
 - `inverse`
 - `hidden`
 - `strikethrough` *(Not widely supported)*
+- `visible` (Text is emitted only if enabled)
 
 ### Colors
 
@@ -286,6 +287,7 @@ If you're on Windows, do yourself a favor and use [`cmder`](http://cmder.net/) i
 - [ansi-styles](https://github.com/chalk/ansi-styles) - ANSI escape codes for styling strings in the terminal
 - [supports-color](https://github.com/chalk/supports-color) - Detect whether a terminal supports color
 - [strip-ansi](https://github.com/chalk/strip-ansi) - Strip ANSI escape codes
+- [strip-ansi-stream](https://github.com/chalk/strip-ansi-stream) - Strip ANSI escape codes from a stream
 - [has-ansi](https://github.com/chalk/has-ansi) - Check if a string has ANSI escape codes
 - [ansi-regex](https://github.com/chalk/ansi-regex) - Regular expression for matching ANSI escape codes
 - [wrap-ansi](https://github.com/chalk/wrap-ansi) - Wordwrap a string with ANSI escape codes
@@ -293,6 +295,7 @@ 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
 - [chalk-animation](https://github.com/bokub/chalk-animation) - Animate strings in the terminal
 - [gradient-string](https://github.com/bokub/gradient-string) - Apply color gradients to strings
+- [chalk-pipe](https://github.com/LitoMore/chalk-pipe) - Create chalk style schemes with simpler style strings
 
 
 ## Maintainers
diff --git a/templates.js b/templates.js
index 1015515..dbdf9b2 100644
--- a/templates.js
+++ b/templates.js
@@ -1,28 +1,28 @@
 'use strict';
-const TEMPLATE_REGEX = /(?:\\(u[a-f0-9]{4}|x[a-f0-9]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
+const TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|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[0-9a-f]{4}|x[0-9a-f]{2}|.)|([^\\])/gi;
-
-const ESCAPES = {
-	n: '\n',
-	r: '\r',
-	t: '\t',
-	b: '\b',
-	f: '\f',
-	v: '\v',
-	0: '\0',
-	'\\': '\\',
-	e: '\u001b',
-	a: '\u0007'
-};
+const ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
+
+const ESCAPES = new Map([
+	['n', '\n'],
+	['r', '\r'],
+	['t', '\t'],
+	['b', '\b'],
+	['f', '\f'],
+	['v', '\v'],
+	['0', '\0'],
+	['\\', '\\'],
+	['e', '\u001B'],
+	['a', '\u0007']
+]);
 
 function unescape(c) {
 	if ((c[0] === 'u' && c.length === 5) || (c[0] === 'x' && c.length === 3)) {
 		return String.fromCharCode(parseInt(c.slice(1), 16));
 	}
 
-	return ESCAPES[c] || c;
+	return ESCAPES.get(c) || c;
 }
 
 function parseArguments(name, args) {
diff --git a/test/visible.js b/test/visible.js
new file mode 100644
index 0000000..5d53bce
--- /dev/null
+++ b/test/visible.js
@@ -0,0 +1,47 @@
+import test from 'ava';
+
+// Spoof supports-color
+require('./_supports-color')(__dirname);
+
+const m = require('..');
+
+test('visible: normal output when enabled', t => {
+	const ctx = new m.constructor({level: 3, enabled: true});
+	t.is(ctx.visible.red('foo'), '\u001B[31mfoo\u001B[39m');
+	t.is(ctx.red.visible('foo'), '\u001B[31mfoo\u001B[39m');
+});
+
+test('visible: no output when disabled', t => {
+	const ctx = new m.constructor({level: 3, enabled: false});
+	t.is(ctx.red.visible('foo'), '');
+	t.is(ctx.visible.red('foo'), '');
+});
+
+test('visible: no output when level is too low', t => {
+	const ctx = new m.constructor({level: 0, enabled: true});
+	t.is(ctx.visible.red('foo'), '');
+	t.is(ctx.red.visible('foo'), '');
+});
+
+test('test switching back and forth between enabled and disabled', t => {
+	const ctx = new m.constructor({level: 3, enabled: true});
+	t.is(ctx.red('foo'), '\u001B[31mfoo\u001B[39m');
+	t.is(ctx.visible.red('foo'), '\u001B[31mfoo\u001B[39m');
+	t.is(ctx.red.visible('foo'), '\u001B[31mfoo\u001B[39m');
+	t.is(ctx.visible('foo'), 'foo');
+	t.is(ctx.red('foo'), '\u001B[31mfoo\u001B[39m');
+
+	ctx.enabled = false;
+	t.is(ctx.red('foo'), 'foo');
+	t.is(ctx.visible('foo'), '');
+	t.is(ctx.visible.red('foo'), '');
+	t.is(ctx.red.visible('foo'), '');
+	t.is(ctx.red('foo'), 'foo');
+
+	ctx.enabled = true;
+	t.is(ctx.red('foo'), '\u001B[31mfoo\u001B[39m');
+	t.is(ctx.visible.red('foo'), '\u001B[31mfoo\u001B[39m');
+	t.is(ctx.red.visible('foo'), '\u001B[31mfoo\u001B[39m');
+	t.is(ctx.visible('foo'), 'foo');
+	t.is(ctx.red('foo'), '\u001B[31mfoo\u001B[39m');
+});
diff --git a/types/index.d.ts b/types/index.d.ts
new file mode 100644
index 0000000..b4e4dc5
--- /dev/null
+++ b/types/index.d.ts
@@ -0,0 +1,97 @@
+// Type definitions for Chalk
+// Definitions by: Thomas Sauer <https://github.com/t-sauer>
+
+export const enum Level {
+	None = 0,
+	Basic = 1,
+	Ansi256 = 2,
+	TrueColor = 3
+}
+
+export interface ChalkOptions {
+	enabled?: boolean;
+	level?: Level;
+}
+
+export interface ChalkConstructor {
+	new (options?: ChalkOptions): Chalk;
+	(options?: ChalkOptions): Chalk;
+}
+
+export interface ColorSupport {
+	level: Level;
+	hasBasic: boolean;
+	has256: boolean;
+	has16m: boolean;
+}
+
+export interface Chalk {
+	(...text: string[]): string;
+	(text: TemplateStringsArray, ...placeholders: string[]): string;
+	constructor: ChalkConstructor;
+	enabled: boolean;
+	level: Level;
+	rgb(r: number, g: number, b: number): this;
+	hsl(h: number, s: number, l: number): this;
+	hsv(h: number, s: number, v: number): this;
+	hwb(h: number, w: number, b: number): this;
+	bgHex(color: string): this;
+	bgKeyword(color: string): this;
+	bgRgb(r: number, g: number, b: number): this;
+	bgHsl(h: number, s: number, l: number): this;
+	bgHsv(h: number, s: number, v: number): this;
+	bgHwb(h: number, w: number, b: number): this;
+	hex(color: string): this;
+	keyword(color: string): this;
+
+	readonly reset: this;
+	readonly bold: this;
+	readonly dim: this;
+	readonly italic: this;
+	readonly underline: this;
+	readonly inverse: this;
+	readonly hidden: this;
+	readonly strikethrough: this;
+
+	readonly visible: this;
+
+	readonly black: this;
+	readonly red: this;
+	readonly green: this;
+	readonly yellow: this;
+	readonly blue: this;
+	readonly magenta: this;
+	readonly cyan: this;
+	readonly white: this;
+	readonly gray: this;
+	readonly grey: this;
+	readonly blackBright: this;
+	readonly redBright: this;
+	readonly greenBright: this;
+	readonly yellowBright: this;
+	readonly blueBright: this;
+	readonly magentaBright: this;
+	readonly cyanBright: this;
+	readonly whiteBright: this;
+
+	readonly bgBlack: this;
+	readonly bgRed: this;
+	readonly bgGreen: this;
+	readonly bgYellow: this;
+	readonly bgBlue: this;
+	readonly bgMagenta: this;
+	readonly bgCyan: this;
+	readonly bgWhite: this;
+	readonly bgBlackBright: this;
+	readonly bgRedBright: this;
+	readonly bgGreenBright: this;
+	readonly bgYellowBright: this;
+	readonly bgBlueBright: this;
+	readonly bgMagentaBright: this;
+	readonly bgCyanBright: this;
+	readonly bgWhiteBright: this;
+}
+
+declare const chalk: Chalk & { supportsColor: ColorSupport };
+
+export default chalk
diff --git a/types/test.ts b/types/test.ts
new file mode 100644
index 0000000..cedb39a
--- /dev/null
+++ b/types/test.ts
@@ -0,0 +1,56 @@
+import chalk, {Level} from '..';
+
+chalk.underline('foo');
+chalk.red('foo');
+chalk.bgRed('foo');
+
+const name = 'Josh';
+chalk`Hello {bold.red ${name}}`;
+
+chalk.red`foo`;
+chalk.underline`foo`;
+chalk`foo`;
+
+chalk.red.bgGreen.underline('foo');
+chalk.underline.red.bgGreen('foo');
+
+chalk.grey('foo');
+
+chalk.constructor({level: 1});
+const ctx = chalk.constructor({level: Level.TrueColor });
+ctx('foo');
+ctx.red('foo');
+ctx`foo`;
+
+chalk.enabled = true;
+chalk.level = 1;
+chalk.level = Level.Ansi256;
+
+chalk.level === Level.Ansi256;
+
+let chalkInstance = new chalk.constructor();
+chalkInstance = chalk.constructor();
+
+chalkInstance.blue('foo');
+chalkInstance`foo`;
+
+let x = 'imastring';
+x = chalk();
+
+chalk.enabled;
+chalk.level;
+chalk.supportsColor.level;
+chalk.supportsColor.has16m;
+chalk.supportsColor.has256;
+chalk.supportsColor.hasBasic;
+
+chalk.keyword('orange').bgBlue('foo');
+chalk.hex('#123456').bgBlue('foo');
+chalk.rgb(1, 14, 9).bgBlue('foo');
+chalk.hsl(1, 14, 9).bgBlue('foo');
+chalk.hsv(1, 14, 9).bgBlue('foo');
+chalk.hwb(1, 14, 9).bgBlue('foo');
+
+chalk.visible('foo');
+chalk.red.visible('foo');
+chalk.visible.red('foo');
diff --git a/types/tsconfig.json b/types/tsconfig.json
new file mode 100644
index 0000000..b73840f
--- /dev/null
+++ b/types/tsconfig.json
@@ -0,0 +1,9 @@
+{
+	"compilerOptions": {
+		"module": "commonjs",
+		"target": "es6",
+		"noImplicitAny": true,
+		"noEmit": true,
+		"allowJs": true
+	}
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-chalk.git



More information about the Pkg-javascript-commits mailing list