MCPcopy
hub / github.com/vitest-dev/vitest / objDisplay

Function objDisplay

packages/utils/src/display.ts:251–279  ·  view source on GitHub ↗
(obj: unknown, options: LoupeOptions = {})

Source from the content-addressed store, hash-verified

249}
250
251export function objDisplay(obj: unknown, options: LoupeOptions = {}): string {
252 if (typeof options.truncate === 'undefined') {
253 options.truncate = 40
254 }
255 const str = inspect(obj, options)
256 const type = Object.prototype.toString.call(obj)
257
258 if (options.truncate && str.length >= options.truncate) {
259 if (type === '[object Function]') {
260 const fn = obj as () => void
261 return !fn.name ? '[Function]' : `[Function: ${fn.name}]`
262 }
263 else if (type === '[object Array]') {
264 return `[ Array(${(obj as []).length}) ]`
265 }
266 else if (type === '[object Object]') {
267 const keys = Object.keys(obj as object)
268 const kstr
269 = keys.length > 2
270 ? `${keys.splice(0, 2).join(', ')}, ...`
271 : keys.join(', ')
272 return `{ Object (${kstr}) }`
273 }
274 else {
275 return str
276 }
277 }
278 return str
279}

Callers 2

formatAttributeFunction · 0.90
utils.spec.tsFile · 0.90

Calls 2

inspectFunction · 0.85
keysMethod · 0.80

Tested by

no test coverage detected