Skip to content

Commit cb348f6

Browse files
committed
docs: add base color samples to readme
1 parent 8216d18 commit cb348f6

18 files changed

+21
-20
lines changed

README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Both are [recommended](https://github.com/es-tooling/module-replacements/blob/ma
105105
The package size in `node_modules` directory:
106106

107107
- `picocolors`: [6.37 kB][npm-picocolors] (not minimized) - A micro library with basic features.
108-
- `аnsis`: [5.92 kB][npm-ansis] (minimized) - A powerful library with a rich set of features.
108+
- `аnsis`: [5.87 kB][npm-ansis] (minimized) - A powerful library with a rich set of features.
109109
- `chalk`: [44.2 kB][npm-chalk] (not minimized) - Provides similar functionality to Ansis.
110110

111111
### ⚡ Performance
@@ -115,7 +115,7 @@ The package size in `node_modules` directory:
115115
- `chalk`: Slower than both **Ansis** and **Picocolors** in all use cases.
116116

117117
> [!CAUTION]
118-
> **Picocolors** doesn't handle important **edge cases**, so it is the fastest and smallest.
118+
> **Picocolors** doesn't handle important **edge cases**, so it is the fastest.
119119
>
120120
> **Picocolors** is faster only in a [simple](#bench-simple) micro-benchmark, which does not reflect real world usage.\
121121
> In a more complex benchmark, **Ansis** is much [closer](#bench-picocolors-complex) to **Picocolors** results or even [faster](#bench-3-styles).
@@ -214,7 +214,7 @@ As of 2025, only **Ansis**, **Chalk**, and **Picocolors** are actively maintaine
214214
- ☑️ Picocolors: `CJS` only
215215
- ☑️ Chalk: `ESM` only
216216
- Does it matter the unpacked size?
217-
-[Ansis - 5.92 kB][npm-ansis]
217+
-[Ansis - 5.87 kB][npm-ansis]
218218
-[Picocolors - 6.37 kB][npm-picocolors]
219219
-[Chalk - 44.2 kB][npm-chalk]
220220
- Does it matter if a library performs [~60 million](#bench-simple) or [~100 million](#bench-simple) **ops/sec** when outputting to the terminal?
@@ -374,16 +374,18 @@ italic.bold.yellow.bgMagentaBright`text`;
374374

375375
## ANSI 16 colors
376376

377-
| Standard Colors | Bright Colors | Standard Backgrounds | Bright Backgrounds |
378-
|:-----------------|:----------------|:---------------------|:-------------------|
379-
| `black` | `gray` | `bgBlack` | `bgGray` |
380-
| `red` | `redBright` | `bgRed` | `bgRedBright` |
381-
| `green` | `greenBright` | `bgGreen` | `bgGreenBright` |
382-
| `yellow` | `yellowBright` | `bgYellow` | `bgYellowBright` |
383-
| `blue` | `blueBright` | `bgBlue` | `bgBlueBright` |
384-
| `magenta` | `magentaBright` | `bgMagenta` | `bgMagentaBright` |
385-
| `cyan` | `cyanBright` | `bgCyan` | `bgCyanBright` |
386-
| `white` | `whiteBright` | `bgWhite` | `bgWhiteBright` |
377+
There are 16 basic colors: 8 standard and 8 bright variants.
378+
379+
| Example | Color | Background | Bright Example | Bright Color | Bright Background |
380+
|:---------------------------------:|:---------------|:--------------------|:---------------------------------------:|:----------------|:------------------|
381+
| ![](docs/img/colors/black.png) | `black` | `bgBlack` | ![](docs/img/colors/gray.png) | `gray` | `bgGray` |
382+
| ![](docs/img/colors/red.png) | `red` | `bgRed` | ![](docs/img/colors/redBright.png) | `redBright` | `bgRedBright` |
383+
| ![](docs/img/colors/green.png) | `green` | `bgGreen` | ![](docs/img/colors/greenBright.png) | `greenBright` | `bgGreenBright` |
384+
| ![](docs/img/colors/yellow.png) | `yellow` | `bgYellow` | ![](docs/img/colors/yellowBright.png) | `yellowBright` | `bgYellowBright` |
385+
| ![](docs/img/colors/blue.png) | `blue` | `bgBlue` | ![](docs/img/colors/blueBright.png) | `blueBright` | `bgBlueBright` |
386+
| ![](docs/img/colors/magenta.png) | `magenta` | `bgMagenta` | ![](docs/img/colors/magentaBright.png) | `magentaBright` | `bgMagentaBright` |
387+
| ![](docs/img/colors/cyan.png) | `cyan` | `bgCyan` | ![](docs/img/colors/cyanBright.png) | `cyanBright` | `bgCyanBright` |
388+
| ![](docs/img/colors/white.png) | `white` | `bgWhite` | ![](docs/img/colors/whiteBright.png) | `whiteBright` | `bgWhiteBright` |
387389

388390

389391
<a name="gray-naming-in-libs"></a>
@@ -1156,7 +1158,7 @@ c.red(1/0) // 'Infinity' in red
11561158

11571159
| Package | Dependencies | Minified | Unpacked Size | Tarball size |
11581160
|:-----------------------------|:------------------------------:|------------------|---------------------------------------------------------:|-----------------------------------------------------------------------:|
1159-
| [`ansis`][ansis] | [0][npm-ansis] | uglified & minified | [5.92 kB][npm-ansis] | [3.5 kB](https://arve0.github.io/npm-download-size/#ansis) |
1161+
| [`ansis`][ansis] | [0][npm-ansis] | uglified & minified | [5.87 kB][npm-ansis] | [3.5 kB](https://arve0.github.io/npm-download-size/#ansis) |
11601162
| [`picocolors`][picocolors] | [0][npm-picocolors] | no | [6.37 kB][npm-picocolors] | [2.6 kB](https://arve0.github.io/npm-download-size/#picocolors) |
11611163
| [`tinyrainbow`][tinyrainbow] | [0][npm-tinyrainbow] | uglified | [8.1 kB][npm-tinyrainbow] | [3.2 kB](https://arve0.github.io/npm-download-size/#tinyrainbow) |
11621164
| [`colorette`][colorette] | [0][npm-colorette] | no | [17.0 kB][npm-colorette] | [4.9 kB](https://arve0.github.io/npm-download-size/#colorette) |

docs/img/colors/black.png

110 Bytes
Loading

docs/img/colors/blue.png

83 Bytes
Loading

docs/img/colors/blueBright.png

83 Bytes
Loading

docs/img/colors/cyan.png

83 Bytes
Loading

docs/img/colors/cyanBright.png

83 Bytes
Loading

docs/img/colors/gray.png

83 Bytes
Loading

docs/img/colors/green.png

83 Bytes
Loading

docs/img/colors/greenBright.png

83 Bytes
Loading

docs/img/colors/magenta.png

83 Bytes
Loading

docs/img/colors/magentaBright.png

83 Bytes
Loading

docs/img/colors/red.png

83 Bytes
Loading

docs/img/colors/redBright.png

83 Bytes
Loading

docs/img/colors/white.png

83 Bytes
Loading

docs/img/colors/whiteBright.png

83 Bytes
Loading

docs/img/colors/yellow.png

83 Bytes
Loading

docs/img/colors/yellowBright.png

83 Bytes
Loading

src/index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ let createStyle = ({ p: props }, { open, close }) => {
3838
let styleFn = (arg, ...values) => {
3939
// If the argument is empty or null, return an empty string
4040
if (!arg) {
41+
// reset
4142
if (open && open === close) return open;
4243
// null == arg || '' === arg
4344
if ((arg ?? EMPTY_STRING) === EMPTY_STRING) return EMPTY_STRING;
@@ -78,12 +79,10 @@ let createStyle = ({ p: props }, { open, close }) => {
7879
}
7980
}
8081

81-
// Detect new line
82-
if (output.includes(LF)) {
83-
output = output.replace(/(\r?\n)/g, closeStack + '$1' + openStack);
84-
}
85-
86-
return openStack + output + closeStack;
82+
return openStack
83+
// Detect new line
84+
+ (output.includes(LF) ? output.replace(/(\r?\n)/g, closeStack + '$1' + openStack) : output)
85+
+ closeStack;
8786
};
8887

8988
let openStack = open;

0 commit comments

Comments
 (0)