show.js 432 B

12345678910111213
  1. 'use strict';
  2. const is = require('is-type-of');
  3. module.exports = function show(obj) {
  4. const type = {}.toString.call(obj).replace(/^\[object (.*)\]$/, '$1');
  5. if (is.buffer(obj)) obj = obj.toString();
  6. // escape \n to \\n for good view in terminal
  7. if (is.string(obj)) obj = obj.replace(/\n/g, '\\n');
  8. // stringify if object
  9. if (!is.regexp(obj) && is.object(obj)) obj = JSON.stringify(obj);
  10. return `${obj}(${type})`;
  11. };