UNPKG

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