get-abbreviated-display-val.js 768 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * Module dependencies
  3. */
  4. var util = require('util');
  5. var _ = require('@sailshq/lodash');
  6. var getDisplayType = require('../get-display-type');
  7. /**
  8. * getAbbreviatedDisplayVal()
  9. *
  10. * A helper function that displays a short, human-readable
  11. * version of a value. Handy for e.g. legible test output.
  12. *
  13. * @param {===} v
  14. * @return {String} [short human-readable display value]
  15. */
  16. module.exports = function getAbbreviatedDisplayVal(v){
  17. if (_.isDate(v)) {
  18. return 'a Date';
  19. }
  20. if (_.isFunction(v)) {
  21. return v.toString();
  22. }
  23. if (_.isError(v)) {
  24. return 'an Error';
  25. }
  26. if (_.isRegExp(v)) {
  27. return 'a RegExp';
  28. }
  29. if (!_.isPlainObject(v) && !_.isArray(v)) {
  30. return getDisplayType(v);
  31. }
  32. return util.inspect(v,false,null);
  33. };