@hatterjiang/term-color-render 1.0.4 → 1.0.5

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.
Files changed (2) hide show
  1. package/README.md +73 -9
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,18 +1,82 @@
1
1
  # term color render
2
2
 
3
+ Render ANSI colors for the terminal using a simple tag syntax like `[red]text[/red]`.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install @hatterjiang/term-color-render
9
+ ```
10
+
11
+ ## Usage
12
+
3
13
  ```js
14
+ // ESM
4
15
  import { renderColor } from "@hatterjiang/term-color-render";
5
16
 
17
+ // CommonJS
18
+ const { renderColor } = require("@hatterjiang/term-color-render");
19
+
6
20
  console.log(renderColor('hello [red]red world[/red], [bold][green]bold and green text[/green][/bold]'));
7
21
  ```
8
22
 
23
+ The second argument optionally forces color on (`true`) or off (`false`):
24
+
25
+ ```js
26
+ renderColor("[red]hi[/red]", true); // "\x1b[31mhi\x1b[0m\x1b[0m"
27
+ renderColor("[red]hi[/red]", false); // "hi"
28
+ ```
29
+
30
+ When omitted, color is enabled automatically based on the environment.
31
+
32
+ ## Supported tags
33
+
34
+ Wrap text in a tag to start it and close with the matching `[/tag]`.
35
+
36
+ ```sh
37
+ [red]red text[/red]
38
+ [green]green text[/green]
39
+ [yellow]yellow text[/yellow]
40
+ [blue]blue text[/blue]
41
+ [pink]pink text[/pink]
42
+ [cyan]cyan text[/cyan]
43
+ [bold]bold text[/bold]
44
+ [under]underlined text[/under]
45
+ [blink]blinking text[/blink]
46
+ ```
47
+
48
+ Tags can be nested; closing an inner tag re-applies the outer one:
49
+
50
+ ```
51
+ [bold][green]bold and green text[/green][/bold]
52
+ ```
53
+
54
+ ## Escaping
55
+
56
+ Escape a bracket with a backslash to keep it as literal text:
57
+
58
+ ```
59
+ \[red\]hi → [red]hi
60
+ ```
61
+
62
+ ## Unknown and unclosed tags
63
+
64
+ Tags that are not in the list above are left as literal text, and unclosed tags are
65
+ preserved instead of being dropped:
66
+
67
+ ```
68
+ [foo]bar[/foo] → [foo]bar[/foo]
69
+ [red → [red
70
+ ```
71
+
72
+ ## Color detection
73
+
74
+ When the second argument is omitted, color is controlled by the environment:
75
+
76
+ - `FORCE_COLOR` — if set, color is enabled unless its value is `"0"`.
77
+ - `NO_COLOR` — if set, color is disabled.
78
+ - Otherwise, color is enabled only when both `stdout` and `stderr` are TTYs.
79
+
80
+ ## TypeScript
9
81
 
10
- Supported colors:
11
- - `[red]red text[/red]`
12
- - `[blue]blue text[/blue]`
13
- - `[green]green text[/green]`
14
- - `[yellow]yellow text[/yellow]`
15
- - `[cyan]cyan text[/cyan]`
16
- - `[pink]cyan text[/pink]`
17
- - `[bold]bold text[/bold]`
18
- - `[under]under text[/under]`
82
+ Type definitions are included and resolved automatically.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatterjiang/term-color-render",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Render color for term use syntax like [red]text[/red]",
5
5
  "license": "MIT",
6
6
  "author": "Hatter Jiang",