@ -6,7 +6,16 @@ const internalUtil = require('internal/util');
const binding = process . binding ( 'util' ) ;
const binding = process . binding ( 'util' ) ;
const isError = internalUtil . isError ;
const isError = internalUtil . isError ;
const kDefaultMaxLength = 100 ;
const inspectDefaultOptions = Object . seal ( {
showHidden : false ,
depth : 2 ,
colors : false ,
customInspect : true ,
showProxy : false ,
maxArrayLength : 100 ,
breakLength : 60
} ) ;
var Debug ;
var Debug ;
var simdFormatters ;
var simdFormatters ;
@ -176,29 +185,31 @@ function inspect(obj, opts) {
stylize : stylizeNoColor
stylize : stylizeNoColor
} ;
} ;
// legacy...
// legacy...
if ( arguments . length >= 3 ) ctx . depth = arguments [ 2 ] ;
if ( arguments [ 2 ] !== undefined ) ctx . depth = arguments [ 2 ] ;
if ( arguments . length >= 4 ) ctx . colors = arguments [ 3 ] ;
if ( arguments [ 3 ] !== undefined ) ctx . colors = arguments [ 3 ] ;
if ( typeof opts === 'boolean' ) {
if ( typeof opts === 'boolean' ) {
// legacy...
// legacy...
ctx . showHidden = opts ;
ctx . showHidden = opts ;
} else if ( opts ) {
// got an "options" object
exports . _ extend ( ctx , opts ) ;
}
}
// set default options
// Set default and user-specified options
if ( ctx . showHidden === undefined ) ctx . showHidden = false ;
ctx = Object . assign ( { } , inspect . defaultOptions , ctx , opts ) ;
if ( ctx . depth === undefined ) ctx . depth = 2 ;
if ( ctx . colors === undefined ) ctx . colors = false ;
if ( ctx . customInspect === undefined ) ctx . customInspect = true ;
if ( ctx . showProxy === undefined ) ctx . showProxy = false ;
if ( ctx . colors ) ctx . stylize = stylizeWithColor ;
if ( ctx . colors ) ctx . stylize = stylizeWithColor ;
if ( ctx . maxArrayLength === undefined ) ctx . maxArrayLength = kDefaultMaxLength ;
if ( ctx . maxArrayLength === null ) ctx . maxArrayLength = Infinity ;
if ( ctx . maxArrayLength === null ) ctx . maxArrayLength = Infinity ;
if ( ctx . breakLength === undefined ) ctx . breakLength = 60 ;
return formatValue ( ctx , obj , ctx . depth ) ;
return formatValue ( ctx , obj , ctx . depth ) ;
}
}
exports . inspect = inspect ;
Object . defineProperty ( inspect , 'defaultOptions' , {
get : function ( ) {
return inspectDefaultOptions ;
} ,
set : function ( options ) {
if ( options === null || typeof options !== 'object' ) {
throw new TypeError ( '"options" must be an object' ) ;
}
Object . assign ( inspectDefaultOptions , options ) ;
return inspectDefaultOptions ;
}
} ) ;
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
inspect . colors = {
inspect . colors = {
@ -231,6 +242,7 @@ inspect.styles = {
'regexp' : 'red'
'regexp' : 'red'
} ;
} ;
exports . inspect = inspect ;
function stylizeWithColor ( str , styleType ) {
function stylizeWithColor ( str , styleType ) {
var style = inspect . styles [ styleType ] ;
var style = inspect . styles [ styleType ] ;