The goog.format Namespace

The goog.format.EmailAddress Class

Formats an email address string for display, and allows for extraction of The individual componants of the address. … more

The goog.format.HtmlPrettyPrinter Class

This class formats HTML to be more human-readable. TODO(user): Add hierarchical indentation. … more

The goog.format.JsonPrettyPrinter Class

Formats a JSON object as a string, properly indented for display. Supports displaying the string as text or html. Users can also specify their own set of delimiters for different environments. For example, the JSON object: {"a": 1, "b": {"c": null, "d": true, "e": [1, 2]}} Will be displayed like this: { "a": 1, "b": { "c": null, "d": true, "e": [ 1, 2 ] } } … more

.WORD_BREAK_HTML {string}

Constant for the WBR replacement used by insertWordBreaks. Safari requires , Opera needs the ­ entity, though this will give a visible hyphen at breaks. IE8 uses a zero width space. Other browsers just use .

.fileSize(bytes, opt_decimals)

Formats a number of bytes in human readable form. 54, 450K, 1.3M, 5G etc.

bytes {number}
The number of bytes to show.
opt_decimals {number=}
The number of decimals to use. Defaults to 2.
returns {string}
The human readable form of the byte size.

.insertWordBreaks(str, opt_maxlen)

Inserts word breaks into an HTML string at a given interval. This method is as aggressive as possible, using a full table of Unicode characters where it is legal to insert word breaks; however, this table comes at a 2.5k pre-gzip (~1k post-gzip) size cost. Consider using insertWordBreaksBasic to minimize the size impact.

str {string}
HTML to insert word breaks into.
opt_maxlen {number=}
Maximum length after which to ensure there is a break. Default is 10 characters.
returns {string}
The string including word breaks.

.insertWordBreaksBasic(str, opt_maxlen)

Inserts word breaks into an HTML string at a given interval. This method is less aggressive than insertWordBreaks, only inserting breaks next to punctuation and between Latin or Cyrillic characters. However, this is good enough for the common case of URLs. It also works for all Latin and Cyrillic languages, plus CJK has no need for word breaks. When this method is used, goog.i18n.GraphemeBreak may be dead code eliminated.

str {string}
HTML to insert word breaks into.
opt_maxlen {number=}
Maximum length after which to ensure there is a break. Default is 10 characters.
returns {string}
The string including word breaks.

.isConvertableScaledNumber(val)

Checks whether string value containing scaling units (K, M, G, T, P, m, u, n) can be converted to a number. Where there is a decimal, there must be a digit to the left of the decimal point. Negative numbers are valid. Examples: 0, 1, 1.0, 10.4K, 2.3M, -0.3P, 1.2m

val {string}
String value to check.
returns {boolean}
True if string could be converted to a numeric value.

.numBytesToString(val, opt_decimals, opt_suffix)

Converts number of bytes to string representation. Binary conversion. Default is to return the additional 'B' suffix, e.g. '10.5KB' to minimize confusion with counts that are scaled by powers of 1000.

val {number}
Value to be converted.
opt_decimals {number=}
The number of decimals to use. Defaults to 2.
opt_suffix {boolean=}
If true, include trailing 'B' in returned string. Default is true.
returns {string}
String representation of number of bytes.

.numericValueToString(val, opt_decimals)

Converts a numeric value to string representation. SI conversion.

val {number}
Value to be converted.
opt_decimals {number=}
The number of decimals to use. Defaults to 2.
returns {string}
String representation of number.

.stringToNumBytes(stringValue)

Converts a string to number of bytes, taking into account the units. Binary conversion.

stringValue {string}
String to be converted to numeric value.
returns {number}
Numeric value for string.

.stringToNumericValue(stringValue)

Converts a string to numeric value, taking into account the units. If string ends in 'B', use binary conversion.

stringValue {string}
String to be converted to numeric value.
returns {number}
Numeric value for string.