// See the end for instructions

var Text = {
as:function(a1) { return '' + (a1 || '') },
is:function(a1) { return '' + a1 === a1 },
no:function(a1) {
	a1 = isNaN(a1=Number(a1)) ? parseFloat(a1) : a1;
	return isNaN(a1) ? 0 : a1;
},
ex:function(a1,a2) {
	var mo = Math.floor(a2/2);
	if (mo > 1) return this.ex(a1 + a1, mo) + (a2 % 2 && a1 || '');
	var fo = '';
	while (a2 > 0) { fo += a1; a2-- }
	return fo;
},
pad:function(a1,a2,a3) {
return this.is(a1)
	? a1 + this.ex(a3 || ' ', a2 - a1.length)
	: this.ex(a3 || ' ', a1 - ('' + a2).length) + a2;
},
trim:function(a1,a2,a3) {
	a1 = this.as(a1).replace(a3 || /^\s+|\s+$/g, '');
	return a2 && a1.length > a2 ? a1.substr(0,a2-1) + '\u2026' : a1; 
},
line:function(a1) {
	var OS = navigator.platform, NL = OS.indexOf('Mac') != -1
		&& '\r' || OS.indexOf('Win') != -1
		&& '\r\n' || '\n';
	return this.as(a1) + NL;
},
code:function(a1) { return (a1=this.as(a1)) ? "unescape('"+escape(a1)+"')" : "''" }
}


//
// 
// All functions are available through the Text object, i.e. Text.function(arguments). They are helpful in formatting text, conversion to numbers, value comparisons, newline resolution, conversion to evaluable code, etc.
// 
// Eight built-in functions are provided. The as() and no() functions convert to and from strings/numbers respectively. The is() function confirms a value as text, and the ex() function expands a compressed string value. The pad() and trim() functions pad and trim text, and the line() and code() functions help work with newlines and create evaluable code from text.
// 
// I. Conversion and Identity 
// Conversion of data from one form to another, or determining the identity of a value is very important in many applications. If someone types in 5 and 10 into text boxes, you want to make sure that if, for instance, they clicked "Add" that the answer given would be 5 + 10, rather than '5' + '10' -- the answer an unsuspecting coder would end up with. For another example, did the user type in 'null' as their username, or click Cancel and create a null response from the prompt dialog?
// 
// Text.as(value) 
// Ensuring the representation of a value as text can be critical! The text.as() function converts values to text, but non-textual "false" values such as null, false, 0, or undefined will return an empty string instead of an ugly word.
// 
// Text.no(value) 
// The no() function does the opposite, converting strings to numbers (including conversion of standard dates to their representation in milliseconds).
// 
// Text.is(value) 
// The is() function returns a Boolean value of whether or not its argument is truly a string
// 
// II. Formatting 
// Formatting text is certainly an obvious task. Padding and cleaning up of text is an important job that is done well by these functions. Think of the last time you've gotten a handwritten receipt at checkout, or done addition without lining up decimal places. Once you've used them you'll find that doing without is like using carbon paper instead of a copier.
// 
// Text.ex(string, multiplier) 
// The ex() expansion function expands short text into a longer string. It makes it easy to create strings of an exact length.
// 
// Text.pad(length, string, filler) | Text.pad(string, length, filler) 
// The pad() function pads text to either the right or left margin. Using this makes it easy to arrange prices in columns along the decimal point, etc. Note that the filler should be one character in length.
// 
// Text.trim(string, length, regexp) 
// "Trimming" out whitespace or other characters is important to clean up input before you can use checking functions like credit card checksum operations or telephone number validation. The optional second and third arguments specify a maximum length and an override for the default elimination of whitespace characters, respectively.
// 
// III. ASCII 
// The functions relate to the ASCII table, making correct newline characters (an OS dependent function) and establishing the character codes for easy creation of code on-the-fly.
// 
// Text.line(string) 
// The line() function returns the correct newline for the platform it runs on. The newline is added to the end of the string if specified, or returned alone
// 
// Text.code(string) 
// The code() function converts a line into its representation in JavaScript, allowing you to create code on-the-fly from arbitrary input.
