Skip to content

Commit b23ef5d

Browse files
committed
Require Node.js 12 and move to ESM
1 parent 4d30b90 commit b23ef5d

File tree

10 files changed

+324
-332
lines changed

10 files changed

+324
-332
lines changed

.github/funding.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github: [sindresorhus,Qix-]
1+
github: [sindresorhus, Qix-]
22
tidelift: npm/ansi-styles

.github/workflows/main.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ jobs:
1212
node-version:
1313
- 14
1414
- 12
15-
- 10
1615
steps:
1716
- uses: actions/checkout@v2
18-
- uses: actions/setup-node@v1
17+
- uses: actions/setup-node@v2
1918
with:
2019
node-version: ${{ matrix.node-version }}
2120
- run: npm install

index.d.ts

Lines changed: 160 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -1,167 +1,165 @@
1-
declare namespace ansiStyles {
2-
interface CSPair {
3-
/**
4-
The ANSI terminal control sequence for starting this style.
5-
*/
6-
readonly open: string;
7-
8-
/**
9-
The ANSI terminal control sequence for ending this style.
10-
*/
11-
readonly close: string;
12-
}
13-
14-
interface ColorBase {
15-
/**
16-
The ANSI terminal control sequence for ending this color.
17-
*/
18-
readonly close: string;
19-
20-
ansi256(code: number): string;
21-
22-
ansi16m(red: number, green: number, blue: number): string;
23-
}
24-
25-
interface Modifier {
26-
/**
27-
Resets the current color chain.
28-
*/
29-
readonly reset: CSPair;
30-
31-
/**
32-
Make text bold.
33-
*/
34-
readonly bold: CSPair;
35-
36-
/**
37-
Emitting only a small amount of light.
38-
*/
39-
readonly dim: CSPair;
40-
41-
/**
42-
Make text italic. (Not widely supported)
43-
*/
44-
readonly italic: CSPair;
45-
46-
/**
47-
Make text underline. (Not widely supported)
48-
*/
49-
readonly underline: CSPair;
50-
51-
/**
52-
Make text overline.
53-
54-
Supported on VTE-based terminals, the GNOME terminal, mintty, and Git Bash.
55-
*/
56-
readonly overline: CSPair;
57-
58-
/**
59-
Inverse background and foreground colors.
60-
*/
61-
readonly inverse: CSPair;
62-
63-
/**
64-
Prints the text, but makes it invisible.
65-
*/
66-
readonly hidden: CSPair;
67-
68-
/**
69-
Puts a horizontal line through the center of the text. (Not widely supported)
70-
*/
71-
readonly strikethrough: CSPair;
72-
}
73-
74-
interface ForegroundColor {
75-
readonly black: CSPair;
76-
readonly red: CSPair;
77-
readonly green: CSPair;
78-
readonly yellow: CSPair;
79-
readonly blue: CSPair;
80-
readonly cyan: CSPair;
81-
readonly magenta: CSPair;
82-
readonly white: CSPair;
83-
84-
/**
85-
Alias for `blackBright`.
86-
*/
87-
readonly gray: CSPair;
88-
89-
/**
90-
Alias for `blackBright`.
91-
*/
92-
readonly grey: CSPair;
93-
94-
readonly blackBright: CSPair;
95-
readonly redBright: CSPair;
96-
readonly greenBright: CSPair;
97-
readonly yellowBright: CSPair;
98-
readonly blueBright: CSPair;
99-
readonly cyanBright: CSPair;
100-
readonly magentaBright: CSPair;
101-
readonly whiteBright: CSPair;
102-
}
103-
104-
interface BackgroundColor {
105-
readonly bgBlack: CSPair;
106-
readonly bgRed: CSPair;
107-
readonly bgGreen: CSPair;
108-
readonly bgYellow: CSPair;
109-
readonly bgBlue: CSPair;
110-
readonly bgCyan: CSPair;
111-
readonly bgMagenta: CSPair;
112-
readonly bgWhite: CSPair;
113-
114-
/**
115-
Alias for `bgBlackBright`.
116-
*/
117-
readonly bgGray: CSPair;
118-
119-
/**
120-
Alias for `bgBlackBright`.
121-
*/
122-
readonly bgGrey: CSPair;
123-
124-
readonly bgBlackBright: CSPair;
125-
readonly bgRedBright: CSPair;
126-
readonly bgGreenBright: CSPair;
127-
readonly bgYellowBright: CSPair;
128-
readonly bgBlueBright: CSPair;
129-
readonly bgCyanBright: CSPair;
130-
readonly bgMagentaBright: CSPair;
131-
readonly bgWhiteBright: CSPair;
132-
}
133-
134-
interface ConvertColor {
135-
/**
136-
Convert from the RGB color space to the ANSI 256 color space.
137-
138-
@param red - (`0...255`)
139-
@param green - (`0...255`)
140-
@param blue - (`0...255`)
141-
*/
142-
rgbToAnsi256(red: number, green: number, blue: number): number;
143-
144-
/**
145-
Convert from the RGB HEX color space to the RGB color space.
146-
147-
@param hex - A hexadecimal string containing RGB data.
148-
*/
149-
hexToRgb(hex: string): [red: number, green: number, blue: number];
150-
151-
/**
152-
Convert from the RGB HEX color space to the ANSI 256 color space.
153-
154-
@param hex - A hexadecimal string containing RGB data.
155-
*/
156-
hexToAnsi256(hex: string): number;
157-
}
1+
export interface CSPair {
2+
/**
3+
The ANSI terminal control sequence for starting this style.
4+
*/
5+
readonly open: string;
6+
7+
/**
8+
The ANSI terminal control sequence for ending this style.
9+
*/
10+
readonly close: string;
11+
}
12+
13+
export interface ColorBase {
14+
/**
15+
The ANSI terminal control sequence for ending this color.
16+
*/
17+
readonly close: string;
18+
19+
ansi256(code: number): string;
20+
21+
ansi16m(red: number, green: number, blue: number): string;
22+
}
23+
24+
export interface Modifier {
25+
/**
26+
Resets the current color chain.
27+
*/
28+
readonly reset: CSPair;
29+
30+
/**
31+
Make text bold.
32+
*/
33+
readonly bold: CSPair;
34+
35+
/**
36+
Emitting only a small amount of light.
37+
*/
38+
readonly dim: CSPair;
39+
40+
/**
41+
Make text italic. (Not widely supported)
42+
*/
43+
readonly italic: CSPair;
44+
45+
/**
46+
Make text underline. (Not widely supported)
47+
*/
48+
readonly underline: CSPair;
49+
50+
/**
51+
Make text overline.
52+
53+
Supported on VTE-based terminals, the GNOME terminal, mintty, and Git Bash.
54+
*/
55+
readonly overline: CSPair;
56+
57+
/**
58+
Inverse background and foreground colors.
59+
*/
60+
readonly inverse: CSPair;
61+
62+
/**
63+
Prints the text, but makes it invisible.
64+
*/
65+
readonly hidden: CSPair;
66+
67+
/**
68+
Puts a horizontal line through the center of the text. (Not widely supported)
69+
*/
70+
readonly strikethrough: CSPair;
71+
}
72+
73+
export interface ForegroundColor {
74+
readonly black: CSPair;
75+
readonly red: CSPair;
76+
readonly green: CSPair;
77+
readonly yellow: CSPair;
78+
readonly blue: CSPair;
79+
readonly cyan: CSPair;
80+
readonly magenta: CSPair;
81+
readonly white: CSPair;
82+
83+
/**
84+
Alias for `blackBright`.
85+
*/
86+
readonly gray: CSPair;
87+
88+
/**
89+
Alias for `blackBright`.
90+
*/
91+
readonly grey: CSPair;
92+
93+
readonly blackBright: CSPair;
94+
readonly redBright: CSPair;
95+
readonly greenBright: CSPair;
96+
readonly yellowBright: CSPair;
97+
readonly blueBright: CSPair;
98+
readonly cyanBright: CSPair;
99+
readonly magentaBright: CSPair;
100+
readonly whiteBright: CSPair;
101+
}
102+
103+
export interface BackgroundColor {
104+
readonly bgBlack: CSPair;
105+
readonly bgRed: CSPair;
106+
readonly bgGreen: CSPair;
107+
readonly bgYellow: CSPair;
108+
readonly bgBlue: CSPair;
109+
readonly bgCyan: CSPair;
110+
readonly bgMagenta: CSPair;
111+
readonly bgWhite: CSPair;
112+
113+
/**
114+
Alias for `bgBlackBright`.
115+
*/
116+
readonly bgGray: CSPair;
117+
118+
/**
119+
Alias for `bgBlackBright`.
120+
*/
121+
readonly bgGrey: CSPair;
122+
123+
readonly bgBlackBright: CSPair;
124+
readonly bgRedBright: CSPair;
125+
readonly bgGreenBright: CSPair;
126+
readonly bgYellowBright: CSPair;
127+
readonly bgBlueBright: CSPair;
128+
readonly bgCyanBright: CSPair;
129+
readonly bgMagentaBright: CSPair;
130+
readonly bgWhiteBright: CSPair;
131+
}
132+
133+
export interface ConvertColor {
134+
/**
135+
Convert from the RGB color space to the ANSI 256 color space.
136+
137+
@param red - (`0...255`)
138+
@param green - (`0...255`)
139+
@param blue - (`0...255`)
140+
*/
141+
rgbToAnsi256(red: number, green: number, blue: number): number;
142+
143+
/**
144+
Convert from the RGB HEX color space to the RGB color space.
145+
146+
@param hex - A hexadecimal string containing RGB data.
147+
*/
148+
hexToRgb(hex: string): [red: number, green: number, blue: number];
149+
150+
/**
151+
Convert from the RGB HEX color space to the ANSI 256 color space.
152+
153+
@param hex - A hexadecimal string containing RGB data.
154+
*/
155+
hexToAnsi256(hex: string): number;
158156
}
159157

160158
declare const ansiStyles: {
161-
readonly modifier: ansiStyles.Modifier;
162-
readonly color: ansiStyles.ForegroundColor & ansiStyles.ColorBase;
163-
readonly bgColor: ansiStyles.BackgroundColor & ansiStyles.ColorBase;
159+
readonly modifier: Modifier;
160+
readonly color: ColorBase & ForegroundColor;
161+
readonly bgColor: ColorBase & BackgroundColor;
164162
readonly codes: ReadonlyMap<number, number>;
165-
} & ansiStyles.BackgroundColor & ansiStyles.ForegroundColor & ansiStyles.Modifier & ansiStyles.ConvertColor;
163+
} & ForegroundColor & BackgroundColor & Modifier & ConvertColor;
166164

167-
export = ansiStyles;
165+
export default ansiStyles;

index.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
const ANSI_BACKGROUND_OFFSET = 10;
42

53
const wrapAnsi256 = (offset = 0) => code => `\u001B[${38 + offset};5;${code}m`;
@@ -157,8 +155,6 @@ function assembleStyles() {
157155
return styles;
158156
}
159157

160-
// Make the export immutable
161-
Object.defineProperty(module, 'exports', {
162-
enumerable: true,
163-
get: assembleStyles
164-
});
158+
const ansiStyles = assembleStyles();
159+
160+
export default ansiStyles;

0 commit comments

Comments
 (0)