Sha256: aff7afa862352598ca2a658fb6ec2064f4016989b2b091c87ef55684b14a04bd
Contents?: true
Size: 1.2 KB
Versions: 26
Compression:
Stored size: 1.2 KB
Contents
/*! * Chai - flag utility * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com> * MIT Licensed */ import {inspect} from './inspect.js'; import {config} from '../config.js'; /** * ### .objDisplay(object) * * Determines if an object or an array matches * criteria to be inspected in-line for error * messages or should be truncated. * * @param {unknown} obj javascript object to inspect * @returns {string} stringified object * @name objDisplay * @namespace Utils * @public */ export function objDisplay(obj) { var str = inspect(obj) , type = Object.prototype.toString.call(obj); if (config.truncateThreshold && str.length >= config.truncateThreshold) { if (type === '[object Function]') { return !obj.name || obj.name === '' ? '[Function]' : '[Function: ' + obj.name + ']'; } else if (type === '[object Array]') { return '[ Array(' + obj.length + ') ]'; } else if (type === '[object Object]') { var keys = Object.keys(obj) , kstr = keys.length > 2 ? keys.splice(0, 2).join(', ') + ', ...' : keys.join(', '); return '{ Object (' + kstr + ') }'; } else { return str; } } else { return str; } }
Version data entries
26 entries across 26 versions & 1 rubygems