Namenskorrektur
This commit is contained in:
parent
9eaa4a841c
commit
c0258314f4
73 changed files with 0 additions and 0 deletions
|
@ -0,0 +1,325 @@
|
|||
// Array Extensions v1.0.7
|
||||
// documentation: http://www.dithered.com/javascript/array/index.html
|
||||
// license: http://creativecommons.org/licenses/by/1.0/
|
||||
// code by Chris Nott (chris[at]dithered[dot]com)
|
||||
// code by Ilya Lebedev (ilya[at]lebedev[dot]net)
|
||||
|
||||
|
||||
// Array.concat() - Join two arrays
|
||||
if (isUndefined(Array.prototype.concat)) {
|
||||
Array.prototype.concat = function (secondArray) {
|
||||
var firstArray = this.copy();
|
||||
for (var i = 0, saL = secondArray.length; i < saL; i++) {
|
||||
firstArray[firstArray.length] = secondArray[i];
|
||||
}
|
||||
return firstArray;
|
||||
};
|
||||
}
|
||||
|
||||
// Array.copy() - Copy an array
|
||||
if (isUndefined(Array.prototype.copy)) {
|
||||
Array.prototype.copy = function() {
|
||||
var copy = new Array();
|
||||
for (var i = 0, tL = this.length; i < tL; i++) {
|
||||
copy[i] = this[i];
|
||||
}
|
||||
return copy;
|
||||
};
|
||||
}
|
||||
|
||||
// Array.pop() - Remove the last element of an array and return it
|
||||
if (isUndefined(Array.prototype.pop)) {
|
||||
Array.prototype.pop = function() {
|
||||
var lastItem = undefined;
|
||||
if ( this.length > 0 ) {
|
||||
lastItem = this[this.length - 1];
|
||||
this.length--;
|
||||
}
|
||||
return lastItem;
|
||||
};
|
||||
}
|
||||
|
||||
// Array.push() - Add an element to the end of an array
|
||||
if (isUndefined(Array.prototype.push)) {
|
||||
Array.prototype.push = function() {
|
||||
var currentLength = this.length;
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
this[currentLength + i] = arguments[i];
|
||||
}
|
||||
return this.length;
|
||||
};
|
||||
}
|
||||
|
||||
// Array.shift() - Remove the first element of an array and return it
|
||||
if (isUndefined(Array.prototype.shift)) {
|
||||
Array.prototype.shift = function() {
|
||||
var firstItem = this[0];
|
||||
for (var i = 0, tL = this.length - 1; i < tL; i++) {
|
||||
this[i] = this[i + 1];
|
||||
}
|
||||
this.length--;
|
||||
return firstItem;
|
||||
};
|
||||
}
|
||||
|
||||
// Array.slice() - Copy several elements of an array and return them
|
||||
if (isUndefined(Array.prototype.slice)) {
|
||||
Array.prototype.slice = function(start, end) {
|
||||
var temp;
|
||||
|
||||
if (end == null || end == '') end = this.length;
|
||||
|
||||
// negative arguments measure from the end of the array
|
||||
else if (end < 0) end = this.length + end;
|
||||
if (start < 0) start = this.length + start;
|
||||
|
||||
// swap limits if they are backwards
|
||||
if (end < start) {
|
||||
temp = end;
|
||||
end = start;
|
||||
start = temp;
|
||||
}
|
||||
|
||||
// copy elements from array to a new array and return the new array
|
||||
var newArray = new Array();
|
||||
for (var i = 0; i < end - start; i++) {
|
||||
newArray[i] = this[start + i];
|
||||
}
|
||||
return newArray;
|
||||
};
|
||||
}
|
||||
|
||||
// Array.splice() - Splice out and / or replace several elements of an array and return any deleted elements
|
||||
if (isUndefined(Array.prototype.splice)) {
|
||||
Array.prototype.splice = function(start, deleteCount) {
|
||||
if (deleteCount == null || deleteCount == '') deleteCount = this.length - start;
|
||||
|
||||
// create a temporary copy of the array
|
||||
var tempArray = this.copy();
|
||||
|
||||
// Copy new elements into array (over-writing old entries)
|
||||
for (var i = start, aL = start + arguments.length - 2; i < aL; i++) {
|
||||
this[i] = arguments[i - start + 2];
|
||||
}
|
||||
|
||||
// Copy old entries after the end of the splice back into array and return
|
||||
var dC = deleteCount - arguments.length + 2;
|
||||
for (var i = start + arguments.length - 2, tL = this.length - deleteCount + arguments.length - 2; i < tL; i++) {
|
||||
this[i] = tempArray[i + dC];
|
||||
}
|
||||
this.length = this.length - dC;
|
||||
return tempArray.slice(start, start + deleteCount);
|
||||
};
|
||||
}
|
||||
|
||||
// Array.unshift - Add an element to the beginning of an array
|
||||
if (isUndefined(Array.prototype.unshift)) {
|
||||
Array.prototype.unshift = function(the_item) {
|
||||
for (var loop = this.length-1 ; loop >= 0; loop--) {
|
||||
this[loop+1] = this[loop];
|
||||
}
|
||||
this[0] = the_item;
|
||||
return this.length;
|
||||
};
|
||||
}
|
||||
|
||||
// Array.indexOf - return index of found element or -1 (similar to String.indexOf)
|
||||
// Don't do the check on 'undefined' because Mozilla does calculate index weirdly
|
||||
Array.prototype.indexOf = function(needle,begin) {
|
||||
for (var i=(null==begin||isNaN(begin)||begin<0)?0:Math.round(begin),len = this.length, idx = -1; idx==-1 & i<len; i++) {
|
||||
idx = (this[i]==needle)?i:idx;
|
||||
}
|
||||
return idx;
|
||||
};
|
||||
// Array.lastIndexOf - return index of found element or -1 (similar to String.lastIndexOf)
|
||||
// Don't do the check on 'undefined' because Mozilla does calculate index weirdly
|
||||
Array.prototype.lastIndexOf = function(needle,end) {
|
||||
for (var i=(null==end||isNaN(end)||end>this.length)?this.length-1:Math.round(end), idx = -1; idx==-1 & i>-1; i--) {
|
||||
idx = (this[i]==needle)?i:idx;
|
||||
}
|
||||
return idx;
|
||||
};
|
||||
// Array.map - maps a function on the array elements
|
||||
if (isUndefined(Array.prototype.map)) {
|
||||
Array.prototype.map = function(func) {
|
||||
if ('function' != typeof func) return this;
|
||||
var tmp = [];
|
||||
for (var loop = this.length-1 ; loop >= 0; loop--) {
|
||||
tmp[loop] = func(this[loop]);
|
||||
}
|
||||
return tmp;
|
||||
};
|
||||
}
|
||||
|
||||
if (isUndefined(Array.prototype.unique)) {
|
||||
/**
|
||||
* Method removes dumplicate entries
|
||||
*
|
||||
* @return {Array}
|
||||
* @scope public
|
||||
*/
|
||||
Array.prototype.unique = function() /* :Array */{
|
||||
var tmp = [];
|
||||
for(var i=0, tL=this.length; i<tL; i++ ) {
|
||||
if( tmp.indexOf(this[i]) < 0 ) tmp[tmp.length] = this[i];
|
||||
}
|
||||
return tmp;
|
||||
};
|
||||
}
|
||||
|
||||
if (isUndefined(Array.prototype.flatten)) {
|
||||
/**
|
||||
* Method flattens 2-dimensional array, when no cols supplied only the cols number from 0th row will be counted
|
||||
*
|
||||
* @param {Number, Array} cols columns to insert to resulting array
|
||||
* @return {Array}
|
||||
* @scope public
|
||||
*/
|
||||
Array.prototype.flatten = function(cols /* :Array */, cd) /* :Array */{
|
||||
if (this.length<1) return [];
|
||||
if (isNumeric(cols)) cols = [cols];
|
||||
var idx = false;
|
||||
if (isArray(cols)) {
|
||||
idx = {};
|
||||
for (var i=0,cL=cols.length;i<cL;i++) idx[cols[i]]=true;
|
||||
}
|
||||
var tmp = [];
|
||||
for (var i=0, tL=this.length; i<tL; i++ ) {
|
||||
if (isUndefined(this[i])) continue;
|
||||
if (!isArray(this[i])) {
|
||||
if (false===idx) tmp[tmp.length] = this[i];
|
||||
} else {
|
||||
for (var k=0, cL=this[i].length; k<cL; k++) {
|
||||
if (false===idx || idx.hasOwnProperty(k)) tmp[tmp.length] = this[i][k];
|
||||
}
|
||||
}
|
||||
}
|
||||
return tmp;
|
||||
};
|
||||
}
|
||||
if (isUndefined(Array.prototype.filter)) {
|
||||
/**
|
||||
* Method returns array with non-empty (not evaluating to false) entries
|
||||
*
|
||||
* @param {Function} cbk optional callback function to perform a filter
|
||||
* @return {Array}
|
||||
* @scope public
|
||||
*/
|
||||
Array.prototype.filter = function(cbk /* :Function */) /* :Array */ {
|
||||
if (!isFunction(cbk)) cbk = null;
|
||||
for (var i=0, tL = this.length, tmp = [], ti=null; i<tL;i++) {
|
||||
ti = cbk?cbk(this[i]):this[i];
|
||||
if (!isEmpty(ti)) tmp[tmp.length] = ti;
|
||||
}
|
||||
return tmp;
|
||||
};
|
||||
}
|
||||
if (isUndefined(Array.prototype.binSearch)) {
|
||||
/**
|
||||
* Provides binary search for the sorted array, causes unexpected results on unsorted one
|
||||
*
|
||||
* @param {Variant} el element to search for
|
||||
* @return {Number} array index
|
||||
* @scope public
|
||||
*/
|
||||
Array.prototype.binSearch = function (el,key) {
|
||||
var l = 0
|
||||
,r = this.length
|
||||
,len = Math.max(r-1,0)
|
||||
,c = Math.ceil(r/2)
|
||||
,cnt = 0
|
||||
if (null != key)
|
||||
while ((!this[c] || el!=this[c][key]) && r>=l) {
|
||||
if (this[c] && el>this[c][key])
|
||||
l=c+1
|
||||
else
|
||||
r=c-1
|
||||
c=Math.max(0,Math.ceil((r+l)/2))
|
||||
}
|
||||
else
|
||||
while (el!=this[c] && r>=l) {
|
||||
if (el>this[c])
|
||||
l=c+1
|
||||
else
|
||||
r=c-1
|
||||
c=Math.max(0,Math.ceil((r+l)/2));
|
||||
}
|
||||
return c
|
||||
}
|
||||
}
|
||||
/**
|
||||
* heap sort ( N log N )
|
||||
*
|
||||
* @scope public
|
||||
*/
|
||||
Array.prototype.heapSort = function () {
|
||||
|
||||
// prepare the array with special sorting method
|
||||
if (!this.sift) {
|
||||
/**
|
||||
* Innersorting method for the heap sort
|
||||
*
|
||||
* @param {Number} low
|
||||
* @param {Number} up
|
||||
*/
|
||||
this.sift = function (low, up) {
|
||||
var c, tmp = this[low];
|
||||
|
||||
while(true){
|
||||
c = (low << 1) + 1;
|
||||
if( c > up ) break;
|
||||
if( c < up && this[c+1][0] > this[c][0] ) c++;
|
||||
if( tmp[0] >= this[c][0] ) break;
|
||||
this[low] = this[c]; // 1/2 (mini) swap ))
|
||||
low = c;
|
||||
}
|
||||
this[low] = tmp;
|
||||
}
|
||||
}
|
||||
var tmp,
|
||||
maximal = this.length - 1,
|
||||
i = maximal << 1;
|
||||
|
||||
while( i >= 0 ){ this.sift(i--, maximal) };
|
||||
i = maximal;
|
||||
while( i > 0 ){
|
||||
// full swap
|
||||
tmp = this[0];
|
||||
this[0] = this[i];
|
||||
this[i] = tmp;
|
||||
this.sift(0,--i);
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
// STATIC METHODS
|
||||
//-----------------------------------------------------------------------------
|
||||
if (isUndefined(Array.range)) {
|
||||
/**
|
||||
* Method creates the array with values in the specified range
|
||||
* 1 argument: create array from min(0, end) to max(0, end) with increment 1
|
||||
* 2 arguments: create array from min(start, end) to max(start, end) with increment 1
|
||||
* 3 arguments: create array from min(start, end) to max(start, end) with increment inc
|
||||
*
|
||||
* @param {Number} end end position
|
||||
* @param {Number} start start position
|
||||
* @param {Number} inc increment
|
||||
* @return {Array}
|
||||
* @scope public
|
||||
*/
|
||||
Array.range = function(end /* :Number */, start /* :Number */, inc /* :Number */) /* :Array */{
|
||||
if (!isNumber(end)) return null;
|
||||
if (!isNumber(inc)) inc = 1;
|
||||
if (!isNumber(start)) start = 0;
|
||||
var tmp = []
|
||||
,mn = Math.min(start, end)
|
||||
,mx = Math.max(start, end)
|
||||
,i = Math.abs(inc)
|
||||
,cnt = -1;
|
||||
do {
|
||||
cnt++;
|
||||
tmp[cnt] = mn;
|
||||
mn += i;
|
||||
} while (mn<=mx);
|
||||
return inc>0?tmp:tmp.reverse();
|
||||
};
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* Checks if property is derived from prototype, applies method if it is not exists
|
||||
*
|
||||
* @param string property name
|
||||
* @return bool true if prototyped
|
||||
* @access public
|
||||
*/
|
||||
if ('undefined' == typeof Object.hasOwnProperty) {
|
||||
Object.prototype.hasOwnProperty = function (prop) {
|
||||
return !('undefined' == typeof this[prop] || this.constructor && this.constructor.prototype[prop] && this[prop] === this.constructor.prototype[prop]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/**************************************************
|
||||
*
|
||||
* Extensions for the RegExp object
|
||||
*
|
||||
* @author Ilya Lebedev <ilya@lebedev.net>
|
||||
* @modified $Date: 2007-10-26 19:25:39 +0400 (Птн, 26 Окт 2007) $
|
||||
* @version $Rev: 339 $
|
||||
* @license LGPL 2.1 or later
|
||||
**************************************************/
|
||||
/**
|
||||
* Does escape of special regexp characters
|
||||
*
|
||||
* Modified version from Simon Willison
|
||||
*
|
||||
* @see http://simon.incutio.com/archive/2006/01/20/escape
|
||||
* @param {String, Array} text to escape
|
||||
* @return {String} escaped result
|
||||
* @scope public
|
||||
*/
|
||||
RegExp.escape = function(text /* :String, Array */) /* :String */ {
|
||||
if (!arguments.callee.sRE) {
|
||||
var specials = [
|
||||
'/', '.', '*', '+', '?', '|',
|
||||
'(', ')', '[', ']', '{', '}', '$', '^', '\\'
|
||||
];
|
||||
arguments.callee.sRE = new RegExp(
|
||||
'(\\' + specials.join('|\\') + ')', 'g'
|
||||
);
|
||||
}
|
||||
return isString(text)?text.replace(arguments.callee.sRE, '\\$1')
|
||||
:(isArray(text)?text.map(RegExp.escape).join("|")
|
||||
:"");
|
||||
}
|
|
@ -0,0 +1,307 @@
|
|||
/**
|
||||
* $Id: string.js 370 2007-11-25 01:39:30Z wingedfox $
|
||||
* $HeadURL: https://svn.debugger.ru/repos/jslibs/BrowserExtensions/tags/BrowserExtensions.018/ext/string.js $
|
||||
*
|
||||
* @author Ildar Shaimordanov
|
||||
* @author Ilya Lebedev
|
||||
* @license LGPL
|
||||
* @version $Rev: 370 $
|
||||
*/
|
||||
|
||||
/**
|
||||
* Decodes html entities
|
||||
*
|
||||
* @return {String} string with decoded entities
|
||||
* @scope public
|
||||
*/
|
||||
String.prototype.entityDecode = function() {
|
||||
if (!arguments.callee.span) arguments.callee.span = document.createElement('span');
|
||||
var s = arguments.callee.span;
|
||||
s.innerHTML = this;
|
||||
return s.firstChild?s.firstChild.nodeValue:"";
|
||||
}
|
||||
|
||||
/**
|
||||
* Method is used to trim specified chars from the left of the string
|
||||
*
|
||||
* @param {String, Array} c char or char list to be trimmed, default is \s
|
||||
* @return {String}
|
||||
* @scope public
|
||||
*/
|
||||
String.prototype.ltrim = function(c) {
|
||||
if (isString(c)) c=c.split("");
|
||||
if (isArray(c) || isUndefined(c)) {
|
||||
c = isEmpty(c)?"\\s":RegExp.escape(c);
|
||||
c = new RegExp("^(?:"+c+")+", "g");
|
||||
return this.replace(c, "");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Method is used to trim specified list from the right of the string
|
||||
*
|
||||
* @param {String, Array} c char or char sequence to be trimmed, default is \s
|
||||
* @return {String}
|
||||
* @scope public
|
||||
*/
|
||||
String.prototype.rtrim = function(c) {
|
||||
if (isString(c)) c=c.split("");
|
||||
if (isArray(c) || isUndefined(c)) {
|
||||
c = isEmpty(c)?"\\s":RegExp.escape(c);
|
||||
c = new RegExp("(?:"+c+")+$", "g");
|
||||
return this.replace(c, "");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Method is used to trim specified chars from the left and the right of the string
|
||||
*
|
||||
* @param {String, Array} c char or char list to be trimmed, default is \s
|
||||
* @return {String}
|
||||
* @scope public
|
||||
*/
|
||||
String.prototype.trim = function(c) {
|
||||
if (isString(c)) c=c.split("");
|
||||
if (isArray(c) || isUndefined(c)) {
|
||||
c = isEmpty(c)?"\\s":RegExp.escape(c);
|
||||
c = new RegExp("^(?:"+c+")+|(?:"+c+")+$", "g");
|
||||
return this.replace(c, "");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicates the string
|
||||
*
|
||||
* @return {String}
|
||||
* @scope public
|
||||
*/
|
||||
String.prototype.dup = function() {
|
||||
var val = this.valueOf();
|
||||
return [val,val].join("");
|
||||
}
|
||||
/**
|
||||
* Repeats string specified number of times
|
||||
*
|
||||
* @param {Number} n number of times to repeat the string
|
||||
* @return {String}
|
||||
* @scope public
|
||||
*/
|
||||
String.prototype.repeat = function(n /* :Number */) /* :String */ {
|
||||
if (isNaN(n=parseInt(n)) || n<0) return "";
|
||||
return Array(n+1).join(this.valueOf());
|
||||
}
|
||||
/**
|
||||
* Pads the string to the specified length
|
||||
*
|
||||
* @param {Number} n number of times to repeat c
|
||||
* positive - on the right side
|
||||
* negative - on the left side
|
||||
* @param {String} c fill char, space is default
|
||||
* @return {String}
|
||||
* @scope public
|
||||
*/
|
||||
String.prototype.padding = function(n, c) {
|
||||
var val = this.valueOf();
|
||||
n = parseInt(n);
|
||||
if (!n) return val;
|
||||
if (isUndefined(c)) c = " ";
|
||||
var pad = String(c).charAt(0).repeat(Math.abs(n) - this.length);
|
||||
return (n < 0) ? pad + val : val + pad;
|
||||
}
|
||||
/**
|
||||
* Pads the string on the right side
|
||||
*
|
||||
* @param {Number} n number of times to repeat c
|
||||
* @param {String} c fill char
|
||||
* @return {String}
|
||||
* @scope public
|
||||
*/
|
||||
String.prototype.padLeft = function(n, c) {
|
||||
return this.padding(-Math.abs(n), c);
|
||||
}
|
||||
/**
|
||||
* Pads the string on the left side
|
||||
*
|
||||
* @param {Number} n number of times to repeat c
|
||||
* @param {String} c fill char
|
||||
* @return {String}
|
||||
* @scope public
|
||||
*/
|
||||
String.prototype.padRight = function(n, c) {
|
||||
return this.padding(Math.abs(n), c);
|
||||
}
|
||||
|
||||
/**
|
||||
* sprintf(format, argument_list)
|
||||
*
|
||||
* The string format function like the one in C/C++, PHP, Perl
|
||||
* Each conversion specification is defined as below:
|
||||
*
|
||||
* %[index][alignment][padding][width][precision]type
|
||||
*
|
||||
* index An optional index specifier that changes the order of the
|
||||
* arguments in the list to be displayed.
|
||||
* alignment An optional alignment specifier that says if the result should be
|
||||
* left-justified or right-justified. The default is
|
||||
* right-justified; a "-" character here will make it left-justified.
|
||||
* padding An optional padding specifier that says what character will be
|
||||
* used for padding the results to the right string size. This may
|
||||
* be a space character or a "0" (zero character). The default is to
|
||||
* pad with spaces. An alternate padding character can be specified
|
||||
* by prefixing it with a single quote ('). See the examples below.
|
||||
* width An optional number, a width specifier that says how many
|
||||
* characters (minimum) this conversion should result in.
|
||||
* precision An optional precision specifier that says how many decimal digits
|
||||
* should be displayed for floating-point numbers. This option has
|
||||
* no effect for other types than float.
|
||||
* type A type specifier that says what type the argument data should be
|
||||
* treated as. Possible types:
|
||||
*
|
||||
* % - a literal percent character. No argument is required.
|
||||
* b - the argument is treated as an integer, and presented as a binary number.
|
||||
* c - the argument is treated as an integer, and presented as the character
|
||||
* with that ASCII value.
|
||||
* d - the argument is treated as an integer, and presented as a decimal number.
|
||||
* u - the same as "d".
|
||||
* f - the argument is treated as a float, and presented as a floating-point.
|
||||
* o - the argument is treated as an integer, and presented as an octal number.
|
||||
* s - the argument is treated as and presented as a string.
|
||||
* x - the argument is treated as an integer and presented as a hexadecimal
|
||||
* number (with lowercase letters).
|
||||
* X - the argument is treated as an integer and presented as a hexadecimal
|
||||
* number (with uppercase letters).
|
||||
*
|
||||
* @return {String}
|
||||
* @scope public
|
||||
*/
|
||||
String.prototype.sprintf = function() {
|
||||
var args = isArray(arguments[0])?arguments[0]:arguments
|
||||
,index = 0
|
||||
,frmt = this.replace(/%%/g, "\0\0")
|
||||
,re = /%((?:\d+\$)?)((?:[-0+# ])?)((?:\d+|\*(?:\d+\$)?)?)((?:.(?:\d+|\*(?:\d+\$)?))?)([bcdeEfosuxX])/g;
|
||||
/*
|
||||
* The re.exec() method returns the array with the following properties
|
||||
* wich are used in this function
|
||||
* x.index contains the substring position found at the origin string
|
||||
* x[0] contains the found substring
|
||||
* x[1] contains the explicit parameter number
|
||||
* x[2] contains the flags
|
||||
* x[3] contains the minwidth
|
||||
* x[4] contains the precision
|
||||
* x[5] contains the type specifier (as [bcdfosuxX])
|
||||
*/
|
||||
frmt = frmt.replace(re, function() {
|
||||
var x = arguments
|
||||
,sign = false
|
||||
,ins;
|
||||
|
||||
/*
|
||||
* calculate min width
|
||||
*/
|
||||
if (!isUndefined(x[3]) && x[3].indexOf("*")==0) {
|
||||
x[3] = parseInt(x[3].replace(/\D/g,""))
|
||||
if (isNaN(x[3])) {
|
||||
x[3] = args[index];
|
||||
/*
|
||||
* increment
|
||||
*/
|
||||
index++;
|
||||
} else {
|
||||
x[3] = args[x[3]]
|
||||
}
|
||||
}
|
||||
/*
|
||||
* calculate precision
|
||||
*/
|
||||
if ("" != x[4]) {
|
||||
if (x[4].indexOf("*")==1) {
|
||||
x[4] = parseInt(x[4].replace(/\D/g,""))
|
||||
if (isNaN(x[4])) {
|
||||
x[4] = args[index];
|
||||
/*
|
||||
* increment
|
||||
*/
|
||||
index++;
|
||||
} else {
|
||||
x[4] = args[x[4]]
|
||||
}
|
||||
} else {
|
||||
x[4] = x[4].replace(/\D/,"")
|
||||
}
|
||||
x[4] = Math.abs(x[4]);
|
||||
}
|
||||
/*
|
||||
* calculate insertion value
|
||||
*/
|
||||
x[1] = parseInt(x[1]);
|
||||
var ins;
|
||||
if (isNumeric(x[1])) {
|
||||
ins = args[x[1]];
|
||||
} else {
|
||||
ins = args[index];
|
||||
/*
|
||||
* index should be incremented only when no explicit parameter number is specified
|
||||
*/
|
||||
index++;
|
||||
}
|
||||
switch (x[5]) {
|
||||
case "b":
|
||||
if (ins<0) ins = 0x10000000000000000+parseInt(ins);
|
||||
ins = Number(ins).bin(x[4]);
|
||||
if (x[4]) ins = ins.substr(0,x[4]);
|
||||
if (x[2]=='#') ins = '0b'+ins;
|
||||
break;
|
||||
case "c":
|
||||
ins = String.fromCharCode(ins);
|
||||
break;
|
||||
case "u":
|
||||
ins = Math.abs(ins);
|
||||
case "d":
|
||||
ins = Math.round(ins);
|
||||
if (ins<0) {
|
||||
ins = "-"+Math.abs(ins).dec(x[4]);
|
||||
} else {
|
||||
ins = Number(ins).dec(x[4]);
|
||||
sign = (x[2] == ' ' || x[2] == '+');
|
||||
}
|
||||
break;
|
||||
case "e":
|
||||
case "E":
|
||||
if (ins>0) {
|
||||
sign = (x[2] == ' ' || x[2] == '+');
|
||||
}
|
||||
ins = Number(ins).toExponential(x[4]?x[4]:6);
|
||||
if (x[5]=='E') ins=ins.toUpperCase();
|
||||
break;
|
||||
case "f":
|
||||
if (ins>0) {
|
||||
sign = (x[2] == ' ' || x[2] == '+');
|
||||
}
|
||||
ins = Number(ins).toFixed(isNumeric(x[4])?x[4]:6);
|
||||
break;
|
||||
case "o":
|
||||
if (ins<0) ins = 0x10000000000000000+parseInt(ins);
|
||||
ins = Number(ins).toString(8);
|
||||
if (x[4]) ins = ins.substr(0,x[4]);
|
||||
if (x[2]=='#' && ins != 0) ins = '0'+ins;
|
||||
break;
|
||||
case "s":
|
||||
ins = String(ins);
|
||||
if (x[4]) ins = ins.substr(0,x[4]);
|
||||
break;
|
||||
case "x":
|
||||
case "X":
|
||||
if (ins<0) ins = 0x10000000000000000+parseInt(ins);
|
||||
ins = Number(ins).hex(-x[4]);
|
||||
if (x[4]) ins = ins.substr(0,x[4]);
|
||||
if (x[2]=='#') ins = '0x'+ins;
|
||||
if (x[5]=='X') ins = ins.toUpperCase();
|
||||
break;
|
||||
}
|
||||
if (sign) ins = x[2]+ins;
|
||||
if (x[3]) ins = (x[2]=='-' || x[3]<0)?ins.padRight(x[3]):ins.padLeft(x[3],x[2]=='0'?0:" ");
|
||||
return ins;
|
||||
})
|
||||
return frmt.replace(/\0\0/g, "%");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue