@vitest/utils
Advanced tools
Comparing version 0.31.4 to 0.32.0
import { notNullish, isPrimitive } from './helpers.js'; | ||
export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isObject, noop, objectAttr, parseRegexp, slash, toArray } from './helpers.js'; | ||
import { format as format$1, plugins } from 'pretty-format'; | ||
export { f as format, l as loupeInspect, o as objDisplay, s as stringify, u as utilInspect } from './chunk-display.js'; | ||
import { S as SAFE_TIMERS_SYMBOL } from './chunk-colors.js'; | ||
export { a as SAFE_COLORS_SYMBOL, c as createColors, b as getColors, g as getDefaultColors, s as setupColors } from './chunk-colors.js'; | ||
import util from 'util'; | ||
import loupeImport from 'loupe'; | ||
import 'pretty-format'; | ||
import 'util'; | ||
import 'loupe'; | ||
const { | ||
AsymmetricMatcher, | ||
DOMCollection, | ||
DOMElement, | ||
Immutable, | ||
ReactElement, | ||
ReactTestComponent | ||
} = plugins; | ||
const PLUGINS = [ | ||
ReactTestComponent, | ||
ReactElement, | ||
DOMElement, | ||
DOMCollection, | ||
Immutable, | ||
AsymmetricMatcher | ||
]; | ||
function stringify(object, maxDepth = 10, { maxLength, ...options } = {}) { | ||
const MAX_LENGTH = maxLength ?? 1e4; | ||
let result; | ||
try { | ||
result = format$1(object, { | ||
maxDepth, | ||
escapeString: false, | ||
// min: true, | ||
plugins: PLUGINS, | ||
...options | ||
}); | ||
} catch { | ||
result = format$1(object, { | ||
callToJSON: false, | ||
maxDepth, | ||
escapeString: false, | ||
// min: true, | ||
plugins: PLUGINS, | ||
...options | ||
}); | ||
} | ||
return result.length >= MAX_LENGTH && maxDepth > 1 ? stringify(object, Math.floor(maxDepth / 2)) : result; | ||
} | ||
function getSafeTimers() { | ||
@@ -112,36 +73,2 @@ const { | ||
const loupe = typeof loupeImport.default === "function" ? loupeImport.default : loupeImport; | ||
function format(...args) { | ||
return util.format(...args); | ||
} | ||
function utilInspect(item, options) { | ||
return util.inspect(item, options); | ||
} | ||
function loupeInspect(obj, options = {}) { | ||
return loupe(obj, { | ||
depth: 2, | ||
truncate: options.truncateThreshold === 0 ? Infinity : options.truncateThreshold ?? 40 | ||
}); | ||
} | ||
function objDisplay(obj, options = {}) { | ||
const truncateThreshold = options.truncateThreshold ?? 40; | ||
const str = loupeInspect(obj, options); | ||
const type = Object.prototype.toString.call(obj); | ||
if (truncateThreshold && str.length >= truncateThreshold) { | ||
if (type === "[object Function]") { | ||
const fn = obj; | ||
return !fn.name || fn.name === "" ? "[Function]" : `[Function: ${fn.name}]`; | ||
} else if (type === "[object Array]") { | ||
return `[ Array(${obj.length}) ]`; | ||
} else if (type === "[object Object]") { | ||
const keys = Object.keys(obj); | ||
const kstr = keys.length > 2 ? `${keys.splice(0, 2).join(", ")}, ...` : keys.join(", "); | ||
return `{ Object (${kstr}) }`; | ||
} else { | ||
return str; | ||
} | ||
} | ||
return str; | ||
} | ||
function createSimpleStackTrace(options) { | ||
@@ -348,2 +275,2 @@ const { message = "error", stackTraceLimit = 1 } = options || {}; | ||
export { SAFE_TIMERS_SYMBOL, createSimpleStackTrace, format, getSafeTimers, isPrimitive, lineSplitRE, loupeInspect, notNullish, objDisplay, offsetToLineNumber, parseErrorStacktrace, parseSingleStack, parseStacktrace, positionToOffset, setSafeTimers, shuffle, stringify, utilInspect }; | ||
export { SAFE_TIMERS_SYMBOL, createSimpleStackTrace, getSafeTimers, isPrimitive, lineSplitRE, notNullish, offsetToLineNumber, parseErrorStacktrace, parseSingleStack, parseStacktrace, positionToOffset, setSafeTimers, shuffle }; |
import { notNullish, isPrimitive } from './helpers.js'; | ||
export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isObject, noop, objectAttr, parseRegexp, slash, toArray } from './helpers.js'; | ||
import { format as format$1, plugins } from 'pretty-format'; | ||
export { f as format, l as loupeInspect, o as objDisplay, s as stringify, u as utilInspect } from './chunk-display.js'; | ||
import { S as SAFE_TIMERS_SYMBOL } from './chunk-colors.js'; | ||
export { a as SAFE_COLORS_SYMBOL, c as createColors, b as getColors, g as getDefaultColors, s as setupColors } from './chunk-colors.js'; | ||
import util from 'util'; | ||
import loupeImport from 'loupe'; | ||
import 'pretty-format'; | ||
import 'util'; | ||
import 'loupe'; | ||
const { | ||
AsymmetricMatcher, | ||
DOMCollection, | ||
DOMElement, | ||
Immutable, | ||
ReactElement, | ||
ReactTestComponent | ||
} = plugins; | ||
const PLUGINS = [ | ||
ReactTestComponent, | ||
ReactElement, | ||
DOMElement, | ||
DOMCollection, | ||
Immutable, | ||
AsymmetricMatcher | ||
]; | ||
function stringify(object, maxDepth = 10, { maxLength, ...options } = {}) { | ||
const MAX_LENGTH = maxLength ?? 1e4; | ||
let result; | ||
try { | ||
result = format$1(object, { | ||
maxDepth, | ||
escapeString: false, | ||
// min: true, | ||
plugins: PLUGINS, | ||
...options | ||
}); | ||
} catch { | ||
result = format$1(object, { | ||
callToJSON: false, | ||
maxDepth, | ||
escapeString: false, | ||
// min: true, | ||
plugins: PLUGINS, | ||
...options | ||
}); | ||
} | ||
return result.length >= MAX_LENGTH && maxDepth > 1 ? stringify(object, Math.floor(maxDepth / 2)) : result; | ||
} | ||
function getSafeTimers() { | ||
@@ -112,36 +73,2 @@ const { | ||
const loupe = typeof loupeImport.default === "function" ? loupeImport.default : loupeImport; | ||
function format(...args) { | ||
return util.format(...args); | ||
} | ||
function utilInspect(item, options) { | ||
return util.inspect(item, options); | ||
} | ||
function loupeInspect(obj, options = {}) { | ||
return loupe(obj, { | ||
depth: 2, | ||
truncate: options.truncateThreshold === 0 ? Infinity : options.truncateThreshold ?? 40 | ||
}); | ||
} | ||
function objDisplay(obj, options = {}) { | ||
const truncateThreshold = options.truncateThreshold ?? 40; | ||
const str = loupeInspect(obj, options); | ||
const type = Object.prototype.toString.call(obj); | ||
if (truncateThreshold && str.length >= truncateThreshold) { | ||
if (type === "[object Function]") { | ||
const fn = obj; | ||
return !fn.name || fn.name === "" ? "[Function]" : `[Function: ${fn.name}]`; | ||
} else if (type === "[object Array]") { | ||
return `[ Array(${obj.length}) ]`; | ||
} else if (type === "[object Object]") { | ||
const keys = Object.keys(obj); | ||
const kstr = keys.length > 2 ? `${keys.splice(0, 2).join(", ")}, ...` : keys.join(", "); | ||
return `{ Object (${kstr}) }`; | ||
} else { | ||
return str; | ||
} | ||
} | ||
return str; | ||
} | ||
function createSimpleStackTrace(options) { | ||
@@ -348,2 +275,2 @@ const { message = "error", stackTraceLimit = 1 } = options || {}; | ||
export { SAFE_TIMERS_SYMBOL, createSimpleStackTrace, format, getSafeTimers, isPrimitive, lineSplitRE, loupeInspect, notNullish, objDisplay, offsetToLineNumber, parseErrorStacktrace, parseSingleStack, parseStacktrace, positionToOffset, setSafeTimers, shuffle, stringify, utilInspect }; | ||
export { SAFE_TIMERS_SYMBOL, createSimpleStackTrace, getSafeTimers, isPrimitive, lineSplitRE, notNullish, offsetToLineNumber, parseErrorStacktrace, parseSingleStack, parseStacktrace, positionToOffset, setSafeTimers, shuffle }; |
{ | ||
"name": "@vitest/utils", | ||
"type": "module", | ||
"version": "0.31.4", | ||
"version": "0.32.0", | ||
"description": "Shared Vitest utility functions", | ||
@@ -27,2 +27,6 @@ "license": "MIT", | ||
}, | ||
"./error": { | ||
"types": "./dist/error.d.ts", | ||
"import": "./dist/error.js" | ||
}, | ||
"./helpers": { | ||
@@ -29,0 +33,0 @@ "types": "./dist/helpers.d.ts", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46471
18
1277