MCPcopy Create free account
hub / github.com/RubyLouvre/anu / formatValue

Function formatValue

test/babel.js:10806–10915  ·  view source on GitHub ↗
(ctx, value, recurseTimes)

Source from the content-addressed store, hash-verified

10804 }
10805
10806 function formatValue(ctx, value, recurseTimes) {
10807 // Provide a hook for user-specified inspect functions.
10808 // Check that value is an object with an inspect function on it
10809 if (ctx.customInspect && value && isFunction(value.inspect) &&
10810 // Filter out the util module, it's inspect function is special
10811 value.inspect !== exports.inspect &&
10812 // Also filter out any prototype objects using the circular check.
10813 !(value.constructor && value.constructor.prototype === value)) {
10814 var ret = value.inspect(recurseTimes, ctx);
10815 if (!isString(ret)) {
10816 ret = formatValue(ctx, ret, recurseTimes);
10817 }
10818 return ret;
10819 }
10820
10821 // Primitive types cannot have properties
10822 var primitive = formatPrimitive(ctx, value);
10823 if (primitive) {
10824 return primitive;
10825 }
10826
10827 // Look up the keys of the object.
10828 var keys = Object.keys(value);
10829 var visibleKeys = arrayToHash(keys);
10830
10831 if (ctx.showHidden) {
10832 keys = Object.getOwnPropertyNames(value);
10833 }
10834
10835 // IE doesn't make error fields non-enumerable
10836 // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
10837 if (isError(value) && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
10838 return formatError(value);
10839 }
10840
10841 // Some type of object without properties can be shortcutted.
10842 if (keys.length === 0) {
10843 if (isFunction(value)) {
10844 var name = value.name ? ': ' + value.name : '';
10845 return ctx.stylize('[Function' + name + ']', 'special');
10846 }
10847 if (isRegExp(value)) {
10848 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
10849 }
10850 if (isDate(value)) {
10851 return ctx.stylize(Date.prototype.toString.call(value), 'date');
10852 }
10853 if (isError(value)) {
10854 return formatError(value);
10855 }
10856 }
10857
10858 var base = '',
10859 array = false,
10860 braces = ['{', '}'];
10861
10862 // Make Array say that they are Array
10863 if (isArray(value)) {

Callers 2

inspectFunction · 0.85
formatPropertyFunction · 0.85

Calls 12

formatPrimitiveFunction · 0.85
arrayToHashFunction · 0.85
isErrorFunction · 0.85
formatErrorFunction · 0.85
isRegExpFunction · 0.85
isArrayFunction · 0.85
formatArrayFunction · 0.85
formatPropertyFunction · 0.85
reduceToSingleStringFunction · 0.85
isFunctionFunction · 0.70
isStringFunction · 0.70
isDateFunction · 0.70

Tested by

no test coverage detected