dantil.js
function prettify(args, options) {
  if (!options) {
    options = {}
  }

  var stylizeOptions = {
    // Number of times to recurse while formatting; defaults to 2.
    depth: options.depth,
    // Format in color if the terminal supports color.
    colors: exports.colors.supportsColor,
  }

  // Use `RegExp()` to get correct `reMultiLined.source`.
  var reMultiLined = RegExp('\n', 'g')
  var reWhitespaceOnly = /^\s+$/
  var indent = '  '
  var prevArgIsSeperateLine = false

  var argsArray = Array.prototype.slice.call(args)

  // Remove any leading newline characters in the first argument, and prepend them to the remainder of the formatted arguments instead of including the characters in the indentation of each argument (as occurs with other whitespace characters in the first argument).
  var firstArg = argsArray[0]
  var leadingNewlines = ''
  if (/^\n+/.test(firstArg)) {
    var lastNewlineIdx = firstArg.lastIndexOf('\n')
    if (lastNewlineIdx === firstArg.length - 1) {
      argsArray.shift()
    } else {
      argsArray[0] = firstArg.slice(lastNewlineIdx + 1)
      firstArg = firstArg.slice(0, lastNewlineIdx + 1)
    }

    leadingNewlines = firstArg
  }

  return leadingNewlines + argsArray.reduce(function (formattedArgs, arg, i, args) {
    var argIsString = typeof arg === 'string'

    // Parse numbers passed as string for styling.
    if (argIsString && /^\S+$/.test(arg) && !isNaN(arg)) {
      arg = parseFloat(arg)
      argIsString = false
    }

    // Do not stylize strings passed as arguments (i.e., not `Object` properties). This also preserves any already-stylized arguments.
    var formattedArg = !options.stylizeStings && argIsString ? arg : exports.stylize(arg, stylizeOptions)

    if (i === 0) {
      // Extend indent for remaining arguments with the first argument's leading whitespace, if any.
      if (argIsString) {
        // Get the substring of leading whitespace characters from the start of the string, up to the first non-whitespace character, if any.
        var firstNonWhitespaceIndex = arg.search(/[^\s]/)
        arg = arg.slice(0, firstNonWhitespaceIndex === -1 ? arg.length : firstNonWhitespaceIndex)

        // JavaScript will not properly indent if '\t' is appended to spaces (i.e., reverse order as here).
        // If the first argument is entirely whitespace, indent all remaining arguments with that whitespace.
        indent = reWhitespaceOnly.test(formattedArg) ? arg : arg + indent

        // If first argument is entirely whitespace, exclude from output because it serves only to set indentation of all remaining arguments.
        if (reWhitespaceOnly.test(formattedArg)) {
          // Force the next argument to be pushed to `formattedArgs` to avoid concatenating with `undefined` (because `formattedArgs` remains empty).
          prevArgIsSeperateLine = true
        } else {
          formattedArgs.push(formattedArg)
        }
      } else {
        formattedArgs.push(formattedArg)

        if (arg instanceof Object) {
          // Do not indent remaining arguments if the first argument is of a complex type.
          indent = ''

          // Format the complex type on a separate line.
          prevArgIsSeperateLine = true
        }
      }
    } else if (arg instanceof Object && (!Array.isArray(arg) || reMultiLined.test(formattedArg) || args[0] instanceof Object)) {
      // Format plain `Object`s, `Array`s with multi-line string representations, and `Array`s when the first argument is of a complex type on separate lines.
      formattedArgs.push(indent + formattedArg.replace(reMultiLined, reMultiLined.source + indent))
      prevArgIsSeperateLine = true
    } else if (prevArgIsSeperateLine) {
      // Format anything that follows a multi-line string representations on a new line.
      formattedArgs.push(indent + formattedArg)
      prevArgIsSeperateLine = false
    } else {
      // Concatenate all consecutive primitive data types.
      formattedArgs[formattedArgs.length - 1] += ' ' + formattedArg
    }

    return formattedArgs
  }, []).join('\n')
}
function prettify(args, options) {
  if (!options) {
    options = {}
  }

  var stylizeOptions = {
    // Number of times to recurse while formatting; defaults to 2.
    depth: options.depth,
    // Format in color if the terminal supports color.
    colors: exports.colors.supportsColor,
  }

  // Use `RegExp()` to get correct `reMultiLined.source`.
  var reMultiLined = RegExp('\n', 'g')
  var reWhitespaceOnly = /^\s+$/
  var indent = '  '
  var prevArgIsSeperateLine = false

  var argsArray = Array.prototype.slice.call(args)

  // Remove any leading newline characters in the first argument, and prepend them to the remainder of the formatted arguments instead of including the characters in the indentation of each argument (as occurs with other whitespace characters in the first argument).
  var firstArg = argsArray[0]
  var leadingNewlines = ''
  if (/^\n+/.test(firstArg)) {
    var lastNewlineIdx = firstArg.lastIndexOf('\n')
    if (lastNewlineIdx === firstArg.length - 1) {
      argsArray.shift()
    } else {
      argsArray[0] = firstArg.slice(lastNewlineIdx + 1)
      firstArg = firstArg.slice(0, lastNewlineIdx + 1)
    }

    leadingNewlines = firstArg
  }

  return leadingNewlines + argsArray.reduce(function (formattedArgs, arg, i, args) {
    var argIsString = typeof arg === 'string'

    // Parse numbers passed as string for styling.
    if (argIsString && /^\S+$/.test(arg) && !isNaN(arg)) {
      arg = parseFloat(arg)
      argIsString = false
    }

    // Do not stylize strings passed as arguments (i.e., not `Object` properties). This also preserves any already-stylized arguments.
    var formattedArg = !options.stylizeStings && argIsString ? arg : exports.stylize(arg, stylizeOptions)

    if (i === 0) {
      // Extend indent for remaining arguments with the first argument's leading whitespace, if any.
      if (argIsString) {
        // Get the substring of leading whitespace characters from the start of the string, up to the first non-whitespace character, if any.
        var firstNonWhitespaceIndex = arg.search(/[^\s]/)
        arg = arg.slice(0, firstNonWhitespaceIndex === -1 ? arg.length : firstNonWhitespaceIndex)

        // JavaScript will not properly indent if '\t' is appended to spaces (i.e., reverse order as here).
        // If the first argument is entirely whitespace, indent all remaining arguments with that whitespace.
        indent = reWhitespaceOnly.test(formattedArg) ? arg : arg + indent

        // If first argument is entirely whitespace, exclude from output because it serves only to set indentation of all remaining arguments.
        if (reWhitespaceOnly.test(formattedArg)) {
          // Force the next argument to be pushed to `formattedArgs` to avoid concatenating with `undefined` (because `formattedArgs` remains empty).
          prevArgIsSeperateLine = true
        } else {
          formattedArgs.push(formattedArg)
        }
      } else {
        formattedArgs.push(formattedArg)

        if (arg instanceof Object) {
          // Do not indent remaining arguments if the first argument is of a complex type.
          indent = ''

          // Format the complex type on a separate line.
          prevArgIsSeperateLine = true
        }
      }
    } else if (arg instanceof Object && (!Array.isArray(arg) || reMultiLined.test(formattedArg) || args[0] instanceof Object)) {
      // Format plain `Object`s, `Array`s with multi-line string representations, and `Array`s when the first argument is of a complex type on separate lines.
      formattedArgs.push(indent + formattedArg.replace(reMultiLined, reMultiLined.source + indent))
      prevArgIsSeperateLine = true
    } else if (prevArgIsSeperateLine) {
      // Format anything that follows a multi-line string representations on a new line.
      formattedArgs.push(indent + formattedArg)
      prevArgIsSeperateLine = false
    } else {
      // Concatenate all consecutive primitive data types.
      formattedArgs[formattedArgs.length - 1] += ' ' + formattedArg
    }

    return formattedArgs
  }, []).join('\n')
}
function prettify ( args , options ) { if ( ! options ) { options = { } } var stylizeOptions = { // Number of times to recurse while formatting; defaults to 2. depth : options . depth , // Format in color if the terminal supports color. colors : exports . colors . supportsColor , } // Use `RegExp()` to get correct `reMultiLined.source`. var reMultiLined = RegExp ( '\n' , 'g' ) var reWhitespaceOnly = / ^\s+$ / var indent = '  ' var prevArgIsSeperateLine = false var argsArray = Array . prototype . slice . call ( args ) // Remove any leading newline characters in the first argument, and prepend them to the remainder of the formatted arguments instead of including the characters in the indentation of each argument (as occurs with other whitespace characters in the first argument). var firstArg = argsArray [ 0 ] var leadingNewlines = '' if ( / ^\n+ / . test ( firstArg ) ) { var lastNewlineIdx = firstArg . lastIndexOf ( '\n' ) if ( lastNewlineIdx === firstArg . length - 1 ) { argsArray . shift ( ) } else { argsArray [ 0 ] = firstArg . slice ( lastNewlineIdx + 1 ) firstArg = firstArg . slice ( 0 , lastNewlineIdx + 1 ) } leadingNewlines = firstArg } return leadingNewlines + argsArray . reduce ( function ( formattedArgs , arg , i , args ) { var argIsString = typeof arg === 'string' // Parse numbers passed as string for styling. if ( argIsString && / ^\S+$ / . test ( arg ) && ! isNaN ( arg ) ) { arg = parseFloat ( arg ) argIsString = false } // Do not stylize strings passed as arguments (i.e., not `Object` properties). This also preserves any already-stylized arguments. var formattedArg = ! options . stylizeStings && argIsString ? arg : exports . stylize ( arg , stylizeOptions ) if ( i === 0 ) { // Extend indent for remaining arguments with the first argument's leading whitespace, if any. if ( argIsString ) { // Get the substring of leading whitespace characters from the start of the string, up to the first non-whitespace character, if any. var firstNonWhitespaceIndex = arg . search ( / [^\s] / ) arg = arg . slice ( 0 , firstNonWhitespaceIndex === - 1 ? arg . length : firstNonWhitespaceIndex ) // JavaScript will not properly indent if '\t' is appended to spaces (i.e., reverse order as here). // If the first argument is entirely whitespace, indent all remaining arguments with that whitespace. indent = reWhitespaceOnly . test ( formattedArg ) ? arg : arg + indent // If first argument is entirely whitespace, exclude from output because it serves only to set indentation of all remaining arguments. if ( reWhitespaceOnly . test ( formattedArg ) ) { // Force the next argument to be pushed to `formattedArgs` to avoid concatenating with `undefined` (because `formattedArgs` remains empty). prevArgIsSeperateLine = true } else { formattedArgs . push ( formattedArg ) } } else { formattedArgs . push ( formattedArg ) if ( arg instanceof Object ) { // Do not indent remaining arguments if the first argument is of a complex type. indent = '' // Format the complex type on a separate line. prevArgIsSeperateLine = true } } } else if ( arg instanceof Object && ( ! Array . isArray ( arg ) || reMultiLined . test ( formattedArg ) || args [ 0 ] instanceof Object ) ) { // Format plain `Object`s, `Array`s with multi-line string representations, and `Array`s when the first argument is of a complex type on separate lines. formattedArgs . push ( indent + formattedArg . replace ( reMultiLined , reMultiLined . source + indent ) ) prevArgIsSeperateLine = true } else if ( prevArgIsSeperateLine ) { // Format anything that follows a multi-line string representations on a new line. formattedArgs . push ( indent + formattedArg ) prevArgIsSeperateLine = false } else { // Concatenate all consecutive primitive data types. formattedArgs [ formattedArgs . length - 1 ] += ' ' + formattedArg } return formattedArgs } , [ ] ) . join ( '\n' ) }
Formats the provided values and objects in color for pretty-printing, recursing `options.depth` times while formatting objects.

Formats plain `Object` and `Array` instances with multi-line string representations on separate lines. Concatenates and formats all other consecutive values on the same line.

If the first argument is of a complex type (e.g., `Object`, `Array`), left-aligns all remaining lines. Otherwise, equally indents each line after the first line, if any. If the first argument has leading whitespace (or is entirely whitespace), prepends all remaining arguments with the same whitespace (as indentation) excluding newline characters.

@private
@static
@param {Array} args The values and objects to format.
@param {Object} [options] The options object.
@param {number} [options.depth=2] The number of times to recurse while formating `args`. Pass `null` to recurse indefinitely.
@param {number} [options.stylizeStings=false] Specify stylizing strings in `args`. This does not apply to `Object` properties.
@returns {string} Returns the formatted string.
Formats the provided values and objects in color for pretty - printing recursing options . depth times while formatting objects .