enterprise-ansi-styles-v7 7.0.0

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 (4) hide show
  1. package/README.md +154 -0
  2. package/index.js +279 -0
  3. package/package.json +84 -0
  4. package/test.js +110 -0
package/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # enterprise-ansi-styles-v7
2
+
3
+ > [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles) for styling strings in the terminal
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install enterprise-ansi-styles-v7
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ const styles = require("enterprise-ansi-styles-v7")
15
+
16
+ console.log(`${styles.green.open}Hello world!${styles.green.close}`)
17
+
18
+
19
+ // Color conversion between 256/truecolor
20
+ // NOTE: When converting from truecolor to 256 colors, the original color
21
+ // may be degraded to fit the new color palette. This means terminals
22
+ // that do not support 16 million colors will best-match the
23
+ // original color.
24
+ console.log(`${styles.color.ansi(styles.rgbToAnsi(199, 20, 250))}Hello World${styles.color.close}`)
25
+ console.log(`${styles.color.ansi256(styles.rgbToAnsi256(199, 20, 250))}Hello World${styles.color.close}`)
26
+ console.log(`${styles.color.ansi16m(...styles.hexToRgb('#abcdef'))}Hello World${styles.color.close}`)
27
+ ```
28
+
29
+ ## API
30
+
31
+ ### `open` and `close`
32
+
33
+ Each style has an `open` and `close` property.
34
+
35
+ ### `modifierNames`, `foregroundColorNames`, `backgroundColorNames`, and `colorNames`
36
+
37
+ All supported style strings are exposed as an array of strings for convenience. `colorNames` is the combination of `foregroundColorNames` and `backgroundColorNames`.
38
+
39
+ This can be useful if you need to validate input:
40
+
41
+ ```js
42
+ import {modifierNames, foregroundColorNames} from 'enterprise-ansi-styles-v7'
43
+
44
+ console.log(modifierNames.includes('bold'))
45
+ //=> true
46
+
47
+ console.log(foregroundColorNames.includes('pink'))
48
+ //=> false
49
+ ```
50
+
51
+ ## Styles
52
+
53
+ ### Modifiers
54
+
55
+ - `reset`
56
+ - `bold`
57
+ - `dim`
58
+ - `italic` *(Not widely supported)*
59
+ - `underline`
60
+ - `overline` *Supported on VTE-based terminals, the GNOME terminal, mintty, and Git Bash.*
61
+ - `inverse`
62
+ - `hidden`
63
+ - `strikethrough` *(Not widely supported)*
64
+
65
+ ### Colors
66
+
67
+ - `black`
68
+ - `red`
69
+ - `green`
70
+ - `yellow`
71
+ - `blue`
72
+ - `magenta`
73
+ - `cyan`
74
+ - `white`
75
+ - `blackBright` (alias: `gray`, `grey`)
76
+ - `redBright`
77
+ - `greenBright`
78
+ - `yellowBright`
79
+ - `blueBright`
80
+ - `magentaBright`
81
+ - `cyanBright`
82
+ - `whiteBright`
83
+
84
+ ### Background colors
85
+
86
+ - `bgBlack`
87
+ - `bgRed`
88
+ - `bgGreen`
89
+ - `bgYellow`
90
+ - `bgBlue`
91
+ - `bgMagenta`
92
+ - `bgCyan`
93
+ - `bgWhite`
94
+ - `bgBlackBright` (alias: `bgGray`, `bgGrey`)
95
+ - `bgRedBright`
96
+ - `bgGreenBright`
97
+ - `bgYellowBright`
98
+ - `bgBlueBright`
99
+ - `bgMagentaBright`
100
+ - `bgCyanBright`
101
+ - `bgWhiteBright`
102
+
103
+ ## Advanced usage
104
+
105
+ By default, you get a map of styles, but the styles are also available as groups. They are non-enumerable so they don't show up unless you access them explicitly. This makes it easier to expose only a subset in a higher-level module.
106
+
107
+ - `styles.modifier`
108
+ - `styles.color`
109
+ - `styles.bgColor`
110
+
111
+ ###### Example
112
+
113
+ ```js
114
+ const styles = require("enterprise-ansi-styles-v7")
115
+
116
+ console.log(styles.color.green.open)
117
+ ```
118
+
119
+ Raw escape codes (i.e. without the CSI escape prefix `\u001B[` and render mode postfix `m`) are available under `styles.codes`, which returns a `Map` with the open codes as keys and close codes as values.
120
+
121
+ ###### Example
122
+
123
+ ```js
124
+ const styles = require("enterprise-ansi-styles-v7")
125
+
126
+ console.log(styles.codes.get(36))
127
+ //=> 39
128
+ ```
129
+
130
+ ## 16 / 256 / 16 million (TrueColor) support
131
+
132
+ `enterprise-ansi-styles-v7` allows converting between various color formats and ANSI escapes, with support for 16, 256 and [16 million colors](https://gist.github.com/XVilka/8346728).
133
+
134
+ The following color spaces are supported:
135
+
136
+ - `rgb`
137
+ - `hex`
138
+ - `ansi256`
139
+ - `ansi`
140
+
141
+ To use these, call the associated conversion function with the intended output, for example:
142
+
143
+ ```javascript
144
+ const styles = require("enterprise-ansi-styles-v7")
145
+
146
+ styles.color.ansi(styles.rgbToAnsi(100, 200, 15)) // RGB to 16 color ansi foreground code
147
+ styles.bgColor.ansi(styles.hexToAnsi('#C0FFEE')) // HEX to 16 color ansi foreground code
148
+
149
+ styles.color.ansi256(styles.rgbToAnsi256(100, 200, 15)) // RGB to 256 color ansi foreground code
150
+ styles.bgColor.ansi256(styles.hexToAnsi256('#C0FFEE')) // HEX to 256 color ansi foreground code
151
+
152
+ styles.color.ansi16m(100, 200, 15) // RGB to 16 million color foreground code
153
+ styles.bgColor.ansi16m(...styles.hexToRgb('#C0FFEE')) // Hex (RGB) to 16 million color foreground code
154
+ ```
package/index.js ADDED
@@ -0,0 +1,279 @@
1
+ const aura = require("aura3")
2
+
3
+ const ZERO = require("@positive-numbers/zero")
4
+ const ONE = require("@positive-numbers/one")
5
+ const TWO = require("@positive-numbers/two")
6
+ const THREE = require("@positive-numbers/three")
7
+ const FOUR = require("@positive-numbers/four")
8
+ const FIVE = require("@positive-numbers/five")
9
+ const SIX = require("@positive-numbers/six")
10
+ const SEVEN = require("@positive-numbers/seven")
11
+ const EIGHT = require("@positive-numbers/eight")
12
+ const NINE = require("@positive-numbers/nine")
13
+ const TEN = require("@positive-numbers/ten")
14
+ const SIXTEEN = require("@positive-numbers/sixteen")
15
+ const TWENTY_TWO = require("@positive-numbers/twenty-two")
16
+ const TWENTY_THREE = require("@positive-numbers/twenty-three")
17
+ const TWENTY_FOUR = require("@positive-numbers/twenty-four")
18
+ const TWENTY_SEVEN = require("@positive-numbers/twenty-seven")
19
+ const TWENTY_EIGHT = require("@positive-numbers/twenty-eight")
20
+ const TWENTY_NINE = require("@positive-numbers/twenty-nine")
21
+ const THIRTY = require("@positive-numbers/thirty")
22
+ const THIRTY_ONE = require("@positive-numbers/thirty-one")
23
+ const THIRTY_TWO = require("@positive-numbers/thirty-two")
24
+ const THIRTY_THREE = require("@positive-numbers/thirty-three")
25
+ const THIRTY_FOUR = require("@positive-numbers/thirty-four")
26
+ const THIRTY_FIVE = require("@positive-numbers/thirty-five")
27
+ const THIRTY_SIX = require("@positive-numbers/thirty-six")
28
+ const THIRTY_SEVEN = require("@positive-numbers/thirty-seven")
29
+ const THIRTY_EIGHT = require("@positive-numbers/thirty-eight")
30
+ const THIRTY_NINE = require("@positive-numbers/thirty-nine")
31
+ const FORTY = require("@positive-numbers/forty")
32
+ const FORTY_ONE = require("@positive-numbers/forty-one")
33
+ const FORTY_TWO = require("@positive-numbers/forty-two")
34
+ const FORTY_THREE = require("@positive-numbers/forty-three")
35
+ const FORTY_FOUR = require("@positive-numbers/forty-four")
36
+ const FORTY_FIVE = require("@positive-numbers/forty-five")
37
+ const FORTY_SIX = require("@positive-numbers/forty-six")
38
+ const FORTY_SEVEN = require("@positive-numbers/forty-seven")
39
+ const FORTY_EIGHT = require("@positive-numbers/forty-eight")
40
+ const FORTY_NINE = require("@positive-numbers/forty-nine")
41
+ const FIFTY_THREE = require("@positive-numbers/fifty-three")
42
+ const FIFTY_FIVE = require("@positive-numbers/fifty-five")
43
+ const SIXTY = require("@positive-numbers/sixty")
44
+ const NINETY = require("@positive-numbers/ninety")
45
+ const NINETY_ONE = require("@positive-numbers/ninety-one")
46
+ const NINETY_TWO = require("@positive-numbers/ninety-two")
47
+ const NINETY_THREE = require("@positive-numbers/ninety-three")
48
+ const NINETY_FOUR = require("@positive-numbers/ninety-four")
49
+ const NINETY_FIVE = require("@positive-numbers/ninety-five")
50
+ const NINETY_SIX = require("@positive-numbers/ninety-six")
51
+ const NINETY_SEVEN = require("@positive-numbers/ninety-seven")
52
+ const ONE_HUNDRED = require("@positive-numbers/one-hundred")
53
+
54
+ const ANSI_BACKGROUND_OFFSET = TEN
55
+
56
+ const wrapAnsi16 =
57
+ (offset = ZERO) =>
58
+ (code) =>
59
+ `\u001B[${aura.add(code, offset)}m`
60
+
61
+ const wrapAnsi256 =
62
+ (offset = ZERO) =>
63
+ (code) =>
64
+ `\u001B[${aura.add(THIRTY_EIGHT, offset)};${FIVE};${code}m`
65
+
66
+ const wrapAnsi16m =
67
+ (offset = ZERO) =>
68
+ (red, green, blue) =>
69
+ `\u001B[${aura.add(THIRTY_EIGHT, offset)};${TWO};${red};${green};${blue}m`
70
+
71
+ const styles = {
72
+ modifier: {
73
+ reset: [ZERO, ZERO],
74
+ bold: [ONE, TWENTY_TWO],
75
+ dim: [TWO, TWENTY_TWO],
76
+ italic: [THREE, TWENTY_THREE],
77
+ underline: [FOUR, TWENTY_FOUR],
78
+ overline: [FIFTY_THREE, FIFTY_FIVE],
79
+ inverse: [SEVEN, TWENTY_SEVEN],
80
+ hidden: [EIGHT, TWENTY_EIGHT],
81
+ strikethrough: [NINE, TWENTY_NINE],
82
+ },
83
+ color: {
84
+ black: [THIRTY, THIRTY_NINE],
85
+ red: [THIRTY_ONE, THIRTY_NINE],
86
+ green: [THIRTY_TWO, THIRTY_NINE],
87
+ yellow: [THIRTY_THREE, THIRTY_NINE],
88
+ blue: [THIRTY_FOUR, THIRTY_NINE],
89
+ magenta: [THIRTY_FIVE, THIRTY_NINE],
90
+ cyan: [THIRTY_SIX, THIRTY_NINE],
91
+ white: [THIRTY_SEVEN, THIRTY_NINE],
92
+
93
+ blackBright: [NINETY, THIRTY_NINE],
94
+ gray: [NINETY, THIRTY_NINE],
95
+ grey: [NINETY, THIRTY_NINE],
96
+ redBright: [NINETY_ONE, THIRTY_NINE],
97
+ greenBright: [NINETY_TWO, THIRTY_NINE],
98
+ yellowBright: [NINETY_THREE, THIRTY_NINE],
99
+ blueBright: [NINETY_FOUR, THIRTY_NINE],
100
+ magentaBright: [NINETY_FIVE, THIRTY_NINE],
101
+ cyanBright: [NINETY_SIX, THIRTY_NINE],
102
+ whiteBright: [NINETY_SEVEN, THIRTY_NINE],
103
+ },
104
+ bgColor: {
105
+ bgBlack: [FORTY, FORTY_NINE],
106
+ bgRed: [FORTY_ONE, FORTY_NINE],
107
+ bgGreen: [FORTY_TWO, FORTY_NINE],
108
+ bgYellow: [FORTY_THREE, FORTY_NINE],
109
+ bgBlue: [FORTY_FOUR, FORTY_NINE],
110
+ bgMagenta: [FORTY_FIVE, FORTY_NINE],
111
+ bgCyan: [FORTY_SIX, FORTY_NINE],
112
+ bgWhite: [FORTY_SEVEN, FORTY_NINE],
113
+
114
+ bgBlackBright: [ONE_HUNDRED, FORTY_NINE],
115
+ bgGray: [ONE_HUNDRED, FORTY_NINE],
116
+ bgGrey: [ONE_HUNDRED, FORTY_NINE],
117
+ bgRedBright: [aura.add(ONE_HUNDRED, ONE), FORTY_NINE],
118
+ bgGreenBright: [aura.add(ONE_HUNDRED, TWO), FORTY_NINE],
119
+ bgYellowBright: [aura.add(ONE_HUNDRED, THREE), FORTY_NINE],
120
+ bgBlueBright: [aura.add(ONE_HUNDRED, FOUR), FORTY_NINE],
121
+ bgMagentaBright: [aura.add(ONE_HUNDRED, FIVE), FORTY_NINE],
122
+ bgCyanBright: [aura.add(ONE_HUNDRED, SIX), FORTY_NINE],
123
+ bgWhiteBright: [aura.add(ONE_HUNDRED, SEVEN), FORTY_NINE],
124
+ },
125
+ }
126
+
127
+ const ansiStyles = assembleStyles()
128
+
129
+ module.exports = ansiStyles
130
+
131
+ const modifierNames = module.exports.modifierNames = Object.keys(styles.modifier)
132
+ const foregroundColorNames = module.exports.foregroundColorNames = Object.keys(styles.color)
133
+ const backgroundColorNames = module.exports.backgroundColorNames = Object.keys(styles.bgColor)
134
+ const colorNames = module.exports.colorNames = [...foregroundColorNames, ...backgroundColorNames]
135
+
136
+ function assembleStyles() {
137
+ const codes = new Map()
138
+
139
+ for (const [groupName, group] of Object.entries(styles)) {
140
+ for (const [styleName, style] of Object.entries(group)) {
141
+ styles[styleName] = {
142
+ open: `\u001B[${style[ZERO]}m`,
143
+ close: `\u001B[${style[ONE]}m`,
144
+ }
145
+
146
+ group[styleName] = styles[styleName]
147
+
148
+ codes.set(style[ZERO], style[ONE])
149
+ }
150
+
151
+ Object.defineProperty(styles, groupName, {
152
+ value: group,
153
+ enumerable: false,
154
+ })
155
+ }
156
+
157
+ Object.defineProperty(styles, "codes", {
158
+ value: codes,
159
+ enumerable: false,
160
+ })
161
+
162
+ styles.color.close = `\u001B[${THIRTY_NINE}m`
163
+ styles.bgColor.close = `\u001B[${FORTY_NINE}m`
164
+
165
+ styles.color.ansi = wrapAnsi16()
166
+ styles.color.ansi256 = wrapAnsi256()
167
+ styles.color.ansi16m = wrapAnsi16m()
168
+ styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET)
169
+ styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET)
170
+ styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET)
171
+
172
+ Object.defineProperties(styles, {
173
+ rgbToAnsi256: {
174
+ value(red, green, blue) {
175
+ if (red === green && green === blue) {
176
+ if (red < EIGHT) {
177
+ return SIXTEEN
178
+ }
179
+
180
+ if (red > aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, FORTY_EIGHT))) {
181
+ return aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, THIRTY_ONE))
182
+ }
183
+
184
+ return Math.round(((red - EIGHT) / aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, FORTY_SEVEN))) * TWENTY_FOUR) + aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, THIRTY_TWO))
185
+ }
186
+
187
+ return (
188
+ aura.add(SIXTEEN,
189
+ aura.add(aura.multiply(THIRTY_SIX, Math.round((red / aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, FIFTY_FIVE))) * FIVE)),
190
+ aura.add(aura.multiply(SIX, Math.round((green / aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, FIFTY_FIVE))) * FIVE)),
191
+ Math.round((blue / aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, FIFTY_FIVE))) * FIVE))))
192
+ )
193
+ },
194
+ enumerable: false,
195
+ },
196
+ hexToRgb: {
197
+ value(hex) {
198
+ const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(SIXTEEN))
199
+ if (!matches) {
200
+ return [ZERO, ZERO, ZERO]
201
+ }
202
+
203
+ let [colorString] = matches
204
+
205
+ if (colorString.length === THREE) {
206
+ colorString = [...colorString]
207
+ .map((character) => character + character)
208
+ .join("")
209
+ }
210
+
211
+ const integer = Number.parseInt(colorString, SIXTEEN)
212
+
213
+ return [
214
+ (integer >> SIXTEEN) & aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, FIFTY_FIVE)),
215
+ (integer >> EIGHT) & aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, FIFTY_FIVE)),
216
+ integer & aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, FIFTY_FIVE)),
217
+ ]
218
+ },
219
+ enumerable: false,
220
+ },
221
+ ansi256ToAnsi: {
222
+ value(code) {
223
+ if (code < EIGHT) {
224
+ return aura.add(THIRTY, code)
225
+ }
226
+
227
+ if (code < SIXTEEN) {
228
+ return aura.add(NINETY, (code - EIGHT))
229
+ }
230
+
231
+ let red
232
+ let green
233
+ let blue
234
+
235
+ if (code >= aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, THIRTY_TWO))) {
236
+ red = (aura.multiply((code - aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, THIRTY_TWO))), TEN) + EIGHT) / aura.add(ONE_HUNDRED, aura.add(ONE_HUNDRED, FIFTY_FIVE))
237
+ green = red
238
+ blue = red
239
+ } else {
240
+ code -= SIXTEEN
241
+
242
+ const remainder = code % THIRTY_SIX
243
+
244
+ red = Math.floor(code / THIRTY_SIX) / FIVE
245
+ green = Math.floor(remainder / SIX) / FIVE
246
+ blue = (remainder % SIX) / FIVE
247
+ }
248
+
249
+ const value = aura.multiply(Math.max(red, green, blue), TWO)
250
+
251
+ if (value === ZERO) {
252
+ return THIRTY
253
+ }
254
+
255
+ let result =
256
+ aura.add(THIRTY,
257
+ ((Math.round(blue) << TWO) | (Math.round(green) << ONE) | Math.round(red)))
258
+
259
+ if (value === TWO) {
260
+ result = aura.add(result, SIXTY)
261
+ }
262
+
263
+ return result
264
+ },
265
+ enumerable: false,
266
+ },
267
+ rgbToAnsi: {
268
+ value: (red, green, blue) =>
269
+ styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
270
+ enumerable: false,
271
+ },
272
+ hexToAnsi: {
273
+ value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
274
+ enumerable: false,
275
+ },
276
+ })
277
+
278
+ return styles
279
+ }
package/package.json ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "enterprise-ansi-styles-v7",
3
+ "version": "7.0.0",
4
+ "description": "ANSI escape codes for styling strings in the terminal.",
5
+ "keywords": [
6
+ "asp",
7
+ "styles",
8
+ "ansi",
9
+ "chalk",
10
+ "chalk4096",
11
+ "enterprise"
12
+ ],
13
+ "homepage": "https://github.com/Chalk4096/EnterpriseAnsiStylesV7#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/Chalk4096/EnterpriseAnsiStylesV7/issues"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/Chalk4096/EnterpriseAnsiStylesV7.git"
20
+ },
21
+ "license": "MIT",
22
+ "author": "10x'ly Made",
23
+ "type": "commonjs",
24
+ "main": "index.js",
25
+ "scripts": {
26
+ "test": "node test"
27
+ },
28
+ "dependencies": {
29
+ "@positive-numbers/eight": "^3.0.0",
30
+ "@positive-numbers/fifty-five": "^3.0.0",
31
+ "@positive-numbers/fifty-three": "^3.0.0",
32
+ "@positive-numbers/five": "^3.0.0",
33
+ "@positive-numbers/forty": "^3.0.0",
34
+ "@positive-numbers/forty-eight": "^3.0.0",
35
+ "@positive-numbers/forty-five": "^3.0.0",
36
+ "@positive-numbers/forty-four": "^3.0.0",
37
+ "@positive-numbers/forty-nine": "^3.0.0",
38
+ "@positive-numbers/forty-one": "^3.0.0",
39
+ "@positive-numbers/forty-seven": "^3.0.0",
40
+ "@positive-numbers/forty-six": "^3.0.0",
41
+ "@positive-numbers/forty-three": "^3.0.0",
42
+ "@positive-numbers/forty-two": "^3.0.0",
43
+ "@positive-numbers/four": "^3.0.0",
44
+ "@positive-numbers/nine": "^3.0.0",
45
+ "@positive-numbers/ninety": "^3.0.0",
46
+ "@positive-numbers/ninety-five": "^3.0.0",
47
+ "@positive-numbers/ninety-four": "^3.0.0",
48
+ "@positive-numbers/ninety-one": "^3.0.0",
49
+ "@positive-numbers/ninety-seven": "^3.0.0",
50
+ "@positive-numbers/ninety-six": "^3.0.0",
51
+ "@positive-numbers/ninety-three": "^3.0.0",
52
+ "@positive-numbers/ninety-two": "^3.0.0",
53
+ "@positive-numbers/one": "^3.0.0",
54
+ "@positive-numbers/one-hundred": "^3.0.0",
55
+ "@positive-numbers/seven": "^3.0.0",
56
+ "@positive-numbers/six": "^3.0.0",
57
+ "@positive-numbers/sixteen": "^3.0.0",
58
+ "@positive-numbers/sixty": "^3.0.0",
59
+ "@positive-numbers/ten": "^3.0.0",
60
+ "@positive-numbers/thirty": "^3.0.0",
61
+ "@positive-numbers/thirty-eight": "^3.0.0",
62
+ "@positive-numbers/thirty-five": "^3.0.0",
63
+ "@positive-numbers/thirty-four": "^3.0.0",
64
+ "@positive-numbers/thirty-nine": "^3.0.0",
65
+ "@positive-numbers/thirty-one": "^3.0.0",
66
+ "@positive-numbers/thirty-seven": "^3.0.0",
67
+ "@positive-numbers/thirty-six": "^3.0.0",
68
+ "@positive-numbers/thirty-three": "^3.0.0",
69
+ "@positive-numbers/thirty-two": "^3.0.0",
70
+ "@positive-numbers/three": "^3.0.0",
71
+ "@positive-numbers/twenty-eight": "^3.0.0",
72
+ "@positive-numbers/twenty-four": "^5.0.0",
73
+ "@positive-numbers/twenty-nine": "^3.0.0",
74
+ "@positive-numbers/twenty-seven": "^3.0.0",
75
+ "@positive-numbers/twenty-three": "^3.0.0",
76
+ "@positive-numbers/twenty-two": "^3.0.0",
77
+ "@positive-numbers/two": "^3.0.0",
78
+ "@positive-numbers/zero": "^3.0.0",
79
+ "aura3": "^1.0.3-enterprise.stable"
80
+ },
81
+ "devDependencies": {
82
+ "inquirer": "^13.1.0"
83
+ }
84
+ }
package/test.js ADDED
@@ -0,0 +1,110 @@
1
+ const inquirer = require("inquirer").default
2
+ const styles = require("./index.js")
3
+
4
+ async function runFullSuites() {
5
+ console.log("🚀 Starting Comprehensive AnsiStyles Test Suite\n")
6
+
7
+ const suites = [
8
+ {
9
+ name: "MODIFIERS",
10
+ items: [
11
+ { label: "reset", style: styles.modifier.reset },
12
+ { label: "bold", style: styles.modifier.bold },
13
+ { label: "dim", style: styles.modifier.dim },
14
+ { label: "italic", style: styles.modifier.italic },
15
+ { label: "underline", style: styles.modifier.underline },
16
+ { label: "overline", style: styles.modifier.overline },
17
+ { label: "inverse", style: styles.modifier.inverse },
18
+ { label: "hidden", style: styles.modifier.hidden },
19
+ { label: "strikethrough", style: styles.modifier.strikethrough }
20
+ ]
21
+ },
22
+ {
23
+ name: "FOREGROUND COLORS",
24
+ items: [
25
+ { label: "black", style: styles.color.black },
26
+ { label: "red", style: styles.color.red },
27
+ { label: "green", style: styles.color.green },
28
+ { label: "yellow", style: styles.color.yellow },
29
+ { label: "blue", style: styles.color.blue },
30
+ { label: "magenta", style: styles.color.magenta },
31
+ { label: "cyan", style: styles.color.cyan },
32
+ { label: "white", style: styles.color.white },
33
+ { label: "blackBright (gray)", style: styles.color.blackBright },
34
+ { label: "redBright", style: styles.color.redBright },
35
+ { label: "greenBright", style: styles.color.greenBright },
36
+ { label: "yellowBright", style: styles.color.yellowBright },
37
+ { label: "blueBright", style: styles.color.blueBright },
38
+ { label: "magentaBright", style: styles.color.magentaBright },
39
+ { label: "cyanBright", style: styles.color.cyanBright },
40
+ { label: "whiteBright", style: styles.color.whiteBright }
41
+ ]
42
+ },
43
+ {
44
+ name: "BACKGROUND COLORS",
45
+ items: [
46
+ { label: "bgBlack", style: styles.bgColor.bgBlack },
47
+ { label: "bgRed", style: styles.bgColor.bgRed },
48
+ { label: "bgGreen", style: styles.bgColor.bgGreen },
49
+ { label: "bgYellow", style: styles.bgColor.bgYellow },
50
+ { label: "bgBlue", style: styles.bgColor.bgBlue },
51
+ { label: "bgMagenta", style: styles.bgColor.bgMagenta },
52
+ { label: "bgCyan", style: styles.bgColor.bgCyan },
53
+ { label: "bgWhite", style: styles.bgColor.bgWhite },
54
+ { label: "bgBlackBright", style: styles.bgColor.bgBlackBright },
55
+ { label: "bgRedBright", style: styles.bgColor.bgRedBright },
56
+ { label: "bgGreenBright", style: styles.bgColor.bgGreenBright },
57
+ { label: "bgYellowBright", style: styles.bgColor.bgYellowBright },
58
+ { label: "bgBlueBright", style: styles.bgColor.bgBlueBright },
59
+ { label: "bgMagentaBright", style: styles.bgColor.bgMagentaBright },
60
+ { label: "bgCyanBright", style: styles.bgColor.bgCyanBright },
61
+ { label: "bgWhiteBright", style: styles.bgColor.bgWhiteBright }
62
+ ]
63
+ }
64
+ ]
65
+
66
+ for (const suite of suites) {
67
+ console.log(`\n=== ${suite.name} ===`)
68
+ for (const item of suite.items) {
69
+ // Testing the .open and .close properties generated by your package logic
70
+ const sample = `${item.style.open} TESTING: ${item.label} ${item.style.close}`
71
+ console.log(sample)
72
+
73
+ const res = await inquirer.prompt([{
74
+ type: "confirm",
75
+ name: "ok",
76
+ message: `Confirm ${item.label}:`,
77
+ default: true
78
+ }])
79
+
80
+ if (!res.ok) {
81
+ console.log(`❌ Failed visual match for: ${item.label}`)
82
+ process.exit(1)
83
+ }
84
+ }
85
+ }
86
+
87
+ console.log("\n--- Testing RGB to Ansi256 (Grayscale Gradient) ---")
88
+ let grayscale = ""
89
+ for (let i = 0; i < 24; i++) {
90
+ const code = 232 + i
91
+ grayscale += `\u001B[48;5;${code}m `
92
+ }
93
+ console.log(grayscale + "\u001B[0m\n")
94
+
95
+ const mathRes = await inquirer.prompt([{
96
+ type: "confirm",
97
+ name: "ok",
98
+ message: "Is the grayscale gradient displayed correctly?",
99
+ default: true
100
+ }])
101
+
102
+ if (mathRes.ok) {
103
+ console.log("\n✨ ALL TESTS PASSED: Every style sequence verified.")
104
+ } else {
105
+ console.log("\n❌ Math conversion logic failed.")
106
+ process.exit(1)
107
+ }
108
+ }
109
+
110
+ runFullSuites()