Skip to content

Commit 9150f61

Browse files
Remove support for hsv, hwb, ansi and css keyword colors and add .rgbToAnsi256(), .hexToRgb() and .hexToAnsi256() (#65)
Co-authored-by: Sindre Sorhus <[email protected]>
1 parent 2d02d5b commit 9150f61

File tree

7 files changed

+103
-367
lines changed

7 files changed

+103
-367
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ language: node_js
22
node_js:
33
- '12'
44
- '10'
5-
- '8'

index.d.ts

Lines changed: 29 additions & 214 deletions
Original file line numberDiff line numberDiff line change
@@ -1,214 +1,4 @@
1-
declare type CSSColor =
2-
| 'aliceblue'
3-
| 'antiquewhite'
4-
| 'aqua'
5-
| 'aquamarine'
6-
| 'azure'
7-
| 'beige'
8-
| 'bisque'
9-
| 'black'
10-
| 'blanchedalmond'
11-
| 'blue'
12-
| 'blueviolet'
13-
| 'brown'
14-
| 'burlywood'
15-
| 'cadetblue'
16-
| 'chartreuse'
17-
| 'chocolate'
18-
| 'coral'
19-
| 'cornflowerblue'
20-
| 'cornsilk'
21-
| 'crimson'
22-
| 'cyan'
23-
| 'darkblue'
24-
| 'darkcyan'
25-
| 'darkgoldenrod'
26-
| 'darkgray'
27-
| 'darkgreen'
28-
| 'darkgrey'
29-
| 'darkkhaki'
30-
| 'darkmagenta'
31-
| 'darkolivegreen'
32-
| 'darkorange'
33-
| 'darkorchid'
34-
| 'darkred'
35-
| 'darksalmon'
36-
| 'darkseagreen'
37-
| 'darkslateblue'
38-
| 'darkslategray'
39-
| 'darkslategrey'
40-
| 'darkturquoise'
41-
| 'darkviolet'
42-
| 'deeppink'
43-
| 'deepskyblue'
44-
| 'dimgray'
45-
| 'dimgrey'
46-
| 'dodgerblue'
47-
| 'firebrick'
48-
| 'floralwhite'
49-
| 'forestgreen'
50-
| 'fuchsia'
51-
| 'gainsboro'
52-
| 'ghostwhite'
53-
| 'gold'
54-
| 'goldenrod'
55-
| 'gray'
56-
| 'green'
57-
| 'greenyellow'
58-
| 'grey'
59-
| 'honeydew'
60-
| 'hotpink'
61-
| 'indianred'
62-
| 'indigo'
63-
| 'ivory'
64-
| 'khaki'
65-
| 'lavender'
66-
| 'lavenderblush'
67-
| 'lawngreen'
68-
| 'lemonchiffon'
69-
| 'lightblue'
70-
| 'lightcoral'
71-
| 'lightcyan'
72-
| 'lightgoldenrodyellow'
73-
| 'lightgray'
74-
| 'lightgreen'
75-
| 'lightgrey'
76-
| 'lightpink'
77-
| 'lightsalmon'
78-
| 'lightseagreen'
79-
| 'lightskyblue'
80-
| 'lightslategray'
81-
| 'lightslategrey'
82-
| 'lightsteelblue'
83-
| 'lightyellow'
84-
| 'lime'
85-
| 'limegreen'
86-
| 'linen'
87-
| 'magenta'
88-
| 'maroon'
89-
| 'mediumaquamarine'
90-
| 'mediumblue'
91-
| 'mediumorchid'
92-
| 'mediumpurple'
93-
| 'mediumseagreen'
94-
| 'mediumslateblue'
95-
| 'mediumspringgreen'
96-
| 'mediumturquoise'
97-
| 'mediumvioletred'
98-
| 'midnightblue'
99-
| 'mintcream'
100-
| 'mistyrose'
101-
| 'moccasin'
102-
| 'navajowhite'
103-
| 'navy'
104-
| 'oldlace'
105-
| 'olive'
106-
| 'olivedrab'
107-
| 'orange'
108-
| 'orangered'
109-
| 'orchid'
110-
| 'palegoldenrod'
111-
| 'palegreen'
112-
| 'paleturquoise'
113-
| 'palevioletred'
114-
| 'papayawhip'
115-
| 'peachpuff'
116-
| 'peru'
117-
| 'pink'
118-
| 'plum'
119-
| 'powderblue'
120-
| 'purple'
121-
| 'rebeccapurple'
122-
| 'red'
123-
| 'rosybrown'
124-
| 'royalblue'
125-
| 'saddlebrown'
126-
| 'salmon'
127-
| 'sandybrown'
128-
| 'seagreen'
129-
| 'seashell'
130-
| 'sienna'
131-
| 'silver'
132-
| 'skyblue'
133-
| 'slateblue'
134-
| 'slategray'
135-
| 'slategrey'
136-
| 'snow'
137-
| 'springgreen'
138-
| 'steelblue'
139-
| 'tan'
140-
| 'teal'
141-
| 'thistle'
142-
| 'tomato'
143-
| 'turquoise'
144-
| 'violet'
145-
| 'wheat'
146-
| 'white'
147-
| 'whitesmoke'
148-
| 'yellow'
149-
| 'yellowgreen';
150-
1511
declare namespace ansiStyles {
152-
interface ColorConvert {
153-
/**
154-
The RGB color space.
155-
156-
@param red - (`0`-`255`)
157-
@param green - (`0`-`255`)
158-
@param blue - (`0`-`255`)
159-
*/
160-
rgb(red: number, green: number, blue: number): string;
161-
162-
/**
163-
The RGB HEX color space.
164-
165-
@param hex - A hexadecimal string containing RGB data.
166-
*/
167-
hex(hex: string): string;
168-
169-
/**
170-
@param keyword - A CSS color name.
171-
*/
172-
keyword(keyword: CSSColor): string;
173-
174-
/**
175-
The HSL color space.
176-
177-
@param hue - (`0`-`360`)
178-
@param saturation - (`0`-`100`)
179-
@param lightness - (`0`-`100`)
180-
*/
181-
hsl(hue: number, saturation: number, lightness: number): string;
182-
183-
/**
184-
The HSV color space.
185-
186-
@param hue - (`0`-`360`)
187-
@param saturation - (`0`-`100`)
188-
@param value - (`0`-`100`)
189-
*/
190-
hsv(hue: number, saturation: number, value: number): string;
191-
192-
/**
193-
The HSV color space.
194-
195-
@param hue - (`0`-`360`)
196-
@param whiteness - (`0`-`100`)
197-
@param blackness - (`0`-`100`)
198-
*/
199-
hwb(hue: number, whiteness: number, blackness: number): string;
200-
201-
/**
202-
Use a [4-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4-bit) to set text color.
203-
*/
204-
ansi(ansi: number): string;
205-
206-
/**
207-
Use an [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
208-
*/
209-
ansi256(ansi: number): string;
210-
}
211-
2122
interface CSPair {
2133
/**
2144
The ANSI terminal control sequence for starting this style.
@@ -222,9 +12,9 @@ declare namespace ansiStyles {
22212
}
22313

22414
interface ColorBase {
225-
readonly ansi: ColorConvert;
226-
readonly ansi256: ColorConvert;
227-
readonly ansi16m: ColorConvert;
15+
ansi256(code: number): string;
16+
17+
ansi16m(red: number, green: number, blue: number): string;
22818

22919
/**
23020
The ANSI terminal control sequence for ending this color.
@@ -333,13 +123,38 @@ declare namespace ansiStyles {
333123
readonly bgMagentaBright: CSPair;
334124
readonly bgWhiteBright: CSPair;
335125
}
126+
127+
interface ConvertColor {
128+
/**
129+
Convert from the RGB color space to the ANSI 256 color space.
130+
131+
@param red - (`0...255`)
132+
@param green - (`0...255`)
133+
@param blue - (`0...255`)
134+
*/
135+
rgbToAnsi256(red: number, green: number, blue: number): number;
136+
137+
/**
138+
Convert from the RGB HEX color space to the RGB color space.
139+
140+
@param hex - A hexadecimal string containing RGB data.
141+
*/
142+
hexToRgb(hex: string): [red: number, green: number, blue: number];
143+
144+
/**
145+
Convert from the RGB HEX color space to the ANSI 256 color space.
146+
147+
@param hex - A hexadecimal string containing RGB data.
148+
*/
149+
hexToAnsi256(hex: string): number;
150+
}
336151
}
337152

338153
declare const ansiStyles: {
339154
readonly modifier: ansiStyles.Modifier;
340155
readonly color: ansiStyles.ForegroundColor & ansiStyles.ColorBase;
341156
readonly bgColor: ansiStyles.BackgroundColor & ansiStyles.ColorBase;
342157
readonly codes: ReadonlyMap<number, number>;
343-
} & ansiStyles.BackgroundColor & ansiStyles.ForegroundColor & ansiStyles.Modifier;
158+
} & ansiStyles.BackgroundColor & ansiStyles.ForegroundColor & ansiStyles.Modifier & ansiStyles.ConvertColor;
344159

345160
export = ansiStyles;

0 commit comments

Comments
 (0)