Some checks failed
CI/CD Pipeline / unit-tests (push) Failing after 1m16s
CI/CD Pipeline / integration-tests (push) Failing after 2m32s
CI/CD Pipeline / lint (push) Successful in 5m22s
CI/CD Pipeline / e2e-tests (push) Has been skipped
CI/CD Pipeline / build (push) Has been skipped
12 lines
399 B
JavaScript
12 lines
399 B
JavaScript
// Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
|
|
export default function(s) {
|
|
out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
|
|
switch (s[i]) {
|
|
case ".": i0 = i1 = i; break;
|
|
case "0": if (i0 === 0) i0 = i; i1 = i; break;
|
|
default: if (!+s[i]) break out; if (i0 > 0) i0 = 0; break;
|
|
}
|
|
}
|
|
return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
|
|
}
|