Home

# Library goog.format

Function Summary
| `conservativelyHasGraphemeBreak_(number lastCharCode, number charCode, boolean= opt_extended) ⇒ boolean` Determines conservatively if a character has a Grapheme break. Conforms to a similar signature as goog.i18n.GraphemeBreak, but is overly conservative, returning true only for characters in common scripts that are simple to account for.
| `fileSize(number bytes, number= opt_decimals) ⇒ string` Formats a number of bytes in human readable form. 54, 450K, 1.3M, 5G etc.
| `insertWordBreaks(string str, number= opt_maxlen) ⇒ string` 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.

`insertWordBreaksBasic(string str, number= opt_maxlen) ⇒ string`

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.

`insertWordBreaksGeneric_(string str, function (number, number, boolean): boolean hasGraphemeBreak, number= opt_maxlen) ⇒ string`

Inserts word breaks into an HTML string at a given interval. The counter is reset if a space is encountered. WBRs aren't inserted into HTML tags or entities. Entites count towards the character count, HTML tags do not. With common strings aliased, objects allocations are constant based on the length of the string: N + 3. This guarantee does not hold if the string contains an element >= U+0300 and hasGraphemeBreak is non-trivial.

| `isConvertableScaledNumber(string val) ⇒ boolean` 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
| `numBytesToString(number val, number= opt_decimals, boolean= opt_suffix) ⇒ string` 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.
| `numericValueToString(number val, number= opt_decimals) ⇒ string` Converts a numeric value to string representation. SI conversion.
| `numericValueToString_(number val, ?Object conversion, number= opt_decimals, string= opt_suffix) ⇒ string` Converts a numeric value to string, using specified conversion scales.
| `stringToNumBytes(string stringValue) ⇒ number` Converts a string to number of bytes, taking into account the units. Binary conversion.
| `stringToNumericValue(string stringValue) ⇒ number` Converts a string to numeric value, taking into account the units. If string ends in 'B', use binary conversion.
| `stringToNumericValue_(string stringValue, ?Object conversion) ⇒ number` Converts a string to numeric value, taking into account the units.