source: node_modules/d3-format/src/formatTrim.js

Last change on this file was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 399 bytes
Line 
1// Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
2export default function(s) {
3 out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
4 switch (s[i]) {
5 case ".": i0 = i1 = i; break;
6 case "0": if (i0 === 0) i0 = i; i1 = i; break;
7 default: if (!+s[i]) break out; if (i0 > 0) i0 = 0; break;
8 }
9 }
10 return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
11}
Note: See TracBrowser for help on using the repository browser.