@vitest/utils 0.29.2 → 0.29.3

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/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  export { assertTypes, clone, createDefer, deepClone, getOwnProperties, getType, isObject, noop, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
2
2
  export { ArgumentsType, Arrayable, Awaitable, Constructable, DeepMerge, MergeInsertions, MutableArray, Nullable } from './types.js';
3
3
  import { PrettyFormatOptions } from 'pretty-format';
4
- import p from 'picocolors';
5
4
 
6
5
  declare function stringify(object: unknown, maxDepth?: number, { maxLength, ...options }?: PrettyFormatOptions & {
7
6
  maxLength?: number;
@@ -27,8 +26,44 @@ declare function objDisplay(obj: unknown): string;
27
26
  declare const SAFE_TIMERS_SYMBOL: unique symbol;
28
27
  declare const SAFE_COLORS_SYMBOL: unique symbol;
29
28
 
30
- declare function getColors(): typeof p;
31
- declare function setColors(colors: typeof p): void;
29
+ declare const colorsMap: {
30
+ readonly bold: readonly ["\u001B[1m", "\u001B[22m", "\u001B[22m\u001B[1m"];
31
+ readonly dim: readonly ["\u001B[2m", "\u001B[22m", "\u001B[22m\u001B[2m"];
32
+ readonly italic: readonly ["\u001B[3m", "\u001B[23m"];
33
+ readonly underline: readonly ["\u001B[4m", "\u001B[24m"];
34
+ readonly inverse: readonly ["\u001B[7m", "\u001B[27m"];
35
+ readonly hidden: readonly ["\u001B[8m", "\u001B[28m"];
36
+ readonly strikethrough: readonly ["\u001B[9m", "\u001B[29m"];
37
+ readonly black: readonly ["\u001B[30m", "\u001B[39m"];
38
+ readonly red: readonly ["\u001B[31m", "\u001B[39m"];
39
+ readonly green: readonly ["\u001B[32m", "\u001B[39m"];
40
+ readonly yellow: readonly ["\u001B[33m", "\u001B[39m"];
41
+ readonly blue: readonly ["\u001B[34m", "\u001B[39m"];
42
+ readonly magenta: readonly ["\u001B[35m", "\u001B[39m"];
43
+ readonly cyan: readonly ["\u001B[36m", "\u001B[39m"];
44
+ readonly white: readonly ["\u001B[37m", "\u001B[39m"];
45
+ readonly gray: readonly ["\u001B[90m", "\u001B[39m"];
46
+ readonly bgBlack: readonly ["\u001B[40m", "\u001B[49m"];
47
+ readonly bgRed: readonly ["\u001B[41m", "\u001B[49m"];
48
+ readonly bgGreen: readonly ["\u001B[42m", "\u001B[49m"];
49
+ readonly bgYellow: readonly ["\u001B[43m", "\u001B[49m"];
50
+ readonly bgBlue: readonly ["\u001B[44m", "\u001B[49m"];
51
+ readonly bgMagenta: readonly ["\u001B[45m", "\u001B[49m"];
52
+ readonly bgCyan: readonly ["\u001B[46m", "\u001B[49m"];
53
+ readonly bgWhite: readonly ["\u001B[47m", "\u001B[49m"];
54
+ };
55
+ type ColorName = keyof typeof colorsMap;
56
+ type ColorsMethods = {
57
+ [Key in ColorName]: (input: unknown) => string;
58
+ };
59
+ type Colors = ColorsMethods & {
60
+ isColorSupported: boolean;
61
+ reset: (input: unknown) => string;
62
+ };
63
+ declare function getDefaultColors(): Colors;
64
+ declare function getColors(): Colors;
65
+ declare function createColors(isTTY?: boolean): Colors;
66
+ declare function setupColors(colors: Colors): void;
32
67
 
33
68
  interface ErrorOptions {
34
69
  message?: string;
@@ -41,4 +76,4 @@ interface ErrorOptions {
41
76
  */
42
77
  declare function createSimpleStackTrace(options?: ErrorOptions): string;
43
78
 
44
- export { SAFE_COLORS_SYMBOL, SAFE_TIMERS_SYMBOL, createSimpleStackTrace, format, getColors, getSafeTimers, inspect, objDisplay, setColors, setSafeTimers, shuffle, stringify };
79
+ export { SAFE_COLORS_SYMBOL, SAFE_TIMERS_SYMBOL, createColors, createSimpleStackTrace, format, getColors, getDefaultColors, getSafeTimers, inspect, objDisplay, setSafeTimers, setupColors, shuffle, stringify };
package/dist/index.js CHANGED
@@ -138,43 +138,75 @@ function objDisplay(obj) {
138
138
  return str;
139
139
  }
140
140
 
141
- const colors = [
142
- "reset",
143
- "bold",
144
- "dim",
145
- "italic",
146
- "underline",
147
- "inverse",
148
- "hidden",
149
- "strikethrough",
150
- "black",
151
- "red",
152
- "green",
153
- "yellow",
154
- "blue",
155
- "magenta",
156
- "cyan",
157
- "white",
158
- "gray",
159
- "bgBlack",
160
- "bgRed",
161
- "bgGreen",
162
- "bgYellow",
163
- "bgBlue",
164
- "bgMagenta",
165
- "bgCyan",
166
- "bgWhite"
167
- ];
168
- const formatter = (str) => String(str);
169
- const defaultColors = colors.reduce((acc, key) => {
170
- acc[key] = formatter;
141
+ const colorsMap = {
142
+ bold: ["\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"],
143
+ dim: ["\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"],
144
+ italic: ["\x1B[3m", "\x1B[23m"],
145
+ underline: ["\x1B[4m", "\x1B[24m"],
146
+ inverse: ["\x1B[7m", "\x1B[27m"],
147
+ hidden: ["\x1B[8m", "\x1B[28m"],
148
+ strikethrough: ["\x1B[9m", "\x1B[29m"],
149
+ black: ["\x1B[30m", "\x1B[39m"],
150
+ red: ["\x1B[31m", "\x1B[39m"],
151
+ green: ["\x1B[32m", "\x1B[39m"],
152
+ yellow: ["\x1B[33m", "\x1B[39m"],
153
+ blue: ["\x1B[34m", "\x1B[39m"],
154
+ magenta: ["\x1B[35m", "\x1B[39m"],
155
+ cyan: ["\x1B[36m", "\x1B[39m"],
156
+ white: ["\x1B[37m", "\x1B[39m"],
157
+ gray: ["\x1B[90m", "\x1B[39m"],
158
+ bgBlack: ["\x1B[40m", "\x1B[49m"],
159
+ bgRed: ["\x1B[41m", "\x1B[49m"],
160
+ bgGreen: ["\x1B[42m", "\x1B[49m"],
161
+ bgYellow: ["\x1B[43m", "\x1B[49m"],
162
+ bgBlue: ["\x1B[44m", "\x1B[49m"],
163
+ bgMagenta: ["\x1B[45m", "\x1B[49m"],
164
+ bgCyan: ["\x1B[46m", "\x1B[49m"],
165
+ bgWhite: ["\x1B[47m", "\x1B[49m"]
166
+ };
167
+ const colorsEntries = Object.entries(colorsMap);
168
+ const string = (str) => String(str);
169
+ string.open = "";
170
+ string.close = "";
171
+ const defaultColors = colorsEntries.reduce((acc, [key]) => {
172
+ acc[key] = string;
171
173
  return acc;
172
174
  }, { isColorSupported: false });
175
+ function getDefaultColors() {
176
+ return { ...defaultColors };
177
+ }
173
178
  function getColors() {
174
179
  return globalThis[SAFE_COLORS_SYMBOL] || defaultColors;
175
180
  }
176
- function setColors(colors2) {
177
- globalThis[SAFE_COLORS_SYMBOL] = colors2;
181
+ function createColors(isTTY = false) {
182
+ const enabled = typeof process !== "undefined" && !("NO_COLOR" in process.env || process.argv.includes("--no-color")) && !("GITHUB_ACTIONS" in process.env) && ("FORCE_COLOR" in process.env || process.argv.includes("--color") || process.platform === "win32" || isTTY && process.env.TERM !== "dumb" || "CI" in process.env);
183
+ const replaceClose = (string2, close, replace, index) => {
184
+ const start = string2.substring(0, index) + replace;
185
+ const end = string2.substring(index + close.length);
186
+ const nextIndex = end.indexOf(close);
187
+ return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end;
188
+ };
189
+ const formatter = (open, close, replace = open) => {
190
+ const fn = (input) => {
191
+ const string2 = String(input);
192
+ const index = string2.indexOf(close, open.length);
193
+ return ~index ? open + replaceClose(string2, close, replace, index) + close : open + string2 + close;
194
+ };
195
+ fn.open = open;
196
+ fn.close = close;
197
+ return fn;
198
+ };
199
+ const colorsObject = {
200
+ isColorSupported: enabled,
201
+ reset: enabled ? (s) => `\x1B[0m${s}\x1B[0m` : string
202
+ };
203
+ for (const [name, formatterArgs] of colorsEntries) {
204
+ colorsObject[name] = enabled ? formatter(...formatterArgs) : string;
205
+ }
206
+ return colorsObject;
207
+ }
208
+ function setupColors(colors) {
209
+ globalThis[SAFE_COLORS_SYMBOL] = colors;
178
210
  }
179
211
 
180
212
  function createSimpleStackTrace(options) {
@@ -190,4 +222,4 @@ function createSimpleStackTrace(options) {
190
222
  return stackTrace;
191
223
  }
192
224
 
193
- export { SAFE_COLORS_SYMBOL, SAFE_TIMERS_SYMBOL, createSimpleStackTrace, format, getColors, getSafeTimers, inspect, objDisplay, setColors, setSafeTimers, shuffle, stringify };
225
+ export { SAFE_COLORS_SYMBOL, SAFE_TIMERS_SYMBOL, createColors, createSimpleStackTrace, format, getColors, getDefaultColors, getSafeTimers, inspect, objDisplay, setSafeTimers, setupColors, shuffle, stringify };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/utils",
3
3
  "type": "module",
4
- "version": "0.29.2",
4
+ "version": "0.29.3",
5
5
  "description": "Shared Vitest utility functions",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -35,7 +35,6 @@
35
35
  "cli-truncate": "^3.1.0",
36
36
  "diff": "^5.1.0",
37
37
  "loupe": "^2.3.6",
38
- "picocolors": "^1.0.0",
39
38
  "pretty-format": "^27.5.1"
40
39
  },
41
40
  "devDependencies": {