Permalink
Browse files

code linted

  • Loading branch information...
1 parent 491ce59 commit 333a2256a199a06bcc316f62fb850ad4bd434f05 @therazor committed Jun 21, 2012
Showing with 33 additions and 30 deletions.
  1. +33 −30 lib/globalize.js
View
@@ -701,7 +701,7 @@ formatDate = function( value, format, culture ) {
rounded = Math.round( number * factor ) / factor;
return isFinite(rounded) ? rounded : number;
- },
+ };
expandInt = function( number, padToLength, formatInfo ) {
var numberString = Math.abs(truncate( number )).toString(),
@@ -728,7 +728,7 @@ formatDate = function( value, format, culture ) {
}
return (number < 0 ? '-' : '') + numberString.slice( 0, stringIndex + 1 ) + ( ret.length ? (sep + ret) : '' );
- },
+ };
expandNumber = function( number, precision, formatInfo ) {
number = roundNumber( number, precision );
@@ -764,22 +764,22 @@ formatDate = function( value, format, culture ) {
}
return expandInt( number, 1, formatInfo ) + right;
- },
+ };
/* handles formats such as #,#.00
- * -----------------------------------
- * The functionality and results from this method are meant to closely resemble
- * C# custom number formatting: http://msdn.microsoft.com/en-us/library/0c899ak8.aspx
- * Notable exceptions are:
- * 1) '' are not used to pass literal content. Use \ instead.
- * (e.g. "'#'" should be "\\#" instead)
- * 2) when using ; section separators, do not fall back to the positive
- * section with nonpositive numbers, if the nonpositive section doesn't have
- * any formatting token.
- * (e.g. "class=positive;class=negative" becomes "class=negative" with a number < 0.)
- * 3) negative signs are always placed at the beginning of the
- * leftmost formatting token.
- * (e.g. "<li>#.#</li>" becomes "<li>-12.43</li>")
+ * -----------------------------------
+ * The functionality and results from this method are meant to closely resemble
+ * C# custom number formatting: http://msdn.microsoft.com/en-us/library/0c899ak8.aspx
+ * Notable exceptions are:
+ * 1) '' are not used to pass literal content. Use \ instead.
+ * (e.g. "'#'" should be "\\#" instead)
+ * 2) when using ; section separators, do not fall back to the positive
+ * section with nonpositive numbers, if the nonpositive section doesn't have
+ * any formatting token.
+ * (e.g. "class=positive;class=negative" becomes "class=negative" with a number < 0.)
+ * 3) negative signs are always placed at the beginning of the
+ * leftmost formatting token.
+ * (e.g. "<li>#.#</li>" becomes "<li>-12.43</li>")
*/
// FIXME: implement number scaling
customNumberFormat = function( value, format, formatInfo ) {
@@ -826,11 +826,10 @@ formatDate = function( value, format, culture ) {
return ret;
}
-
- // FIXME ignore escaped ; first
+
// Now this would be nice and easy with javascript's
// variable length negative lookbehind regex... o wait
- // var patterns = format.split(/(?<!([\\]{2})*\\);/, 3),
+ // var patterns = format.split(/(?<!(?:[\\]{2})*\\);/, 3),
var patterns = notEscapedSplit( format, ';', 3 ),
zeroPattern,
pattern;
@@ -853,11 +852,13 @@ formatDate = function( value, format, culture ) {
case 3:
if ( value === 0 )
patterns = patterns.slice( 2 );
+ /* falls through */
case 2:
if ( value < 0 ) {
patterns = patterns.slice( 1 );
value = Math.abs( value );
}
+ /* falls through */
case 1:
pattern = patterns[0];
}
@@ -887,9 +888,9 @@ formatDate = function( value, format, culture ) {
if ( !isEscaped && pattern.charAt(i) === ',' ) {
if ( !~arrayIndexOf( uniqueCharsFound, '.' ) &&
- ( subpatterns.length ||
- ( subpatternContainer === subpatterns && subpattern.length )
- )
+ ( subpatterns.length ||
+ ( subpatternContainer === subpatterns && subpattern.length )
+ )
)
hasGroupsSeparator = true;
} else if ( i !== len ) {
@@ -907,7 +908,7 @@ formatDate = function( value, format, culture ) {
// is used to format the number 100 million, the output is "100".
if ( /[.]/.test( pattern.charAt(i) ) ) {
if ( ~arrayIndexOf( uniqueCharsFound, pattern.charAt(i) ) ||
- ( pattern.charAt(i) == ',' && ~arrayIndexOf( uniqueCharsFound, '.' ) ) )
+ ( pattern.charAt(i) == ',' && ~arrayIndexOf( uniqueCharsFound, '.' ) ) )
continue;
else if ( pattern.charAt(i) == '.' )
decimalsSeparatorIndex = subpatterns.length;
@@ -928,7 +929,7 @@ formatDate = function( value, format, culture ) {
prevSubpatternContainer = subpatternContainer;
}
- };
+ }
if ( subpattern !== '' )
subpatternContainer.push( subpattern );
@@ -975,10 +976,10 @@ formatDate = function( value, format, culture ) {
formattedIntDec[0] = '-' + formattedIntDec[0];
}
+ var decimalPlaces;
if ( ~decimalsSeparatorIndex && intDecPatterns.length > 1 && intDecPatterns[1] !== '' ) {
var splitRounded = roundedString.split('.'),
- roundedDecimals = splitRounded.length > 1 ? splitRounded[1] : '',
- decimalPlaces;
+ roundedDecimals = splitRounded.length > 1 ? splitRounded[1] : '';
if ( roundedDecimals.length > decimalsLengthRange[1] )
decimalPlaces = decimalsLengthRange[1];
@@ -988,15 +989,17 @@ formatDate = function( value, format, culture ) {
decimalPlaces = roundedDecimals.length;
formattedIntDec.push( zeroPad( roundedDecimals, decimalPlaces, false ) );
- }
+ } else
+ decimalPlaces = 0;
var curFragment,
decimalPlacesGap = decimalsLengthRange[1] - decimalPlaces,
- curIntLength = 0;
+ curIntLength = 0,
+ sliceLength;
for ( i = subpatterns.length - 1; i > 0; i-- ) {
if ( i > decimalsSeparatorIndex && formattedIntDec.length > 1 ) { // decimal part
- var sliceLength = subpatterns[i].length - ( subpatterns[i].lastIndexOf( '.' ) + 1 );
+ sliceLength = subpatterns[i].length - ( subpatterns[i].lastIndexOf( '.' ) + 1 );
curFragment = formattedIntDec[1].substring( formattedIntDec[1].length -
Math.max( sliceLength - decimalPlacesGap, 0 ) );
@@ -1007,7 +1010,7 @@ formatDate = function( value, format, culture ) {
decimalPlacesGap -= sliceLength - curFragment.length;
}
if ( i <= decimalsSeparatorIndex || !~decimalsSeparatorIndex ) { // int part
- var sliceLength = subpatterns[i].indexOf( '.' );
+ sliceLength = subpatterns[i].indexOf( '.' );
if ( !~sliceLength )
sliceLength = subpatterns[i].length;
if ( hasGroupsSeparator )

0 comments on commit 333a225

Please sign in to comment.