File tree Expand file tree Collapse file tree 2 files changed +30
-16
lines changed Expand file tree Collapse file tree 2 files changed +30
-16
lines changed Original file line number Diff line number Diff line change @@ -12,25 +12,33 @@ var BADNUM = numConstants.BADNUM;
12
12
13
13
var lib = module . exports = { } ;
14
14
15
- lib . adjustFormat = function adjustFormat ( a ) {
15
+ lib . adjustFormat = function adjustFormat ( formatStr ) {
16
16
if (
17
- ! a ||
18
- / ^ [ 0 1 2 3 4 5 6 7 8 9 ] .[ 0 1 2 3 4 5 6 7 8 9 ] f / . test ( a ) ||
19
- / .[ 0 1 2 3 4 5 6 7 8 9 ] % / . test ( a )
20
- ) return a ;
17
+ ! formatStr ||
18
+ / ^ [ 0 1 2 3 4 5 6 7 8 9 ] .[ 0 1 2 3 4 5 6 7 8 9 ] f / . test ( formatStr ) ||
19
+ / .[ 0 1 2 3 4 5 6 7 8 9 ] % / . test ( formatStr )
20
+ ) return formatStr ;
21
21
22
- if ( a === '0.f' ) return '~f' ;
23
- if ( / ^ [ 0 1 2 3 4 5 6 7 8 9 ] % / . test ( a ) ) return '~%' ;
24
- if ( / ^ [ 0 1 2 3 4 5 6 7 8 9 ] s / . test ( a ) ) return '~s' ;
22
+ if ( formatStr === '0.f' ) return '~f' ;
23
+ if ( / ^ [ 0 1 2 3 4 5 6 7 8 9 ] % / . test ( formatStr ) ) return '~%' ;
24
+ if ( / ^ [ 0 1 2 3 4 5 6 7 8 9 ] s / . test ( formatStr ) ) return '~s' ;
25
25
26
26
// try adding tilde to the start of format in order to trim
27
- if ( ! ( / ^ [ ~ , . 0 $ ] / . test ( a ) ) && / [ & f p s ] / . test ( a ) ) return '~' + a ;
27
+ if ( ! ( / ^ [ ~ , . 0 $ ] / . test ( formatStr ) ) && / [ & f p s ] / . test ( formatStr ) ) return '~' + formatStr ;
28
28
29
- return a ;
29
+ return formatStr ;
30
30
} ;
31
31
32
- lib . numberFormat = function ( a ) {
33
- return d3Format ( lib . adjustFormat ( a ) ) ;
32
+ lib . noFormat = function ( value ) { return value ; } ;
33
+
34
+ lib . numberFormat = function ( formatStr ) {
35
+ try {
36
+ formatStr = d3Format ( lib . adjustFormat ( formatStr ) ) ;
37
+ } catch ( e ) {
38
+ return lib . noFormat ;
39
+ }
40
+
41
+ return formatStr ;
34
42
} ;
35
43
36
44
lib . nestedProperty = require ( './nested_property' ) ;
Original file line number Diff line number Diff line change @@ -703,10 +703,16 @@ function getFormatter(formatObj, separators) {
703
703
formatObj . thousands = separators . charAt ( 1 ) ;
704
704
705
705
return {
706
- numberFormat : function ( a ) {
707
- return formatLocale ( formatObj ) . format (
708
- Lib . adjustFormat ( a )
709
- ) ;
706
+ numberFormat : function ( formatStr ) {
707
+ try {
708
+ formatStr = formatLocale ( formatObj ) . format (
709
+ Lib . adjustFormat ( formatStr )
710
+ ) ;
711
+ } catch ( e ) {
712
+ return Lib . noFormat ;
713
+ }
714
+
715
+ return formatStr ;
710
716
} ,
711
717
timeFormat : timeFormatLocale ( formatObj ) . utcFormat
712
718
} ;
You can’t perform that action at this time.
0 commit comments