Clear Up
SharpKit Reference

Format Class

Namespace: Ext.util

Base Types

System.Object

Constructors

Name Description
Format()

Methods

Name Description
date(object, JsString) Parse a value into a formatted date using the specified format pattern. @param {String/Date} value The value to format (Strings must conform to the format expected by the javascript Date object's parse() method) @param {String} format (optional) Any valid date format string (defaults to 'm/d/Y') @return {String} The formatted date string
ellipsis(JsString, JsNumber, bool) Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length @param {String} value The string to truncate @param {Number} length The maximum length to allow before truncating @param {Boolean} word True to try to find a common word break @return {String} The converted text
escape(JsString) Escapes the passed string for ' and \ @param {String} string The string to escape @return {String} The escaped string
escapeRegex(JsString) Escapes the passed string for use in a regular expression @param {String} str @return {String}
format(JsString) Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
  
var cls = 'my-class', text = 'Some text';
var s = Ext.util.Format.format('<div class="{0}">{1}</div>', cls, text);
// s now contains the string: '<div class="my-class">Some text</div>'
            
@param {String} string The tokenized string to be formatted @param {String...} values The values to replace token {0}, {1}, etc @return {String} The formatted string
htmlDecode(JsString)
htmlEncode(JsString)
leftPad(JsString, JsNumber, JsString) Pads the left side of a string with a specified character. This is especially useful for normalizing number and date strings. Example usage: *
  
var s = Ext.util.Format.leftPad('123', 5, '0');
// s now contains the string: '00123'
            
@param {String} string The original string @param {Number} size The total length of the output string @param {String} char (optional) The character with which to pad the original string (defaults to empty string " ") @return {String} The padded string
toggle(JsString, JsString, JsString) Utility function that allows you to easily switch a string between two alternating values. The passed value is compared to the current string, and if they are equal, the other value that was passed in is returned. If they are already different, the first value passed in is returned. Note that this method returns the new value but does not change the current string.
  
// alternate sort directions
sort = Ext.util.Format.toggle(sort, 'ASC', 'DESC');
// instead of conditional logic:
sort = (sort == 'ASC' ? 'DESC' : 'ASC');
            
@param {String} string The current string @param {String} value The value to compare to the current string @param {String} other The new value to use if the string already equals the first value passed in @return {String} The new value
trim(JsString) Trims whitespace from either end of a string, leaving spaces within the string intact. Example:
  
var s = '  foo bar  ';
alert('-' + s + '-');         //alerts "- foo bar -"
alert('-' + Ext.util.Format.trim(s) + '-');  //alerts "-foo bar-"
            
@param {String} string The string to escape @return {String} The trimmed string

Properties

Name Description
defaultDateFormat Reusable data formatting functions
escapeRe
escapeRegexRe
formatRe
singleton Reusable data formatting functions
trimRe
© Copyright 2005-2011 SharpKit. All rights reserved.