Sha256: 22970e457c95d9bcb2c375dd7b2ea1aaa654be72942dc83cc559af79f085ec58

Contents?: true

Size: 1.17 KB

Versions: 8

Compression:

Stored size: 1.17 KB

Contents

/*!
 * Chai - flag utility
 * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
 * MIT Licensed
 */

/*!
 * Module dependancies
 */

var inspect = require('./inspect');
var config = require('../config');

/**
 * ### .objDisplay (object)
 *
 * Determines if an object or an array matches
 * criteria to be inspected in-line for error
 * messages or should be truncated.
 *
 * @param {Mixed} javascript object to inspect
 * @name objDisplay
 * @api public
 */

module.exports = function (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

8 entries across 8 versions & 1 rubygems

Version Path
ende-0.5.22 components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/objDisplay.js
ende-0.5.21 components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/objDisplay.js
ende-0.5.6 components/chaijs/chai/1.9.1/lib/chai/utils/objDisplay.js
ende-0.5.5 components/chaijs/chai/1.9.1/lib/chai/utils/objDisplay.js
ende-0.5.4 components/chaijs/chai/1.9.1/lib/chai/utils/objDisplay.js
ende-0.5.3 components/chaijs/chai/1.9.1/lib/chai/utils/objDisplay.js
ende-0.5.2 components/chaijs/chai/1.9.1/lib/chai/utils/objDisplay.js
ende-0.5.1 components/chaijs/chai/1.9.1/lib/chai/utils/objDisplay.js