@dataloop-ai/components 0.15.2 → 0.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataloop-ai/components",
3
- "version": "0.15.2",
3
+ "version": "0.15.3",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./models": "./models.ts",
@@ -88,7 +88,10 @@ export default defineComponent({
88
88
  return value[0].toUpperCase() + value.slice(1)
89
89
  },
90
90
  abbreviateNumber(nr: number) {
91
- if (nr) return abbreviateToString(nr)
91
+ if (typeof nr === 'number') {
92
+ return abbreviateToString(nr)
93
+ }
94
+ return nr
92
95
  },
93
96
  computeClass(value: string): (string | boolean)[] {
94
97
  return [value, this.small && `${value}--small`]
@@ -1,14 +1,23 @@
1
- export function abbreviateToString(value: number): string {
2
- const suffixes = ['', 'k', 'm', 'b', 't']
3
- const suffixNum = Math.floor(('' + value).length / 3)
4
- const shortValue = parseFloat(
5
- (suffixNum !== 0
6
- ? value / Math.pow(1000, suffixNum)
7
- : value
8
- ).toPrecision(2)
9
- )
10
- if (shortValue % 1 !== 0) {
11
- shortValue.toFixed(1)
1
+ export function abbreviateToString(num: number, precision: number = 1): string {
2
+ const abbreviations = [
3
+ { value: 1e12, suffix: 'T' },
4
+ { value: 1e9, suffix: 'B' },
5
+ { value: 1e6, suffix: 'M' },
6
+ { value: 1e3, suffix: 'K' }
7
+ ]
8
+
9
+ const match = abbreviations.find((abb) => num >= abb.value)
10
+ if (!match) {
11
+ return num.toString()
12
+ }
13
+
14
+ const abbreviated = (num / match.value).toFixed(precision)
15
+ const formatted = Number(abbreviated).toString()
16
+ const suffix = match.suffix
17
+
18
+ if (formatted.includes('.')) {
19
+ return formatted.replace(/\.?0*$/, '') + suffix
20
+ } else {
21
+ return formatted + suffix
12
22
  }
13
- return shortValue + suffixes[suffixNum]
14
23
  }