@peteanderson/ansi 0.2.0 → 0.2.1

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.
package/README.md CHANGED
@@ -14,7 +14,7 @@ npm install @peteanderson/ansi
14
14
  const ansi = require("@peteanderson/ansi");
15
15
 
16
16
  console.log(ansi.fg.red("error: something went wrong"));
17
- console.log(ansi.bg.blue(ansi.fg.white("highlighted")));
17
+ console.log(ansi.bg.blue.combine(ansi.fg.white)("highlighted"));
18
18
  console.log(ansi.style.bold("important"));
19
19
  console.log(ansi.fg.rgb(5, 2, 0)("custom color"));
20
20
  console.log(ansi.strip("styled text")); // remove all ANSI codes
@@ -31,7 +31,7 @@ Functions that wrap text with color codes:
31
31
  - Bright colors: `brightBlack` `brightRed` `brightGreen` `brightYellow` `brightBlue` `brightMagenta`
32
32
  `brightCyan` `brightWhite`
33
33
  - `fg.rgb(r, g, b)(text)` - 24-bit RGB color (r, g, b in 0–5 or grayscale 232–255)
34
- - `fg.x256(code)(text)` - 256-color palette
34
+ - `fg.x256(code)(text)` or `fg.x256(r, g, b)(text)` - 256-color palette
35
35
 
36
36
  All return functions with `open` and `close` properties for raw sequences.
37
37
 
@@ -43,7 +43,7 @@ Functions that wrap text with color codes:
43
43
  - Bright colors: `brightBlack` `brightRed` `brightGreen` `brightYellow` `brightBlue` `brightMagenta`
44
44
  `brightCyan` `brightWhite`
45
45
  - `bg.rgb(r, g, b)(text)` - 24-bit RGB color
46
- - `bg.x256(code)(text)` - 256-color palette
46
+ - `bg.x256(code)(text)` or `bg.x256(r, g, b)(text)` - 256-color palette
47
47
 
48
48
  ### `style`
49
49
 
@@ -52,7 +52,8 @@ Functions that wrap text with style codes:
52
52
  `bold` `dim` `italic` `underline` `inverse` `hidden` `strikethrough` `doubleUnderline` `framed`
53
53
  `encircled` `overline`
54
54
 
55
- All return functions with `open` and `close` properties for raw sequences.
55
+ All return functions with `open` and `close` properties for raw sequences. SGR functions also have a
56
+ `combine()` method for appending additional styles.
56
57
 
57
58
  ### `caret`
58
59
 
package/dist/ansi.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import caret = require("./caret");
2
2
  import erase = require("./erase");
3
3
  import scroll = require("./scroll");
4
- import { reset } from "./sgr";
5
- import { style } from "./sgr";
6
- import { fg } from "./sgr";
7
- import { bg } from "./sgr";
4
+ import { reset } from "./sgr/reset";
5
+ import { style } from "./sgr/style";
6
+ import { fg } from "./sgr/color";
7
+ import { bg } from "./sgr/color";
8
8
  import { strip } from "./strip";
9
9
  import { sanitize } from "./strip";
10
10
  import { slice } from "./strip";
package/dist/index.d.ts CHANGED
@@ -44,188 +44,59 @@ declare const _exports: {
44
44
  };
45
45
  reset: string;
46
46
  style: {
47
- bold: ((s: string) => string) & {
48
- open: string;
49
- close: string;
50
- };
51
- dim: ((s: string) => string) & {
52
- open: string;
53
- close: string;
54
- };
55
- italic: ((s: string) => string) & {
56
- open: string;
57
- close: string;
58
- };
59
- underline: ((s: string) => string) & {
60
- open: string;
61
- close: string;
62
- };
63
- inverse: ((s: string) => string) & {
64
- open: string;
65
- close: string;
66
- };
67
- hidden: ((s: string) => string) & {
68
- open: string;
69
- close: string;
70
- };
71
- strikethrough: ((s: string) => string) & {
72
- open: string;
73
- close: string;
74
- };
75
- doubleUnderline: ((s: string) => string) & {
76
- open: string;
77
- close: string;
78
- };
79
- frame: ((s: string) => string) & {
80
- open: string;
81
- close: string;
82
- };
83
- encircle: ((s: string) => string) & {
84
- open: string;
85
- close: string;
86
- };
87
- overline: ((s: string) => string) & {
88
- open: string;
89
- close: string;
90
- };
47
+ bold: import("./sgr/sgr").SGR;
48
+ dim: import("./sgr/sgr").SGR;
49
+ italic: import("./sgr/sgr").SGR;
50
+ underline: import("./sgr/sgr").SGR;
51
+ inverse: import("./sgr/sgr").SGR;
52
+ hidden: import("./sgr/sgr").SGR;
53
+ strikethrough: import("./sgr/sgr").SGR;
54
+ doubleUnderline: import("./sgr/sgr").SGR;
55
+ frame: import("./sgr/sgr").SGR;
56
+ encircle: import("./sgr/sgr").SGR;
57
+ overline: import("./sgr/sgr").SGR;
91
58
  };
92
59
  fg: {
93
- black: ((s: string) => string) & {
94
- open: string;
95
- close: string;
96
- };
97
- red: ((s: string) => string) & {
98
- open: string;
99
- close: string;
100
- };
101
- green: ((s: string) => string) & {
102
- open: string;
103
- close: string;
104
- };
105
- yellow: ((s: string) => string) & {
106
- open: string;
107
- close: string;
108
- };
109
- blue: ((s: string) => string) & {
110
- open: string;
111
- close: string;
112
- };
113
- magenta: ((s: string) => string) & {
114
- open: string;
115
- close: string;
116
- };
117
- cyan: ((s: string) => string) & {
118
- open: string;
119
- close: string;
120
- };
121
- white: ((s: string) => string) & {
122
- open: string;
123
- close: string;
124
- };
125
- brightBlack: ((s: string) => string) & {
126
- open: string;
127
- close: string;
128
- };
129
- brightRed: ((s: string) => string) & {
130
- open: string;
131
- close: string;
132
- };
133
- brightGreen: ((s: string) => string) & {
134
- open: string;
135
- close: string;
136
- };
137
- brightYellow: ((s: string) => string) & {
138
- open: string;
139
- close: string;
140
- };
141
- brightBlue: ((s: string) => string) & {
142
- open: string;
143
- close: string;
144
- };
145
- brightMagenta: ((s: string) => string) & {
146
- open: string;
147
- close: string;
148
- };
149
- brightCyan: ((s: string) => string) & {
150
- open: string;
151
- close: string;
152
- };
153
- brightWhite: ((s: string) => string) & {
154
- open: string;
155
- close: string;
156
- };
60
+ black: import("./sgr/sgr").SGR;
61
+ red: import("./sgr/sgr").SGR;
62
+ green: import("./sgr/sgr").SGR;
63
+ yellow: import("./sgr/sgr").SGR;
64
+ blue: import("./sgr/sgr").SGR;
65
+ magenta: import("./sgr/sgr").SGR;
66
+ cyan: import("./sgr/sgr").SGR;
67
+ white: import("./sgr/sgr").SGR;
68
+ brightBlack: import("./sgr/sgr").SGR;
69
+ brightRed: import("./sgr/sgr").SGR;
70
+ brightGreen: import("./sgr/sgr").SGR;
71
+ brightYellow: import("./sgr/sgr").SGR;
72
+ brightBlue: import("./sgr/sgr").SGR;
73
+ brightMagenta: import("./sgr/sgr").SGR;
74
+ brightCyan: import("./sgr/sgr").SGR;
75
+ brightWhite: import("./sgr/sgr").SGR;
157
76
  default: string;
158
77
  rgb: (r: number, g: number, b: number) => (text: string) => string;
159
- x256: (r: number, g: number, b: number) => (text: string) => string;
78
+ x256: (arg0: number, arg1?: number, arg2?: number) => (text: string) => string;
160
79
  };
161
80
  bg: {
162
- black: ((s: string) => string) & {
163
- open: string;
164
- close: string;
165
- };
166
- red: ((s: string) => string) & {
167
- open: string;
168
- close: string;
169
- };
170
- green: ((s: string) => string) & {
171
- open: string;
172
- close: string;
173
- };
174
- yellow: ((s: string) => string) & {
175
- open: string;
176
- close: string;
177
- };
178
- blue: ((s: string) => string) & {
179
- open: string;
180
- close: string;
181
- };
182
- magenta: ((s: string) => string) & {
183
- open: string;
184
- close: string;
185
- };
186
- cyan: ((s: string) => string) & {
187
- open: string;
188
- close: string;
189
- };
190
- white: ((s: string) => string) & {
191
- open: string;
192
- close: string;
193
- };
194
- brightBlack: ((s: string) => string) & {
195
- open: string;
196
- close: string;
197
- };
198
- brightRed: ((s: string) => string) & {
199
- open: string;
200
- close: string;
201
- };
202
- brightGreen: ((s: string) => string) & {
203
- open: string;
204
- close: string;
205
- };
206
- brightYellow: ((s: string) => string) & {
207
- open: string;
208
- close: string;
209
- };
210
- brightBlue: ((s: string) => string) & {
211
- open: string;
212
- close: string;
213
- };
214
- brightMagenta: ((s: string) => string) & {
215
- open: string;
216
- close: string;
217
- };
218
- brightCyan: ((s: string) => string) & {
219
- open: string;
220
- close: string;
221
- };
222
- brightWhite: ((s: string) => string) & {
223
- open: string;
224
- close: string;
225
- };
81
+ black: import("./sgr/sgr").SGR;
82
+ red: import("./sgr/sgr").SGR;
83
+ green: import("./sgr/sgr").SGR;
84
+ yellow: import("./sgr/sgr").SGR;
85
+ blue: import("./sgr/sgr").SGR;
86
+ magenta: import("./sgr/sgr").SGR;
87
+ cyan: import("./sgr/sgr").SGR;
88
+ white: import("./sgr/sgr").SGR;
89
+ brightBlack: import("./sgr/sgr").SGR;
90
+ brightRed: import("./sgr/sgr").SGR;
91
+ brightGreen: import("./sgr/sgr").SGR;
92
+ brightYellow: import("./sgr/sgr").SGR;
93
+ brightBlue: import("./sgr/sgr").SGR;
94
+ brightMagenta: import("./sgr/sgr").SGR;
95
+ brightCyan: import("./sgr/sgr").SGR;
96
+ brightWhite: import("./sgr/sgr").SGR;
226
97
  default: string;
227
98
  rgb: (r: number, g: number, b: number) => (text: string) => string;
228
- x256: (r: number, g: number, b: number) => (text: string) => string;
99
+ x256: (arg0: number, arg1?: number, arg2?: number) => (text: string) => string;
229
100
  };
230
101
  strip: (text: string) => string;
231
102
  sanitize: (text: string) => string;
@@ -0,0 +1,62 @@
1
+ export namespace fg {
2
+ export let black: import("./sgr").SGR;
3
+ export let red: import("./sgr").SGR;
4
+ export let green: import("./sgr").SGR;
5
+ export let yellow: import("./sgr").SGR;
6
+ export let blue: import("./sgr").SGR;
7
+ export let magenta: import("./sgr").SGR;
8
+ export let cyan: import("./sgr").SGR;
9
+ export let white: import("./sgr").SGR;
10
+ export let brightBlack: import("./sgr").SGR;
11
+ export let brightRed: import("./sgr").SGR;
12
+ export let brightGreen: import("./sgr").SGR;
13
+ export let brightYellow: import("./sgr").SGR;
14
+ export let brightBlue: import("./sgr").SGR;
15
+ export let brightMagenta: import("./sgr").SGR;
16
+ export let brightCyan: import("./sgr").SGR;
17
+ export let brightWhite: import("./sgr").SGR;
18
+ let _default: string;
19
+ export { _default as default };
20
+ export let rgb: (r: number, g: number, b: number) => (text: string) => string;
21
+ export let x256: (arg0: number, arg1?: number, arg2?: number) => (text: string) => string;
22
+ }
23
+ export namespace bg {
24
+ let black_1: import("./sgr").SGR;
25
+ export { black_1 as black };
26
+ let red_1: import("./sgr").SGR;
27
+ export { red_1 as red };
28
+ let green_1: import("./sgr").SGR;
29
+ export { green_1 as green };
30
+ let yellow_1: import("./sgr").SGR;
31
+ export { yellow_1 as yellow };
32
+ let blue_1: import("./sgr").SGR;
33
+ export { blue_1 as blue };
34
+ let magenta_1: import("./sgr").SGR;
35
+ export { magenta_1 as magenta };
36
+ let cyan_1: import("./sgr").SGR;
37
+ export { cyan_1 as cyan };
38
+ let white_1: import("./sgr").SGR;
39
+ export { white_1 as white };
40
+ let brightBlack_1: import("./sgr").SGR;
41
+ export { brightBlack_1 as brightBlack };
42
+ let brightRed_1: import("./sgr").SGR;
43
+ export { brightRed_1 as brightRed };
44
+ let brightGreen_1: import("./sgr").SGR;
45
+ export { brightGreen_1 as brightGreen };
46
+ let brightYellow_1: import("./sgr").SGR;
47
+ export { brightYellow_1 as brightYellow };
48
+ let brightBlue_1: import("./sgr").SGR;
49
+ export { brightBlue_1 as brightBlue };
50
+ let brightMagenta_1: import("./sgr").SGR;
51
+ export { brightMagenta_1 as brightMagenta };
52
+ let brightCyan_1: import("./sgr").SGR;
53
+ export { brightCyan_1 as brightCyan };
54
+ let brightWhite_1: import("./sgr").SGR;
55
+ export { brightWhite_1 as brightWhite };
56
+ let _default_1: string;
57
+ export { _default_1 as default };
58
+ let rgb_1: (r: number, g: number, b: number) => (text: string) => string;
59
+ export { rgb_1 as rgb };
60
+ let x256_1: (arg0: number, arg1?: number, arg2?: number) => (text: string) => string;
61
+ export { x256_1 as x256 };
62
+ }
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ const { sgr } = require("./sgr");
3
+ /** @type {(r: number, g: number, b: number, open: number, close: number) => (text: string) => string} */
4
+ const rgb = (r, g, b, open, close) => sgr([open, 2, r, g, b], close);
5
+ /**
6
+ * @overload
7
+ * @param {number} code
8
+ * @param {number} open
9
+ * @param {number} close
10
+ * @returns {(text: string) => string}
11
+ */ /**
12
+ * @overload
13
+ * @param {number} r
14
+ * @param {number} g
15
+ * @param {number} b
16
+ * @param {number} open
17
+ * @param {number} close
18
+ * @returns {(text: string) => string}
19
+ */ /**
20
+ @type {
21
+ (
22
+ ...args: [number, number, number] | [number, number, number, number, number]
23
+ ) => (text: string) => string}
24
+ */
25
+ function x256(...args) {
26
+ if (args.length === 3)
27
+ return sgr([args[1], 5, args[0]], args[2]);
28
+ const [r, g, b, open, close] = args;
29
+ if (r === g && g === b) {
30
+ // grayscale
31
+ return sgr([open, 5, 232 + Math.floor(r * 24 / 256)], close);
32
+ }
33
+ // 6x6x6 color cube
34
+ return sgr([
35
+ open,
36
+ 5,
37
+ 16 +
38
+ Math.floor(r * 6 / 256) * 36 +
39
+ Math.floor(g * 6 / 256) * 6 +
40
+ Math.floor(b * 6 / 256)
41
+ ], close);
42
+ }
43
+ const fg = {
44
+ black: sgr(30, 39),
45
+ red: sgr(31, 39),
46
+ green: sgr(32, 39),
47
+ yellow: sgr(33, 39),
48
+ blue: sgr(34, 39),
49
+ magenta: sgr(35, 39),
50
+ cyan: sgr(36, 39),
51
+ white: sgr(37, 39),
52
+ brightBlack: sgr(90, 39),
53
+ brightRed: sgr(91, 39),
54
+ brightGreen: sgr(92, 39),
55
+ brightYellow: sgr(93, 39),
56
+ brightBlue: sgr(94, 39),
57
+ brightMagenta: sgr(95, 39),
58
+ brightCyan: sgr(96, 39),
59
+ brightWhite: sgr(97, 39),
60
+ default: "\x1b[39m",
61
+ /** @type {(r: number, g: number, b: number) => (text: string) => string} */
62
+ rgb: (r, g, b) => rgb(r, g, b, 38, 39),
63
+ /**
64
+ * @overload
65
+ * @param {number} code
66
+ * @returns {(text: string) => string}
67
+ */ /**
68
+ * @param {number} r
69
+ * @param {number} g
70
+ * @param {number} b
71
+ * @returns {(text: string) => string}
72
+ */ /** @type {(arg0: number, arg1?: number, arg2?: number) => (text: string) => string} */
73
+ x256: (arg0, arg1, arg2) => arg1 === undefined || arg2 === undefined
74
+ ? x256(arg0, 38, 39)
75
+ : x256(arg0, arg1, arg2, 38, 39),
76
+ };
77
+ const bg = {
78
+ black: sgr(40, 49),
79
+ red: sgr(41, 49),
80
+ green: sgr(42, 49),
81
+ yellow: sgr(43, 49),
82
+ blue: sgr(44, 49),
83
+ magenta: sgr(45, 49),
84
+ cyan: sgr(46, 49),
85
+ white: sgr(47, 49),
86
+ brightBlack: sgr(100, 49),
87
+ brightRed: sgr(101, 49),
88
+ brightGreen: sgr(102, 49),
89
+ brightYellow: sgr(103, 49),
90
+ brightBlue: sgr(104, 49),
91
+ brightMagenta: sgr(105, 49),
92
+ brightCyan: sgr(106, 49),
93
+ brightWhite: sgr(107, 49),
94
+ default: "\x1b[49m",
95
+ /** @type {(r: number, g: number, b: number) => (text: string) => string} */
96
+ rgb: (r, g, b) => rgb(r, g, b, 48, 49),
97
+ /**
98
+ * @overload
99
+ * @param {number} code
100
+ * @returns {(text: string) => string}
101
+ */ /**
102
+ * @param {number} r
103
+ * @param {number} g
104
+ * @param {number} b
105
+ * @returns {(text: string) => string}
106
+ */ /** @type {(arg0: number, arg1?: number, arg2?: number) => (text: string) => string} */
107
+ x256: (arg0, arg1, arg2) => arg1 === undefined || arg2 === undefined
108
+ ? x256(arg0, 48, 49)
109
+ : x256(arg0, arg1, arg2, 48, 49),
110
+ };
111
+ module.exports = { fg, bg };
@@ -0,0 +1,59 @@
1
+ declare const _exports: {
2
+ fg: {
3
+ black: import("./sgr").SGR;
4
+ red: import("./sgr").SGR;
5
+ green: import("./sgr").SGR;
6
+ yellow: import("./sgr").SGR;
7
+ blue: import("./sgr").SGR;
8
+ magenta: import("./sgr").SGR;
9
+ cyan: import("./sgr").SGR;
10
+ white: import("./sgr").SGR;
11
+ brightBlack: import("./sgr").SGR;
12
+ brightRed: import("./sgr").SGR;
13
+ brightGreen: import("./sgr").SGR;
14
+ brightYellow: import("./sgr").SGR;
15
+ brightBlue: import("./sgr").SGR;
16
+ brightMagenta: import("./sgr").SGR;
17
+ brightCyan: import("./sgr").SGR;
18
+ brightWhite: import("./sgr").SGR;
19
+ default: string;
20
+ rgb: (r: number, g: number, b: number) => (text: string) => string;
21
+ x256: (arg0: number, arg1?: number, arg2?: number) => (text: string) => string;
22
+ };
23
+ bg: {
24
+ black: import("./sgr").SGR;
25
+ red: import("./sgr").SGR;
26
+ green: import("./sgr").SGR;
27
+ yellow: import("./sgr").SGR;
28
+ blue: import("./sgr").SGR;
29
+ magenta: import("./sgr").SGR;
30
+ cyan: import("./sgr").SGR;
31
+ white: import("./sgr").SGR;
32
+ brightBlack: import("./sgr").SGR;
33
+ brightRed: import("./sgr").SGR;
34
+ brightGreen: import("./sgr").SGR;
35
+ brightYellow: import("./sgr").SGR;
36
+ brightBlue: import("./sgr").SGR;
37
+ brightMagenta: import("./sgr").SGR;
38
+ brightCyan: import("./sgr").SGR;
39
+ brightWhite: import("./sgr").SGR;
40
+ default: string;
41
+ rgb: (r: number, g: number, b: number) => (text: string) => string;
42
+ x256: (arg0: number, arg1?: number, arg2?: number) => (text: string) => string;
43
+ };
44
+ style: {
45
+ bold: import("./sgr").SGR;
46
+ dim: import("./sgr").SGR;
47
+ italic: import("./sgr").SGR;
48
+ underline: import("./sgr").SGR;
49
+ inverse: import("./sgr").SGR;
50
+ hidden: import("./sgr").SGR;
51
+ strikethrough: import("./sgr").SGR;
52
+ doubleUnderline: import("./sgr").SGR;
53
+ frame: import("./sgr").SGR;
54
+ encircle: import("./sgr").SGR;
55
+ overline: import("./sgr").SGR;
56
+ };
57
+ reset: "\u001B[0m";
58
+ };
59
+ export = _exports;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ module.exports = {
3
+ ...require("./reset"),
4
+ ...require("./style"),
5
+ ...require("./color"),
6
+ };
@@ -0,0 +1 @@
1
+ export const reset: "\u001B[0m";
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ const reset = "\x1b[0m";
3
+ module.exports = { reset };
@@ -0,0 +1,14 @@
1
+ export type Code = number | number[];
2
+ export type SGR = {
3
+ (text: string): string;
4
+ open: string;
5
+ close: string;
6
+ [$codes]: {
7
+ open: Code;
8
+ close: Code;
9
+ };
10
+ combine: (...styles: SGR[]) => SGR;
11
+ };
12
+ export function sgr(open: Code, close: Code, reset?: boolean): SGR;
13
+ declare const $codes: unique symbol;
14
+ export {};
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ const $codes = Symbol();
3
+ /**
4
+ @typedef {number | number[]} Code
5
+ @typedef {{
6
+ (text: string): string;
7
+ open : string;
8
+ close : string;
9
+ [$codes] : {open: Code, close: Code};
10
+ combine : (...styles: SGR[]) => SGR;
11
+ }} SGR
12
+ */
13
+ /** @type {(code: Code, codes: Code[]) => Code} */
14
+ function combine(code, codes) {
15
+ if (!codes.length)
16
+ return code;
17
+ const rtn = Array.isArray(code) ? [...code] : [code];
18
+ for (const c of codes) {
19
+ if (Array.isArray(c))
20
+ rtn.push(...c);
21
+ else
22
+ rtn.push(c);
23
+ }
24
+ return rtn;
25
+ }
26
+ /** @type {(code: Code) => string | number} */
27
+ const codeSequence = code => Array.isArray(code) ? code.join(';') : code;
28
+ /** @type {(open: Code, close: Code, reset?: boolean) => SGR} */
29
+ function sgr(open, close, reset = false) {
30
+ const openCode = codeSequence(open);
31
+ const closeCode = codeSequence(close);
32
+ const openSequence = `\x1b[${openCode}m`;
33
+ const closeSequence = `\x1b[${closeCode}m`;
34
+ const reopenCode = reset ? `${closeCode};${openCode}` : openCode;
35
+ const rxClose = new RegExp(`(?<start>\\x1b\\[(?:\\d+;)*)${closeCode}(?<end>(?:;\\d+)*m)`, "g");
36
+ const replace = `$<start>${reopenCode}$<end>`;
37
+ /** @type {(text: string) => string} */
38
+ const func = s => openSequence + s.replace(rxClose, replace) + closeSequence;
39
+ return Object.assign(func, {
40
+ [$codes]: { open, close },
41
+ open: openSequence,
42
+ close: closeSequence,
43
+ /** @type {(...styles: SGR[]) => SGR} */
44
+ combine: (...styles) => sgr(combine(open, styles.map(s => s[$codes].open)), combine(close, styles.map(s => s[$codes].close))),
45
+ });
46
+ }
47
+ module.exports = { sgr };
@@ -0,0 +1,13 @@
1
+ export namespace style {
2
+ let bold: import("./sgr").SGR;
3
+ let dim: import("./sgr").SGR;
4
+ let italic: import("./sgr").SGR;
5
+ let underline: import("./sgr").SGR;
6
+ let inverse: import("./sgr").SGR;
7
+ let hidden: import("./sgr").SGR;
8
+ let strikethrough: import("./sgr").SGR;
9
+ let doubleUnderline: import("./sgr").SGR;
10
+ let frame: import("./sgr").SGR;
11
+ let encircle: import("./sgr").SGR;
12
+ let overline: import("./sgr").SGR;
13
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ const { sgr } = require("./sgr");
3
+ const style = {
4
+ bold: sgr(1, 22, true),
5
+ dim: sgr(2, 22, true),
6
+ italic: sgr(3, 23),
7
+ underline: sgr(4, 24),
8
+ inverse: sgr(7, 27),
9
+ hidden: sgr(8, 28),
10
+ strikethrough: sgr(9, 29),
11
+ doubleUnderline: sgr(21, 24),
12
+ frame: sgr(51, 54),
13
+ encircle: sgr(52, 54),
14
+ overline: sgr(53, 55),
15
+ };
16
+ module.exports = { style };
@@ -0,0 +1,2 @@
1
+ export type Code = number | number[];
2
+ export function combine(code: Code, codes: Code[]): Code;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ /** @typedef {number | number[]} Code */
3
+ /** @type {(code: Code, codes: Code[]) => Code} */
4
+ function combine(code, codes) {
5
+ if (!codes.length)
6
+ return code;
7
+ const rtn = Array.isArray(code) ? [...code] : [code];
8
+ for (const c of codes) {
9
+ if (Array.isArray(c))
10
+ rtn.push(...c);
11
+ else
12
+ rtn.push(c);
13
+ }
14
+ return rtn;
15
+ }
16
+ module.exports = { combine };
package/dist/strip.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  */
5
5
  export const strip: (text: string) => string;
6
6
  /**
7
- * Remove all ANSI escape codes except SGR (m) codes, which are used for color and styling.
7
+ * Remove all ANSI escape codes except SGR codes (m), which are used for color and styling.
8
8
  * @type {(text: string) => string}
9
9
  */
10
10
  export const sanitize: (text: string) => string;