Skip to content

Commit 3ea8d90

Browse files
committed
refactor adjustFormat
1 parent 320b270 commit 3ea8d90

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

src/lib/index.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,25 @@ var BADNUM = numConstants.BADNUM;
1212
var lib = module.exports = {};
1313

1414
lib.adjustFormat = function(a) {
15-
if(!a) return a;
16-
var b = a;
17-
if(b === '0.f') return '~f';
18-
if(/^[0123456789].[0123456789]f/.test(b)) return a;
19-
if(/.[0123456789]%/.test(b)) return a;
20-
if(/^[0123456789]%/.test(b)) return '~%';
21-
if(/^[0123456789]s/.test(b)) return '~s';
22-
if(!(/^[~,.0$]/.test(b)) && /[&fps]/.test(b)) {
23-
// try adding tilde to the start of format in order to trim
24-
b = '~' + b;
25-
}
26-
return b;
15+
if(
16+
!a ||
17+
/^[0123456789].[0123456789]f/.test(a) ||
18+
/.[0123456789]%/.test(a)
19+
) return a;
20+
21+
if(a === '0.f') return '~f';
22+
if(/^[0123456789]%/.test(a)) return '~%';
23+
if(/^[0123456789]s/.test(a)) return '~s';
24+
25+
// try adding tilde to the start of format in order to trim
26+
if(!(/^[~,.0$]/.test(a)) && /[&fps]/.test(a)) return '~' + a;
27+
28+
return a;
2729
};
2830

2931
var d3Format = require('d3-format').format;
3032
var numberFormat = function(a) {
31-
var b = lib.adjustFormat(a);
32-
33-
// console.log('"' + a + '" > "' + b + '"');
34-
35-
return d3Format(b);
33+
return d3Format(lib.adjustFormat(a));
3634
};
3735
lib.numberFormat = numberFormat;
3836

0 commit comments

Comments
 (0)