Format an array.
------------------------------------------------------------------------------
969450
def awesome_array(a)
      return "[]" if a == []

      if a.instance_variable_defined?('@__awesome_methods__')
        methods_array(a)
      elsif @options[:multiline]
        width = (a.size - 1).to_s.size 

        data = a.inject([]) do |arr, item|
          index = indent
          index += colorize("[#{arr.size.to_s.rjust(width)}] ", :array) if @options[:index]
          indented do
            index += @inspector.awesome(item)
            arr << index
          end
        end
        data = limited(data, width) if should_be_limited?
        "[\n" + data.join(",\n") + "\n#{outdent}]"
      else
        "[ " + a.map{ |item| @inspector.awesome(item) }.join(", ") +  " ]"
      end
    end
58557
function format(value) {
    if (typeof value == 'number')
      return value;

    var str = String(value);
    var ary = str.split('\n').map((e) => JSON.stringify(e));
    if (ary.length > 1) {
      // If the string has newlines, start it off on its own line so that
      // it's easier to compare against another string with newlines.
      return '\n' + ary.join('\n');
    } else {
      return ary.join('\n');
    }
  }
1119393
function stringifyArray( arr, indent ) {
  var hasMoreThanOneItem = arr.length > 1;
  if ( hasMoreThanOneItem ) {
    var out = '[';
    arr.forEach( function( itm, idx ) {
      if ( idx > 0 )
        out += ",";
      out += "\n" + indent + itm;
    });
    return out + "]";
  } else {
    return "[" + ( arr.length == 1 ? arr[0] : '' ) + "]";
  }
}
1073650
protected function _format(array $data) {
		foreach (['id', 'rev'] as $key) {
			if (isset($data["_{$key}"])) {
				$data[$key] = $data["_{$key}"];
				unset($data["_{$key}"]);
			}
		}
		return $data;
	}
519491
function formatString (string) {
    const separator = "\n";
    return Array.isArray(string) ?
        string.reduce((acc, line) => acc.concat(line.split(separator)), []) :
        string.split(separator);
}
826424
function makeArray() {
  var arr = [];

  for (var i = 0; i < arguments.length; i++) {
    var arg = arguments[i];
    if (!arg) continue;

    var argType = typeof arg;

    if ('string' === argType || 'number' === argType) {
      arr.push(arg);
    } else if (Array.isArray(arg)) {
      arr = arr.concat(arg);
    } else if ('object' === argType) {
      for (var key in arg) {
        if (arg.hasOwnProperty(key) && arg[key]) {
          arr.push(key);
        }
      }
    }
  }

  return arr;
}
460373
function formatCSV(values) {
    if (values instanceof Array) {
        return values.map(v => formatValue(v)).join();
    }
    if (typeof values === 'object' && values !== null) {
        return Object.keys(values).map(v => formatValue(values[v])).join();
    }
    return values === undefined ? '' : formatValue(values);
}
65764
function formatValues(values) {
  var formatted = {};
  for (var key in values) {
    if (values.hasOwnProperty(key)) {
      if (typeof values[key] === 'boolean') {
        var position = key.indexOf('{');
        if (position !== -1) {
          if (values[key] === true) {
            // Each options of SelectWidget are stored as boolean and grouped using '{' and '}'
            // eg:
            // gender{male} = true
            // gender{female} = false
            var newKey = key.substr(0, position);
            var newValue = key.substr(position);
            newValue = newValue.replace('{', '');
            newValue = newValue.replace('}', '');
            if (!Array.isArray(formatted[newKey])) {
              formatted[newKey] = [];
            }
            formatted[newKey].push(newValue);
          }
        } else {
          formatted[key] = values[key];
        }
      } else {
        if (typeof values[key] === 'string') {
          formatted[key] = values[key].trim();
        } else {
          formatted[key] = values[key];
        }
      }
    }
  }
  return formatted;
}
1333357
private function formatArrayField($arr, $pk = null)
    {
        $ret = [];
        foreach ($arr as $k => $v) {
            if ($pk !== null) {
                $k = $pk . $k;
            }
            if (is_array($v)) {
                $ret = array_merge($ret, $this->formatArrayField($v, $k . ']['));
            } else {
                $ret[$k] = $v;
            }
        }
        return $ret;
    }
94046
public void format(PrintStream out, String[] headers, String[]... rows) {
        int[] columnWidth = computeEachColumnWidth(this.defaultColumnWidth, headers, rows);

        printRow(out, columnWidth, headers);
        printTableSeperatir(out, headers, columnWidth);

        for (String[] row : rows) {
            printRow(out, columnWidth, row);
        }
    }
204837
function format(text) {
    const lintResult = linter.executeOnText(text)
    return lintResult.results[0].output || text
}
1050751
function parseArray(array) {
  const templates = array.map(parse);
  const templateParameters = templates.reduce(
    (parameters, template) => parameters.concat(template.parameters),
    []
  );
  const templateFn = context => templates.map(template => template(context));

  return Template(templateFn, templateParameters);
}
220014
public function format($args)
    {
        if ($this->isArray($args)) {
            $value = vsprintf($this->val(), $args);
        } else {
            if ($this->isInstanceOf($args, new ArrayObject([]))) {
                $value = vsprintf($this->val(), $args->val());
            } else {
                $value = sprintf($this->val(), $args);
            }
        }
        $this->val($value);

        return $this;
    }
159970
function format(data) {
    const time = util.formatTime(new Date());
    const outputArray = data.toString().replace(/^\s+|\s+$/g, '').split(/\s+/);
    const outputValues = [];
    for (let i = 0, counter = 0; i < outputArray.length; i++) {
        if (!isNaN(outputArray[i])) {
            outputValues[counter] = parseFloat(outputArray[i]);
            counter++;
        }
    }
    if (outputValues.length > 0) {
        return {
            date: time,
            disk: {
                kb_read: outputValues[9],
                kb_wrtn: outputValues[10],
                kb_read_per: outputValues[7],
                kb_wrtn_per: outputValues[8],
                tps: outputValues[6]
            },
            cpu: {
                cpu_user: outputValues[0],
                cpu_nice: outputValues[1],
                cpu_system: outputValues[2],
                cpu_iowait: outputValues[3],
                cpu_steal: outputValues[4],
                cpu_idle: outputValues[5]
            }
        };
    }
    return false;
}
464175
function (printArray, format, preProcessor, settings) {
  format = format || ''
  preProcessor = preProcessor || []
  settings = settings || defaultSettings

  const INDENT = emptyString(settings.indent)
  const ROW_SPACER = emptyString(settings.rowSpace)

  const headings = getAllKeys(printArray)
  const maxLength = getMaxLength(headings, printArray)
  const maxLengths = Object.keys(maxLength).reduce((s, k) => s + maxLength[k], 0)

  // print headline
  const headline = []
  const seperator = []

  _.forEach(headings, function (header, i) {
    headline.push(toLength(header, maxLength[header], 'c'))
    seperator.push(new Array(maxLength[header] + 1).join('-'))
  })

  console.log(INDENT + seperator.join(ROW_SPACER))
  console.log(INDENT + headline.join(ROW_SPACER))
  console.log(INDENT + seperator.join(ROW_SPACER))

  // print rows
  _.forEach(printArray, function (row) {
    const line = []

    if (row === null || typeof row === 'string') {
      if (row === null || row === '') {
        return console.log('')
      }
      return console.log(chalk.grey.bold(toLength(row || '', maxLengths, 'l')))
    }

    _.forEach(headings, function (header, i) {
      let str = row[header] || ''

      if (_.isFunction(preProcessor[i])) {
        str = preProcessor[i](str) || str
      }

      line.push(toLength(str, maxLength[header], format.substr(i, 1)))
    })
    console.log(INDENT + line.join(ROW_SPACER))
  })
}
1306342
private function formatThrowableObjects(array $array)
    {
        array_walk_recursive($array, function (&$value) {
            if ($value instanceof \Throwable) {
                try {
                    $value = serialize($value);
                } catch (\Throwable $throwable) {
                    $value = $this->formatThrowable($value);
                }
            }
        });

        return $array;
    }
543608
function flatten( a ) {
    var results;
    var isArray = ( a.length !== undefined && typeof a !== "string" );
    if ( isArray ) {
        results = []
        for ( var i = 0; i < a.length; i++ ) {
            var result = flatten( a[i] );
            results = results.concat( result );
        }
    } else {
        results = [ a ];
    }
    return results;
}