* Add @fileoverview JSDoc comment
* Move static methods down to the bottom of the file to circumvent a strange bug that prevents documentation from being generated.
This commit is contained in:
parent
da7bdcfba0
commit
486e9a5836
4 changed files with 130 additions and 119 deletions
|
@ -9,11 +9,14 @@
|
||||||
* Copyright 1998-2005 Helma Software. All Rights Reserved.
|
* Copyright 1998-2005 Helma Software. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* $RCSfile: Date.js,v $
|
* $RCSfile: Date.js,v $
|
||||||
* $Author: czv $
|
* $Author: stefanp $
|
||||||
* $Revision: 1.2 $
|
* $Revision: 1.3 $
|
||||||
* $Date: 2006/04/24 07:02:17 $
|
* $Date: 2006/08/21 15:57:05 $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fileoverview Adds useful methods to the JavaScript Date type.
|
||||||
|
*/
|
||||||
|
|
||||||
Date.ONESECOND = 1000;
|
Date.ONESECOND = 1000;
|
||||||
Date.ONEMINUTE = 60 * Date.ONESECOND;
|
Date.ONEMINUTE = 60 * Date.ONESECOND;
|
||||||
|
|
|
@ -9,29 +9,14 @@
|
||||||
* Copyright 1998-2006 Helma Software. All Rights Reserved.
|
* Copyright 1998-2006 Helma Software. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* $RCSfile: Number.js,v $
|
* $RCSfile: Number.js,v $
|
||||||
* $Author: tobi $
|
* $Author: robert $
|
||||||
* $Revision: 1.3 $
|
* $Revision: 1.4 $
|
||||||
* $Date: 2006/07/18 08:24:59 $
|
* $Date: 2006/12/14 17:28:43 $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* factory to create functions for sorting objects in an array
|
* @fileoverview Adds useful methods to the JavaScript Number type.
|
||||||
* @param String name of the field each object is compared with
|
|
||||||
* @param Number order (ascending or descending)
|
|
||||||
* @return Function ready for use in Array.prototype.sort
|
|
||||||
*/
|
*/
|
||||||
Number.Sorter = function(field, order) {
|
|
||||||
if (!order)
|
|
||||||
order = 1;
|
|
||||||
return function(a, b) {
|
|
||||||
return (a[field] - b[field]) * order;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Number.Sorter.ASC = 1;
|
|
||||||
Number.Sorter.DESC = -1;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* format a Number to a String
|
* format a Number to a String
|
||||||
|
@ -67,6 +52,24 @@ Number.prototype.toPercent = function(total, fmt, locale) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* factory to create functions for sorting objects in an array
|
||||||
|
* @param String name of the field each object is compared with
|
||||||
|
* @param Number order (ascending or descending)
|
||||||
|
* @return Function ready for use in Array.prototype.sort
|
||||||
|
*/
|
||||||
|
Number.Sorter = function(field, order) {
|
||||||
|
if (!order)
|
||||||
|
order = 1;
|
||||||
|
return function(a, b) {
|
||||||
|
return (a[field] - b[field]) * order;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
Number.Sorter.ASC = 1;
|
||||||
|
Number.Sorter.DESC = -1;
|
||||||
|
|
||||||
|
|
||||||
// prevent any newly added properties from being enumerated
|
// prevent any newly added properties from being enumerated
|
||||||
for (var i in Number)
|
for (var i in Number)
|
||||||
Number.dontEnum(i);
|
Number.dontEnum(i);
|
||||||
|
|
|
@ -10,10 +10,13 @@
|
||||||
*
|
*
|
||||||
* $RCSfile: Object.js,v $
|
* $RCSfile: Object.js,v $
|
||||||
* $Author: czv $
|
* $Author: czv $
|
||||||
* $Revision: 1.6 $
|
* $Revision: 1.2 $
|
||||||
* $Date: 2006/04/18 13:06:58 $
|
* $Date: 2006/04/24 07:02:17 $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fileoverview Adds useful methods to the JavaScript Object type.
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* copy the properties of an object into
|
* copy the properties of an object into
|
||||||
|
|
192
core/String.js
192
core/String.js
|
@ -10,8 +10,8 @@
|
||||||
*
|
*
|
||||||
* $RCSfile: String.js,v $
|
* $RCSfile: String.js,v $
|
||||||
* $Author: tobi $
|
* $Author: tobi $
|
||||||
* $Revision: 1.3 $
|
* $Revision: 1.4 $
|
||||||
* $Date: 2006/07/24 16:03:57 $
|
* $Date: 2006/08/06 11:27:56 $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,100 +28,9 @@ String.RIGHT = 1
|
||||||
String.ISOFORMAT = "yyyy-MM-dd'T'HH:mm:ssZ";
|
String.ISOFORMAT = "yyyy-MM-dd'T'HH:mm:ssZ";
|
||||||
String.NULL = "";
|
String.NULL = "";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* factory to create functions for sorting objects in an array
|
* @fileoverview Adds useful methods to the JavaScript String type.
|
||||||
* @param String name of the field each object is compared with
|
|
||||||
* @param Number order (ascending or descending)
|
|
||||||
* @return Function ready for use in Array.prototype.sort
|
|
||||||
*/
|
*/
|
||||||
String.Sorter = function(field, order) {
|
|
||||||
if (!order)
|
|
||||||
order = 1;
|
|
||||||
var key = field + ":" + order;
|
|
||||||
if (!String.Sorter.cache[key]) {
|
|
||||||
String.Sorter.cache[key] = function(a, b) {
|
|
||||||
var str1 = String(a[field] || String.NULL).toLowerCase();
|
|
||||||
var str2 = String(b[field] || String.NULL).toLowerCase();
|
|
||||||
if (str1 > str2)
|
|
||||||
return order * 1;
|
|
||||||
if (str1 < str2)
|
|
||||||
return order * -1;
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return String.Sorter.cache[key];
|
|
||||||
};
|
|
||||||
|
|
||||||
String.Sorter.ASC = 1;
|
|
||||||
String.Sorter.DESC = -1;
|
|
||||||
String.Sorter.cache = {};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* create a string from a bunch of substrings
|
|
||||||
* @param String one or more strings as arguments
|
|
||||||
* @return String the resulting string
|
|
||||||
*/
|
|
||||||
String.compose = function() {
|
|
||||||
res.push();
|
|
||||||
for (var i=0; i<arguments.length; i++)
|
|
||||||
res.write(arguments[i]);
|
|
||||||
return res.pop();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* creates a random string (numbers and chars)
|
|
||||||
* @param len length of key
|
|
||||||
* @param mode determines which letters to use. null or 0 = all letters;
|
|
||||||
* 1 = skip 0, 1, l and o which can easily be mixed with numbers;
|
|
||||||
* 2 = use numbers only
|
|
||||||
* @returns random string
|
|
||||||
*/
|
|
||||||
String.random = function(len, mode) {
|
|
||||||
if (mode == 2) {
|
|
||||||
var x = Math.random() * Math.pow(10,len);
|
|
||||||
return Math.floor(x);
|
|
||||||
}
|
|
||||||
var keystr = String.NULL;
|
|
||||||
for (var i=0; i<len; i++) {
|
|
||||||
var x = Math.floor((Math.random() * 36));
|
|
||||||
if (mode == 1) {
|
|
||||||
// skip 0,1
|
|
||||||
x = (x<2) ? x + 2 : x;
|
|
||||||
// don't use the letters l (charCode 21+87) and o (24+87)
|
|
||||||
x = (x==21) ? 22 : x;
|
|
||||||
x = (x==24) ? 25 : x;
|
|
||||||
}
|
|
||||||
if (x<10) {
|
|
||||||
keystr += String(x);
|
|
||||||
} else {
|
|
||||||
keystr += String.fromCharCode(x+87);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return keystr;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* append one string onto another and add some "glue"
|
|
||||||
* if none of the strings is empty or null.
|
|
||||||
* @param String the first string
|
|
||||||
* @param String the string to be appended onto the first one
|
|
||||||
* @param String the "glue" to be inserted between both strings
|
|
||||||
* @return String the resulting string
|
|
||||||
*/
|
|
||||||
String.join = function(str1, str2, glue) {
|
|
||||||
if (glue == null)
|
|
||||||
glue = String.NULL;
|
|
||||||
if (str1 && str2)
|
|
||||||
return str1 + glue + str2;
|
|
||||||
else if (str2)
|
|
||||||
return str2;
|
|
||||||
return str1;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checks if a date format pattern is correct
|
* checks if a date format pattern is correct
|
||||||
|
@ -383,7 +292,7 @@ String.prototype.tail = function(limit, clipping, delimiter) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* set clip method out of compatibility/convenience reason
|
* set clip method out of compatibility/convenience reason
|
||||||
* FIXME: we eventually have to get rid of this one...
|
* FIXME: we eventually have to get rid of this one...
|
||||||
* @see String.prototype.head()
|
* @see String.prototype.head()
|
||||||
|
@ -663,6 +572,99 @@ String.prototype.stripTags = function() {
|
||||||
return stripTags(this);
|
return stripTags(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* factory to create functions for sorting objects in an array
|
||||||
|
* @param String name of the field each object is compared with
|
||||||
|
* @param Number order (ascending or descending)
|
||||||
|
* @return Function ready for use in Array.prototype.sort
|
||||||
|
*/
|
||||||
|
String.Sorter = function(field, order) {
|
||||||
|
if (!order)
|
||||||
|
order = 1;
|
||||||
|
var key = field + ":" + order;
|
||||||
|
if (!String.Sorter.cache[key]) {
|
||||||
|
String.Sorter.cache[key] = function(a, b) {
|
||||||
|
var str1 = String(a[field] || String.NULL).toLowerCase();
|
||||||
|
var str2 = String(b[field] || String.NULL).toLowerCase();
|
||||||
|
if (str1 > str2)
|
||||||
|
return order * 1;
|
||||||
|
if (str1 < str2)
|
||||||
|
return order * -1;
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return String.Sorter.cache[key];
|
||||||
|
};
|
||||||
|
|
||||||
|
String.Sorter.ASC = 1;
|
||||||
|
String.Sorter.DESC = -1;
|
||||||
|
String.Sorter.cache = {};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create a string from a bunch of substrings
|
||||||
|
* @param String one or more strings as arguments
|
||||||
|
* @return String the resulting string
|
||||||
|
*/
|
||||||
|
String.compose = function() {
|
||||||
|
res.push();
|
||||||
|
for (var i=0; i<arguments.length; i++)
|
||||||
|
res.write(arguments[i]);
|
||||||
|
return res.pop();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates a random string (numbers and chars)
|
||||||
|
* @param len length of key
|
||||||
|
* @param mode determines which letters to use. null or 0 = all letters;
|
||||||
|
* 1 = skip 0, 1, l and o which can easily be mixed with numbers;
|
||||||
|
* 2 = use numbers only
|
||||||
|
* @returns random string
|
||||||
|
*/
|
||||||
|
String.random = function(len, mode) {
|
||||||
|
if (mode == 2) {
|
||||||
|
var x = Math.random() * Math.pow(10,len);
|
||||||
|
return Math.floor(x);
|
||||||
|
}
|
||||||
|
var keystr = String.NULL;
|
||||||
|
for (var i=0; i<len; i++) {
|
||||||
|
var x = Math.floor((Math.random() * 36));
|
||||||
|
if (mode == 1) {
|
||||||
|
// skip 0,1
|
||||||
|
x = (x<2) ? x + 2 : x;
|
||||||
|
// don't use the letters l (charCode 21+87) and o (24+87)
|
||||||
|
x = (x==21) ? 22 : x;
|
||||||
|
x = (x==24) ? 25 : x;
|
||||||
|
}
|
||||||
|
if (x<10) {
|
||||||
|
keystr += String(x);
|
||||||
|
} else {
|
||||||
|
keystr += String.fromCharCode(x+87);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return keystr;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* append one string onto another and add some "glue"
|
||||||
|
* if none of the strings is empty or null.
|
||||||
|
* @param String the first string
|
||||||
|
* @param String the string to be appended onto the first one
|
||||||
|
* @param String the "glue" to be inserted between both strings
|
||||||
|
* @return String the resulting string
|
||||||
|
*/
|
||||||
|
String.join = function(str1, str2, glue) {
|
||||||
|
if (glue == null)
|
||||||
|
glue = String.NULL;
|
||||||
|
if (str1 && str2)
|
||||||
|
return str1 + glue + str2;
|
||||||
|
else if (str2)
|
||||||
|
return str2;
|
||||||
|
return str1;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// prevent any newly added properties from being enumerated
|
// prevent any newly added properties from being enumerated
|
||||||
for (var i in String)
|
for (var i in String)
|
||||||
|
|
Loading…
Add table
Reference in a new issue