1+ import { CURRENCY , PERCENT , LIST_SEPARATOR , GROUP_SEPARATOR , CURRENCY_PLACEHOLDER , PERCENT_PLACEHOLDER , POINT , EMPTY } from '../common/constants' ;
12import formatCurrencySymbol from './format-currency-symbol' ;
23import groupInteger from './group-integer' ;
34import round from '../common/round' ;
45
5- const CURRENCY_SYMBOL = "$" ;
6- const PERCENT_SYMBOL = "%" ;
76const PLACEHOLDER = "__??__" ;
8- const CURRENCY = "currency" ;
9- const PERCENT = "percent" ;
10- const POINT = "." ;
11- const COMMA = "," ;
7+
128const SHARP = "#" ;
139const ZERO = "0" ;
14- const EMPTY = "" ;
1510
1611const literalRegExp = / ( \\ .) | ( [ ' ] [ ^ ' ] * [ ' ] ? ) | ( [ " ] [ ^ " ] * [ " ] ? ) / g;
1712const trailingZerosRegExp = / ( \. (?: [ 0 - 9 ] * [ 1 - 9 ] ) ? ) 0 + $ / g;
@@ -23,8 +18,8 @@ function setFormatLiterals(formatOptions) {
2318 if ( format . indexOf ( "'" ) > - 1 || format . indexOf ( "\"" ) > - 1 || format . indexOf ( "\\" ) > - 1 ) {
2419 const literals = formatOptions . literals = [ ] ;
2520 formatOptions . format = format . replace ( literalRegExp , function ( match ) {
26- const quoteChar = match . charAt ( 0 ) . replace ( "\\" , "" ) ;
27- const literal = match . slice ( 1 ) . replace ( quoteChar , "" ) ;
21+ const quoteChar = match . charAt ( 0 ) . replace ( "\\" , EMPTY ) ;
22+ const literal = match . slice ( 1 ) . replace ( quoteChar , EMPTY ) ;
2823
2924 literals . push ( literal ) ;
3025
@@ -42,7 +37,7 @@ function trimTrailingZeros(value, lastZero) {
4237 trimRegex = new RegExp ( `(\\.[0-9]{${ lastZero } }[1-9]*)0+$` , 'g' ) ;
4338 }
4439
45- return value . replace ( trimRegex , '$1' ) . replace ( trailingPointRegExp , '' ) ;
40+ return value . replace ( trimRegex , '$1' ) . replace ( trailingPointRegExp , EMPTY ) ;
4641}
4742
4843function roundNumber ( formatOptions ) {
@@ -106,7 +101,7 @@ function isConstantFormat(format) {
106101
107102function setValueSpecificFormat ( formatOptions ) {
108103 let { number, format } = formatOptions ;
109- format = format . split ( ";" ) ;
104+ format = format . split ( LIST_SEPARATOR ) ;
110105 if ( formatOptions . negative && format [ 1 ] ) {
111106 format = format [ 1 ] ;
112107 formatOptions . hasNegativeFormat = true ;
@@ -127,20 +122,20 @@ function setStyleOptions(formatOptions, info) {
127122 const format = formatOptions . format ;
128123
129124 //multiply number if the format has percent
130- if ( format . indexOf ( PERCENT_SYMBOL ) !== - 1 ) {
125+ if ( format . indexOf ( PERCENT_PLACEHOLDER ) !== - 1 ) {
131126 formatOptions . style = PERCENT ;
132127 formatOptions . symbol = info . numbers . symbols . percentSign ;
133128 formatOptions . number *= 100 ;
134129 }
135130
136- if ( format . indexOf ( CURRENCY_SYMBOL ) !== - 1 ) {
131+ if ( format . indexOf ( CURRENCY_PLACEHOLDER ) !== - 1 ) {
137132 formatOptions . style = CURRENCY ;
138133 formatOptions . symbol = formatCurrencySymbol ( info ) ;
139134 }
140135}
141136
142137function setGroupOptions ( formatOptions ) {
143- formatOptions . hasGroup = formatOptions . format . indexOf ( COMMA ) > - 1 ;
138+ formatOptions . hasGroup = formatOptions . format . indexOf ( GROUP_SEPARATOR ) > - 1 ;
144139 if ( formatOptions . hasGroup ) {
145140 formatOptions . format = formatOptions . format . replace ( commaRegExp , EMPTY ) ;
146141 }
@@ -185,7 +180,7 @@ function replaceStyleSymbols(number, style, symbol) {
185180 result = EMPTY ;
186181 for ( let idx = 0 , length = number . length ; idx < length ; idx ++ ) {
187182 let ch = number . charAt ( idx ) ;
188- result += ( ch === CURRENCY_SYMBOL || ch === PERCENT_SYMBOL ) ? symbol : ch ;
183+ result += ( ch === CURRENCY_PLACEHOLDER || ch === PERCENT_PLACEHOLDER ) ? symbol : ch ;
189184 }
190185 }
191186 return result ;
0 commit comments