@@ -32,7 +32,7 @@ export const formatThousands = (val: string, options: IOptions): string => {
32
32
33
33
export const partialFormat = ( val : string , options : IOptions ) : string => {
34
34
val = val . replace ( new RegExp ( `[${ options . thousands } ]` , "g" ) , "" ) ;
35
- val = removeleadingZeros ( val , options ) ;
35
+ val = removeLeadingZeros ( val , options ) ;
36
36
val = removeExtraDecimals ( val , options ) ;
37
37
val = formatThousands ( val , options ) ;
38
38
@@ -73,16 +73,14 @@ export const fullFormat = (val: string, options: IOptions): string => {
73
73
}
74
74
} ;
75
75
76
- // TODO: fix typoes
77
- export const removeleadingZeros = ( val : string , options : IOptions ) : string => {
76
+ const removeLeadingZeros = ( val : string , options : IOptions ) : string => {
78
77
const decimalIndex = getDecimalIndex ( val , options . decimal ) ;
79
78
const sign = val [ 0 ] === "-" ? val [ 0 ] : "" ;
80
79
let integerPart = val . slice ( sign ? 1 : 0 , decimalIndex + 1 ) ;
81
80
const decimalPart = val . slice ( decimalIndex + 1 ) ;
82
81
83
82
const i = 0 ;
84
83
85
- // TODO: investigate compile error with == 0
86
84
while (
87
85
integerPart [ i ] === "0"
88
86
&& integerPart [ i + 1 ] !== options . decimal
@@ -94,7 +92,7 @@ export const removeleadingZeros = (val: string, options: IOptions): string => {
94
92
return `${ sign } ${ integerPart } ${ decimalPart } ` ;
95
93
} ;
96
94
97
- export const removeExtraDecimals = ( val : string , options : IOptions ) : string => {
95
+ const removeExtraDecimals = ( val : string , options : IOptions ) : string => {
98
96
const decimalIndex = getDecimalIndex ( val , options . decimal ) ;
99
97
const integerPart = val . slice ( 0 , decimalIndex + 1 ) ;
100
98
const decimalPart = val . slice ( decimalIndex + 1 )
@@ -140,7 +138,6 @@ export const allowedZero = (val: string, char: string, caretPos: number, options
140
138
if ( ( integerPart . length > 0 ) && ( caretPos < integerPart . length + 1 ) ) {
141
139
// IF integer part is just a zero then no zeros can be added
142
140
// ELSE the zero can not be added at the front of the value
143
- // TODO: investigate compile error with == 0
144
141
return integerPart === "0" ? false : caretPos > 0 ;
145
142
} else {
146
143
return true ;
@@ -187,8 +184,7 @@ export const parseString = (str: string, options: IOptions): string => {
187
184
let parsed = "" ;
188
185
189
186
for ( const c of str ) {
190
- // TODO: type c properly
191
- if ( ! isNaN ( c as any ) ) { // If a number
187
+ if ( ! isNaN ( Number ( c ) ) ) { // If a number
192
188
parsed += c ;
193
189
} else if ( c === options . decimal && parsed . indexOf ( c ) === - 1 ) { // If a decimal (and no decimals exist so far)
194
190
parsed += options . decimal ;
0 commit comments