format

Classes

goog.format.EmailAddress
Formats an email address string for display, and allows for extraction of the individual components of the address.
goog.format.HtmlPrettyPrinter
This class formats HTML to be more human-readable. TODO(user): Add hierarchical indentation.
goog.format.InternationalizedEmailAddress
Formats an email address string for display, and allows for extraction of the individual components of the address.
goog.format.JsonPrettyPrinter
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 ] } }

Public Protected Private

Enumerations

goog.format.WbrToken_ :
Tokens used within insertWordBreaks.
Constants:
AMP
No description.
GT
No description.
LT
No description.
SEMI_COLON
No description.
SPACE
No description.
Code »

Global Functions

goog.format.conservativelyHasGraphemeBreak_(lastCharCodecharCodeopt_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.
Arguments:
lastCharCode : number
The previous character code. Ignored.
charCode : number
The character code under consideration. It must be at least \u0300 as a precondition -- this case is covered by insertWordBreaksGeneric_.
opt_extended : boolean=
Ignored, to conform with the interface.
Returns: boolean  Whether it is one of the recognized subsets of characters with a grapheme break.
code »
goog.format.fileSize(bytesopt_decimals) string
Formats a number of bytes in human readable form. 54, 450K, 1.3M, 5G etc.
Arguments:
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.
code »
goog.format.insertWordBreaks(stropt_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.
Arguments:
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.
code »
goog.format.insertWordBreaksBasic(stropt_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.
Arguments:
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.
code »
goog.format.insertWordBreaksGeneric_(strhasGraphemeBreakopt_maxlen) string
Inserts word breaks into an HTML string at a given interval. The counter is reset if a space or a character which behaves like a space is encountered, but it isn't incremented if an invisible formatting character is encountered. WBRs aren't inserted into HTML tags or entities. Entities 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.
Arguments:
str : string
HTML to insert word breaks into.
hasGraphemeBreak : function(number, number, boolean): boolean
A function determining if there is a grapheme break between two characters, in the same signature as goog.i18n.GraphemeBreak.hasGraphemeBreak.
opt_maxlen : number=
Maximum length after which to ensure there is a break. Default is 10 characters.
Returns: string  The string including word breaks.
code »
goog.format.isConvertableScaledNumber(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
Arguments:
val : string
String value to check.
Returns: boolean  True if string could be converted to a numeric value.
code »
goog.format.isInvisibleFormattingCharacter_(charCode) boolean
Returns true if and only if given character is an invisible formatting character.
Arguments:
charCode : number
The character code under consideration.
Returns: boolean  True if the character is an invisible formatting character.
code »
goog.format.isTreatedAsBreakingSpace_(charCode) boolean
Returns true if and only if given character should be treated as a breaking space. All ASCII control characters, the main Unicode range of spacing characters (U+2000 to U+200B inclusive except for U+2007), and several other Unicode space characters are treated as breaking spaces.
Arguments:
charCode : number
The character code under consideration.
Returns: boolean  True if the character is a breaking space.
code »
goog.format.numBytesToString(valopt_decimalsopt_suffixopt_useSeparator) 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.
Arguments:
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.
opt_useSeparator : boolean=
If true, number and scale will be separated by a no break space. Default is false.
Returns: string  String representation of number of bytes.
code »
goog.format.numericValueToString(valopt_decimals) string
Converts a numeric value to string representation. SI conversion.
Arguments:
val : number
Value to be converted.
opt_decimals : number=
The number of decimals to use. Defaults to 2.
Returns: string  String representation of number.
code »
goog.format.numericValueToString_(valconversionopt_decimalsopt_suffixopt_useSeparator) string
Converts a numeric value to string, using specified conversion scales.
Arguments:
val : number
Value to be converted.
conversion : Object
Dictionary of scaling factors.
opt_decimals : number=
The number of decimals to use. Default is 2.
opt_suffix : string=
Optional suffix to append.
opt_useSeparator : boolean=
If true, number and scale will be separated by a space. Default is false.
Returns: string  The human readable form of the byte size.
code »
goog.format.stringToNumBytes(stringValue) number
Converts a string to number of bytes, taking into account the units. Binary conversion.
Arguments:
stringValue : string
String to be converted to numeric value.
Returns: number  Numeric value for string.
code »
goog.format.stringToNumericValue(stringValue) number
Converts a string to numeric value, taking into account the units. If string ends in 'B', use binary conversion.
Arguments:
stringValue : string
String to be converted to numeric value.
Returns: number  Numeric value for string.
code »
goog.format.stringToNumericValue_(stringValueconversion) number
Converts a string to numeric value, taking into account the units.
Arguments:
stringValue : string
String to be converted to numeric value.
conversion : Object
Dictionary of conversion scales.
Returns: number  Numeric value for string. If it cannot be converted, returns NaN.
code »

Global Properties

goog.format.EmailAddressTest :
No description.
Code »
goog.format.FIRST_GRAPHEME_EXTEND_ :
First Unicode code point that has the Mark property.
Code »
goog.format.HtmlPrettyPrinterTest :
No description.
Code »
goog.format.IS_IE8_OR_ABOVE_ :
True iff the current userAgent is IE8 or above.
Code »
goog.format.InternationalizedEmailAddressTest :
No description.
Code »
goog.format.JsonPrettyPrinterTest :
No description.
Code »
goog.format.NUMERIC_SCALES_BINARY_ :
Scaling factors for conversion of numeric value to string. Binary conversion.
Code »
goog.format.NUMERIC_SCALES_SI_ :
Scaling factors for conversion of numeric value to string. SI conversion.
Code »
goog.format.NUMERIC_SCALE_PREFIXES_ :
Ordered list of scaling prefixes in decreasing order.
Code »
goog.format.SCALED_NUMERIC_RE_ :
Regular expression for detecting scaling units, such as K, M, G, etc. for converting a string representation to a numeric value. Also allow 'k' to be aliased to 'K'. These could be used for SI (powers of 1000) or Binary (powers of 1024) conversions. Also allow final 'B' to be interpreted as byte-count, implicitly triggering binary conversion (e.g., '10.2MB').
Code »
goog.format.WORD_BREAK_HTML :
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 .
Code »

Package format

Package Reference