summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts/extended/string.js
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web/Javascripts/extended/string.js')
-rw-r--r--framework/Web/Javascripts/extended/string.js60
1 files changed, 52 insertions, 8 deletions
diff --git a/framework/Web/Javascripts/extended/string.js b/framework/Web/Javascripts/extended/string.js
index e265edf4..46274256 100644
--- a/framework/Web/Javascripts/extended/string.js
+++ b/framework/Web/Javascripts/extended/string.js
@@ -1,4 +1,14 @@
+/**
+ * @class String extensions
+ */
Object.extend(String.prototype, {
+ /**
+ * @param {String} "left" to pad the string on the left, "right" to pad right.
+ * @param {Number} minimum string length.
+ * @param {String} character(s) to pad
+ * @return {String} padded character(s) on the left or right to satisfy minimum string length
+ */
+
pad : function(side, len, chr) {
if (!chr) chr = ' ';
var s = this;
@@ -7,26 +17,49 @@ Object.extend(String.prototype, {
return s;
},
+ /**
+ * @param {Number} minimum string length.
+ * @param {String} character(s) to pad
+ * @return {String} padded character(s) on the left to satisfy minimum string length
+ */
padLeft : function(len, chr) {
return this.pad('left',len,chr);
},
+ /**
+ * @param {Number} minimum string length.
+ * @param {String} character(s) to pad
+ * @return {String} padded character(s) on the right to satisfy minimum string length
+ */
padRight : function(len, chr) {
return this.pad('right',len,chr);
},
+ /**
+ * @param {Number} minimum string length.
+ * @return {String} append zeros to the left to satisfy minimum string length.
+ */
zerofill : function(len) {
return this.padLeft(len,'0');
},
+ /**
+ * @return {String} removed white spaces from both ends.
+ */
trim : function() {
return this.replace(/^\s+|\s+$/g,'');
},
+ /**
+ * @return {String} removed white spaces from the left end.
+ */
trimLeft : function() {
return this.replace(/^\s+/,'');
},
+ /**
+ * @return {String} removed white spaces from the right end.
+ */
trimRight : function() {
return this.replace(/\s+$/,'');
},
@@ -35,7 +68,7 @@ Object.extend(String.prototype, {
* Convert period separated function names into a function reference.
* e.g. "Prado.AJAX.Callback.Action.setValue".toFunction() will return
* the actual function Prado.AJAX.Callback.Action.setValue()
- * @return Function the corresponding function represented by the string.
+ * @return {Function} the corresponding function represented by the string.
*/
toFunction : function()
{
@@ -58,7 +91,7 @@ Object.extend(String.prototype, {
/**
* Convert a string into integer, returns null if not integer.
- * @return {integer|null} null if string does not represent an integer.
+ * @return {Number} null if string does not represent an integer.
*/
toInteger : function()
{
@@ -72,8 +105,8 @@ Object.extend(String.prototype, {
/**
* Convert a string into a double/float value. <b>Internationalization
* is not supported</b>
- * @param {string} the decimal character
- * @return {float|null} null if string does not represent a float value
+ * @param {String} the decimal character
+ * @return {Double} null if string does not represent a float value
*/
toDouble : function(decimalchar)
{
@@ -93,10 +126,10 @@ Object.extend(String.prototype, {
* of dicimal digits, grouping and decimal characters can be specified.
* <i>The currency input format is <b>very</b> strict, null will be returned if
* the pattern does not match</i>.
- * @param {string} the grouping character, default is ","
- * @param {int} number of decimal digits
- * @param {string} the decimal character, default is "."
- * @type {float|null} the currency value as float.
+ * @param {String} the grouping character, default is ","
+ * @param {Number} number of decimal digits
+ * @param {String} the decimal character, default is "."
+ * @type {Double} the currency value as float.
*/
toCurrency : function(groupchar, digits, decimalchar)
{
@@ -116,5 +149,16 @@ Object.extend(String.prototype, {
+ ((digits > 0) ? "." + m[7] : "");
var num = parseFloat(cleanInput);
return (isNaN(num) ? null : num);
+ },
+
+ /**
+ * Converts the string to a date by finding values that matches the
+ * date format pattern.
+ * @param string date format pattern, e.g. MM-dd-yyyy
+ * @return {Date} the date extracted from the string
+ */
+ toDate : function(format)
+ {
+ return Date.SimpleParse(this, format);
}
});