extra tests, specific benchmark, example in readme
This commit is contained in:
parent
7d238e2ebb
commit
e5ea8df1e5
5 changed files with 26 additions and 2 deletions
12
benchmark.js
12
benchmark.js
|
|
@ -47,4 +47,16 @@ suite('chalk', () => {
|
||||||
bench('cached: 1 style nested non-intersecting', () => {
|
bench('cached: 1 style nested non-intersecting', () => {
|
||||||
chalkBgRed(blueStyledString);
|
chalkBgRed(blueStyledString);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
set('iterations', 10000);
|
||||||
|
|
||||||
|
bench('cached: 1 style template literal', () => {
|
||||||
|
// eslint-disable-next-line no-unused-expressions
|
||||||
|
chalkRed`the fox jumps over the lazy dog`;
|
||||||
|
});
|
||||||
|
|
||||||
|
bench('cached: nested styles template literal', () => {
|
||||||
|
// eslint-disable-next-line no-unused-expressions
|
||||||
|
chalkRed`the fox {bold jumps} over the {underline lazy} dog`;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,11 @@ expectType<string>(chalk.bgWhiteBright`foo`);
|
||||||
expectType<string>(chalk.red.bgGreen.underline('foo'));
|
expectType<string>(chalk.red.bgGreen.underline('foo'));
|
||||||
expectType<string>(chalk.underline.red.bgGreen('foo'));
|
expectType<string>(chalk.underline.red.bgGreen('foo'));
|
||||||
|
|
||||||
|
// -- Complex template literal --
|
||||||
|
expectType<string>(chalk.underline``);
|
||||||
|
expectType<string>(chalk.red.bgGreen.bold`Hello {italic.blue ${name}}`);
|
||||||
|
expectType<string>(chalk.strikethrough.cyanBright.bgBlack`Works with {reset {bold numbers}} {bold.red ${1}}`);
|
||||||
|
|
||||||
// -- Color types ==
|
// -- Color types ==
|
||||||
expectType<typeof chalk.Color>('red');
|
expectType<typeof chalk.Color>('red');
|
||||||
expectError<typeof chalk.Color>('hotpink');
|
expectError<typeof chalk.Color>('hotpink');
|
||||||
|
|
|
||||||
|
|
@ -215,10 +215,11 @@ console.log(chalk`
|
||||||
|
|
||||||
Blocks are delimited by an opening curly brace (`{`), a style, some content, and a closing curly brace (`}`).
|
Blocks are delimited by an opening curly brace (`{`), a style, some content, and a closing curly brace (`}`).
|
||||||
|
|
||||||
Template styles are chained exactly like normal Chalk styles. The following two statements are equivalent:
|
Template styles are chained exactly like normal Chalk styles. The following three statements are equivalent:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
console.log(chalk.bold.rgb(10, 100, 200)('Hello!'));
|
console.log(chalk.bold.rgb(10, 100, 200)('Hello!'));
|
||||||
|
console.log(chalk.bold.rgb(10, 100, 200)`Hello!`);
|
||||||
console.log(chalk`{bold.rgb(10,100,200) Hello!}`);
|
console.log(chalk`{bold.rgb(10,100,200) Hello!}`);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ const createStyler = (open, close, parent) => {
|
||||||
const createBuilder = (self, _styler, _isEmpty) => {
|
const createBuilder = (self, _styler, _isEmpty) => {
|
||||||
const builder = (...arguments_) => {
|
const builder = (...arguments_) => {
|
||||||
if (Array.isArray(arguments_[0])) {
|
if (Array.isArray(arguments_[0])) {
|
||||||
// Called as a template litteral, e.g. chalk.red`2 + 3 = {bold ${2+3}}`
|
// Called as a template literal, e.g. chalk.red`2 + 3 = {bold ${2+3}}`
|
||||||
return applyStyle(builder, chalkTag(builder, ...arguments_));
|
return applyStyle(builder, chalkTag(builder, ...arguments_));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,12 @@ test('correctly perform nested template substitutions', t => {
|
||||||
const exclamation = 'Neat';
|
const exclamation = 'Neat';
|
||||||
t.is(instance.bold`Hello, {cyan.inverse ${name}!} This is a` + ' test. ' + instance.green`${exclamation}!`,
|
t.is(instance.bold`Hello, {cyan.inverse ${name}!} This is a` + ' test. ' + instance.green`${exclamation}!`,
|
||||||
instance.bold('Hello,', instance.cyan.inverse(name + '!'), 'This is a') + ' test. ' + instance.green(exclamation + '!'));
|
instance.bold('Hello,', instance.cyan.inverse(name + '!'), 'This is a') + ' test. ' + instance.green(exclamation + '!'));
|
||||||
|
|
||||||
|
t.is(instance.red.bgGreen.bold`Hello {italic.blue ${name}}`,
|
||||||
|
instance.red.bgGreen.bold('Hello ' + instance.italic.blue(name)));
|
||||||
|
|
||||||
|
t.is(instance.strikethrough.cyanBright.bgBlack`Works with {reset {bold numbers}} {bold.red ${1}}`,
|
||||||
|
instance.strikethrough.cyanBright.bgBlack('Works with ' + instance.reset.bold('numbers') + ' ' + instance.bold.red(1)));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('correctly parse and evaluate color-convert functions', t => {
|
test('correctly parse and evaluate color-convert functions', t => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue