Visual improvements on classic template
This commit is contained in:
@@ -28,14 +28,14 @@
|
||||
}
|
||||
|
||||
/**Formatter */
|
||||
export function format(n, {sign = false, unit = true} = {}) {
|
||||
export function format(n, {sign = false, unit = true, fixed} = {}) {
|
||||
if (unit) {
|
||||
for (const {u, v} of [{u:"b", v:10**9}, {u:"m", v:10**6}, {u:"k", v:10**3}]) {
|
||||
if (n/v >= 1)
|
||||
return `${(sign)&&(n > 0) ? "+" : ""}${(n/v).toFixed(2).substr(0, 4).replace(/[.]0*$/, "")}${u}`
|
||||
return `${(sign)&&(n > 0) ? "+" : ""}${(n/v).toFixed(fixed ?? 2).substr(0, 4).replace(/[.]0*$/, "")}${u}`
|
||||
}
|
||||
}
|
||||
return `${(sign)&&(n > 0) ? "+" : ""}${n}`
|
||||
return `${(sign)&&(n > 0) ? "+" : ""}${fixed ? n.toFixed(fixed) : n}`
|
||||
}
|
||||
|
||||
/**Bytes formatter */
|
||||
|
||||
Reference in New Issue
Block a user