Feat plugin stock (#196)

This commit is contained in:
Simon Lecoq
2021-03-21 17:52:05 +01:00
committed by GitHub
parent 89182c62c0
commit ed5dc9a53c
11 changed files with 330 additions and 5 deletions

View File

@@ -28,10 +28,12 @@
}
/**Formatter */
export function format(n, {sign = false} = {}) {
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}`
export function format(n, {sign = false, unit = true} = {}) {
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}`
}