@hanzo/ui 4.3.6 → 4.3.7
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 +1 -2
- package/tsconfig.json +1 -6
- package/util/format-to-max-char.ts +1 -1
- package/util/number-abbreviate.ts +100 -0
- package/declare.d.ts +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/ui",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.7",
|
|
4
4
|
"description": "Library that contains shared UI primitives, support for a common design system, and other boilerplate support.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -82,7 +82,6 @@
|
|
|
82
82
|
"lodash.isplainobject": "^4.0.6",
|
|
83
83
|
"lodash.merge": "^4.6.2",
|
|
84
84
|
"markdown-to-jsx": "^7.4.7",
|
|
85
|
-
"number-abbreviate": "^2.0.0",
|
|
86
85
|
"postcss-selector-parser": "^6.0.16",
|
|
87
86
|
"react-day-picker": "^8.10.1",
|
|
88
87
|
"react-intersection-observer": "^9.8.2",
|
package/tsconfig.json
CHANGED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// cf: https://github.com/domharrington/js-number-abbreviate/blob/master/index.js
|
|
2
|
+
|
|
3
|
+
const DEF_ABBREVIATIONS = ['K', 'M', 'B', 'T']
|
|
4
|
+
|
|
5
|
+
class NumberAbbreviator {
|
|
6
|
+
|
|
7
|
+
private _units: string[]
|
|
8
|
+
|
|
9
|
+
constructor(units?: string[]) {
|
|
10
|
+
this._units = units ?? DEF_ABBREVIATIONS
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
private _abbreviate = (n: number, decPlaces: number): string => {
|
|
14
|
+
|
|
15
|
+
const _decPlaces = Math.pow(10, decPlaces)
|
|
16
|
+
let _n = n
|
|
17
|
+
|
|
18
|
+
let _unit
|
|
19
|
+
for (let i = this._units.length - 1; i >= 0; i--) {
|
|
20
|
+
const size = Math.pow(10, (i + 1) * 3)
|
|
21
|
+
if (size <= _n) {
|
|
22
|
+
_n = Math.round(_n * _decPlaces / size) / _decPlaces
|
|
23
|
+
if ((_n === 1000) && (i < this._units.length - 1)) {
|
|
24
|
+
_n = 1
|
|
25
|
+
i++
|
|
26
|
+
}
|
|
27
|
+
_unit = this._units[i]
|
|
28
|
+
break
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return _n.toString() + (_unit ?? '')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
abbreviate = (n: number, decPlaces: number) => {
|
|
35
|
+
const abbreviatedNumber = this._abbreviate(Math.abs(n), decPlaces || 0)
|
|
36
|
+
return n < 0 ? '-' + abbreviatedNumber : abbreviatedNumber
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
export default NumberAbbreviator
|
|
42
|
+
|
|
43
|
+
/*
|
|
44
|
+
(function(root){
|
|
45
|
+
'use strict';
|
|
46
|
+
|
|
47
|
+
function NumberAbbreviate() {
|
|
48
|
+
var units
|
|
49
|
+
if (!(this instanceof NumberAbbreviate)) {
|
|
50
|
+
// function usage: abbrev(n, decPlaces, units)
|
|
51
|
+
var n = arguments[0]
|
|
52
|
+
var decPlaces = arguments[1]
|
|
53
|
+
units = arguments[2]
|
|
54
|
+
var ab = new NumberAbbreviate(units)
|
|
55
|
+
return ab.abbreviate(n, decPlaces)
|
|
56
|
+
}
|
|
57
|
+
// class usage: new NumberAbbreviate(units)
|
|
58
|
+
units = arguments[0]
|
|
59
|
+
this.units = units == null ? ['k', 'm', 'b', 't'] : units
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
NumberAbbreviate.prototype._abbreviate = function(number, decPlaces) {
|
|
63
|
+
decPlaces = Math.pow(10, decPlaces)
|
|
64
|
+
|
|
65
|
+
for (var i = this.units.length - 1; i >= 0; i--) {
|
|
66
|
+
|
|
67
|
+
var size = Math.pow(10, (i + 1) * 3)
|
|
68
|
+
|
|
69
|
+
if (size <= number) {
|
|
70
|
+
number = Math.round(number * decPlaces / size) / decPlaces
|
|
71
|
+
|
|
72
|
+
if ((number === 1000) && (i < this.units.length - 1)) {
|
|
73
|
+
number = 1
|
|
74
|
+
i++
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
number += this.units[i]
|
|
78
|
+
|
|
79
|
+
break
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return number
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
NumberAbbreviate.prototype.abbreviate = function(number, decPlaces) {
|
|
87
|
+
var isNegative = number < 0
|
|
88
|
+
var abbreviatedNumber = this._abbreviate(Math.abs(number), decPlaces || 0)
|
|
89
|
+
|
|
90
|
+
return isNegative ? '-' + abbreviatedNumber : abbreviatedNumber;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
94
|
+
module.exports = NumberAbbreviate
|
|
95
|
+
} else {
|
|
96
|
+
root.NumberAbbreviate = NumberAbbreviate
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
})(this);
|
|
100
|
+
*/
|
package/declare.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
declare module 'number-abbreviate'
|