2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
Vn.Value =
|
|
|
|
{
|
|
|
|
regexpNumber: /%\.([0-9]+)d/g
|
|
|
|
,regexpString: /%s/g
|
|
|
|
|
|
|
|
,compare: function (a, b)
|
|
|
|
{
|
|
|
|
if (a === b)
|
|
|
|
return true;
|
|
|
|
if (typeof a === typeof b && a instanceof Date)
|
|
|
|
return a.getTime () === b.getTime ();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
,format: function (value, format)
|
|
|
|
{
|
|
|
|
if (value === null || value === undefined)
|
|
|
|
return '';
|
|
|
|
|
|
|
|
if (format)
|
|
|
|
switch (typeof value)
|
|
|
|
{
|
|
|
|
case 'number':
|
|
|
|
return format.replace (this.regexpNumber,
|
|
|
|
this.replaceNumber.bind (null, value));
|
|
|
|
case 'string':
|
|
|
|
return format.replace (this.regexpString,
|
|
|
|
this.replaceString.bind (null, value));
|
|
|
|
case 'object':
|
|
|
|
if (value instanceof Date)
|
|
|
|
return Vn.Date.strftime (value, format);
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
,replaceNumber: function (value, token, digits)
|
|
|
|
{
|
|
|
|
return new Number (value).toFixed (parseInt (digits));
|
|
|
|
}
|
|
|
|
|
|
|
|
,replaceString: function (value)
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
};
|
2015-08-27 14:04:34 +00:00
|
|
|
|
|
|
|
function sprintf (formatString)
|
|
|
|
{
|
|
|
|
var args = arguments;
|
|
|
|
|
|
|
|
if (args.length <= 1)
|
|
|
|
return formatString;
|
|
|
|
|
|
|
|
var i = 1;
|
|
|
|
return formatString.replace (/%[s|d]/g, function ()
|
|
|
|
{
|
|
|
|
return args[i++];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|