B2G/gecko/toolkit/devtools/Console.jsm
/**
 * String utility to ensure that strings are a specified length. Strings
 * that are too long are truncated to the max length and the last char is
 * set to "_". Strings that are too short are left padded with spaces.
 *
 * @param {string} aStr
 *        The string to format to the correct length
 * @param {number} aMaxLen
 *        The maximum allowed length of the returned string
 * @param {number} aMinLen (optional)
 *        The minimum allowed length of the returned string. If undefined,
 *        then aMaxLen will be used
 * @param {object} aOptions (optional)
 *        An object allowing format customization. The only customization
 *        allowed currently is 'truncate' which can take the value "start" to
 *        truncate strings from the start as opposed to the end.
 * @return {string}
 *        The original string formatted to fit the specified lengths
 */
String utility to ensure that strings are a specified length. Strings
that are too long are truncated to the max length and the last char is
set to "_". Strings that are too short are left padded with spaces.

@param {string} aStr
The string to format to the correct length
@param {number} aMaxLen
The maximum allowed length of the returned string
@param {number} aMinLen (optional)
The minimum allowed length of the returned string. If undefined,
then aMaxLen will be used
@param {object} aOptions (optional)
An object allowing format customization. The only customization
allowed currently is 'truncate' which can take the value "start" to
truncate strings from the start as opposed to the end.
@return {string}
The original string formatted to fit the specified lengths
String utility to ensure that strings are a specified length . Strings that are too long are truncated to the max length and the last char is set to " _ " . Strings that are too short are left padded with spaces . @param { string } aStr The string to format to the correct length @param { number } aMaxLen The maximum allowed length of the returned string @param { number } aMinLen ( optional ) The minimum allowed length of the returned string . If undefined then aMaxLen will be used @param { object } aOptions ( optional ) An object allowing format customization . The only customization allowed currently is ' truncate ' which can take the value " start " to truncate strings from the start as opposed to the end . @return { string } The original string formatted to fit the specified lengths
function fmt(aStr, aMaxLen, aMinLen, aOptions) {
  if (aMinLen == null) {
    aMinLen = aMaxLen;
  }
  if (aStr == null) {
    aStr = "";
  }
  if (aStr.length > aMaxLen) {
    if (aOptions && aOptions.truncate == "start") {
      return "_" + aStr.substring(aStr.length - aMaxLen + 1);
    }
    else {
      return aStr.substring(0, aMaxLen - 1) + "_";
    }
  }
  if (aStr.length < aMinLen) {
    return Array(aMinLen - aStr.length + 1).join(" ") + aStr;
  }
  return aStr;
}
function fmt ( aStr , aMaxLen , aMinLen , aOptions ) { if ( aMinLen == null ) { aMinLen = aMaxLen ; } if ( aStr == null ) { aStr = "" ; } if ( aStr . length > aMaxLen ) { if ( aOptions && aOptions . truncate == "start" ) { return "_" + aStr . substring ( aStr . length - aMaxLen + 1 ) ; } else { return aStr . substring ( 0 , aMaxLen - 1 ) + "_" ; } } if ( aStr . length < aMinLen ) { return Array ( aMinLen - aStr . length + 1 ) . join ( " " ) + aStr ; } return aStr ; }
String utility to ensure that strings are a specified length.
String utility to ensure that strings are a specified length .