chalk 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -137,6 +137,13 @@ declare namespace chalk {
137
137
  DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%}
138
138
  `);
139
139
  ```
140
+
141
+ @example
142
+ ```
143
+ import chalk = require('chalk');
144
+
145
+ log(chalk.red.bgBlack`2 + 3 = {bold ${2 + 3}}`)
146
+ ```
140
147
  */
141
148
  (text: TemplateStringsArray, ...placeholders: unknown[]): string;
142
149
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chalk",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "Terminal string styling done right",
5
5
  "license": "MIT",
6
6
  "repository": "chalk/chalk",
package/readme.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  > Terminal string styling done right
11
11
 
12
- [![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) [![npm dependents](https://badgen.net/npm/dependents/chalk)](https://www.npmjs.com/package/chalk?activeTab=dependents) [![Downloads](https://badgen.net/npm/dt/chalk)](https://www.npmjs.com/package/chalk) [![](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/xojs/xo) ![TypeScript-ready](https://img.shields.io/npm/types/chalk.svg) [![run on repl.it](http://repl.it/badge/github/chalk/chalk)](https://repl.it/github/chalk/chalk)
12
+ [![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) [![npm dependents](https://badgen.net/npm/dependents/chalk)](https://www.npmjs.com/package/chalk?activeTab=dependents) [![Downloads](https://badgen.net/npm/dt/chalk)](https://www.npmjs.com/package/chalk) [![](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/xojs/xo) ![TypeScript-ready](https://img.shields.io/npm/types/chalk.svg) [![run on repl.it](https://repl.it/badge/github/chalk/chalk)](https://repl.it/github/chalk/chalk)
13
13
 
14
14
  <img src="https://cdn.jsdelivr.net/gh/chalk/ansi-styles@8261697c95bf34b6c7767e2cbe9941a851d59385/screenshot.svg" width="900">
15
15
 
@@ -199,7 +199,7 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=
199
199
 
200
200
  ## Tagged template literal
201
201
 
202
- Chalk can be used as a [tagged template literal](http://exploringjs.com/es6/ch_template-literals.html#_tagged-template-literals).
202
+ Chalk can be used as a [tagged template literal](https://exploringjs.com/es6/ch_template-literals.html#_tagged-template-literals).
203
203
 
204
204
  ```js
205
205
  const chalk = require('chalk');
@@ -215,10 +215,11 @@ console.log(chalk`
215
215
 
216
216
  Blocks are delimited by an opening curly brace (`{`), a style, some content, and a closing curly brace (`}`).
217
217
 
218
- Template styles are chained exactly like normal Chalk styles. The following two statements are equivalent:
218
+ Template styles are chained exactly like normal Chalk styles. The following three statements are equivalent:
219
219
 
220
220
  ```js
221
221
  console.log(chalk.bold.rgb(10, 100, 200)('Hello!'));
222
+ console.log(chalk.bold.rgb(10, 100, 200)`Hello!`);
222
223
  console.log(chalk`{bold.rgb(10,100,200) Hello!}`);
223
224
  ```
224
225
 
package/source/index.js CHANGED
@@ -6,6 +6,8 @@ const {
6
6
  stringEncaseCRLFWithFirstIndex
7
7
  } = require('./util');
8
8
 
9
+ const {isArray} = Array;
10
+
9
11
  // `supportsColor.level` → `ansiStyles.color[name]` mapping
10
12
  const levelMapping = [
11
13
  'ansi',
@@ -135,6 +137,11 @@ const createStyler = (open, close, parent) => {
135
137
 
136
138
  const createBuilder = (self, _styler, _isEmpty) => {
137
139
  const builder = (...arguments_) => {
140
+ if (isArray(arguments_[0]) && isArray(arguments_[0].raw)) {
141
+ // Called as a template literal, for example: chalk.red`2 + 3 = {bold ${2+3}}`
142
+ return applyStyle(builder, chalkTag(builder, ...arguments_));
143
+ }
144
+
138
145
  // Single argument is hot path, implicit coercion is faster than anything
139
146
  // eslint-disable-next-line no-implicit-coercion
140
147
  return applyStyle(builder, (arguments_.length === 1) ? ('' + arguments_[0]) : arguments_.join(' '));
@@ -189,7 +196,7 @@ let template;
189
196
  const chalkTag = (chalk, ...strings) => {
190
197
  const [firstString] = strings;
191
198
 
192
- if (!Array.isArray(firstString)) {
199
+ if (!isArray(firstString) || !isArray(firstString.raw)) {
193
200
  // If chalk() was called by itself or with a string,
194
201
  // return the string itself as a string.
195
202
  return strings.join(' ');