Sha256: ae2fda6a0c563a19f7351bc4ff2c1ae272de56a861ee1148ddf4d888cac9789e

Contents?: true

Size: 1.09 KB

Versions: 100

Compression:

Stored size: 1.09 KB

Contents

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

/*!
 * Module dependancies
 */

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

/**
 * ### .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 (str.length >= 40) {
    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

100 entries across 68 versions & 1 rubygems

Version Path
ende-0.4.25 vendor/components/indefinido-observable/components/chaijs-chai/lib/chai/utils/objDisplay.js
ende-0.4.25 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/objDisplay.js
ende-0.4.24 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/objDisplay.js
ende-0.4.24 vendor/components/indefinido-observable/components/chaijs-chai/lib/chai/utils/objDisplay.js
ende-0.4.23 vendor/components/indefinido-observable/components/chaijs-chai/lib/chai/utils/objDisplay.js
ende-0.4.23 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/objDisplay.js
ende-0.5.1 components/indefinido/indemma/master/components/chaijs-chai/lib/chai/utils/objDisplay.js
ende-0.4.22 vendor/components/indefinido-observable/components/chaijs-chai/lib/chai/utils/objDisplay.js
ende-0.4.22 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/objDisplay.js
ende-0.4.21 vendor/components/indefinido-observable/components/chaijs-chai/lib/chai/utils/objDisplay.js
ende-0.4.21 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/objDisplay.js
ende-0.5.0 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/objDisplay.js
ende-0.4.20 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/objDisplay.js
ende-0.4.19 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/objDisplay.js
ende-0.4.18 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/objDisplay.js
ende-0.4.17 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/objDisplay.js
ende-0.4.16 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/objDisplay.js
ende-0.3.13 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/objDisplay.js
ende-0.3.12 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/objDisplay.js
ende-0.3.11 vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/objDisplay.js