@gearbox-protocol/permissionless-ui 1.15.4 → 1.15.5
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/dist/cjs/components/health-factor/health-factor.cjs +1 -1
- package/dist/cjs/components/trading-view/graph-dropdown.cjs +1 -1
- package/dist/cjs/utils/format-money.cjs +1 -1
- package/dist/cjs/utils/format-number.cjs +1 -1
- package/dist/esm/components/health-factor/health-factor.js +1 -1
- package/dist/esm/components/trading-view/graph-dropdown.js +20 -19
- package/dist/esm/utils/format-money.js +8 -8
- package/dist/esm/utils/format-number.js +55 -47
- package/dist/types/utils/format-money.d.ts +3 -1
- package/dist/types/utils/format-number.d.ts +4 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("react/jsx-runtime");require("react");const _=require("../../utils/cn.cjs");require("sonner");require("@gearbox-protocol/sdk");const n=require("../../utils/format-money.cjs"),u=15e3,c=11e3,q=10500,s=t=>{if(!t)return;const e=Number(t);return e>=u?"good":e>c?"medium":e>q?"bad":e>n.PERCENTAGE_FACTOR?"critical":"liquidation"};function C({value:t,debt:e,decimals:a=3,zone:r,showColor:l=!0,className:d,...m}){const o=e!==void 0&&e===0n,i=(()=>{if(!o)return r??s(t)})(),f=()=>{if(!l||i===void 0)return"";switch(i){case"good":return"text-green-600";case"medium":return"text-yellow-600";case"bad":return"text-orange-500";case"critical":case"liquidation":return"text-destructive";default:return""}},g=()=>{if(o)return"N/A";const F=Number(t)/n.PERCENTAGE_FACTOR,A=n.formatPercentAmount(F,a);return String(A)};return H.jsx("div",{className:_.cn("font-medium",f(),d),...m,children:g()})}exports.BAD_HF=c;exports.GOOD_HF=u;exports.HealthFactor=C;exports.getHFZones=s;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("react/jsx-runtime");require("react");const _=require("../../utils/cn.cjs");require("sonner");require("@gearbox-protocol/sdk");const n=require("../../utils/format-money.cjs"),u=15e3,c=11e3,q=10500,s=t=>{if(!t)return;const e=Number(t);return e>=u?"good":e>c?"medium":e>q?"bad":e>n.PERCENTAGE_FACTOR?"critical":"liquidation"};function C({value:t,debt:e,decimals:a=3,zone:r,showColor:l=!0,className:d,...m}){const o=e!==void 0&&e===0n,i=(()=>{if(!o)return r??s(t)})(),f=()=>{if(!l||i===void 0)return"";switch(i){case"good":return"text-green-600";case"medium":return"text-yellow-600";case"bad":return"text-orange-500";case"critical":case"liquidation":return"text-destructive";default:return""}},g=()=>{if(o)return"N/A";const F=Number(t)/n.PERCENTAGE_FACTOR,A=n.formatPercentAmount(F,a,!1);return String(A)};return H.jsx("div",{className:_.cn("font-medium",f(),d),...m,children:g()})}exports.BAD_HF=c;exports.GOOD_HF=u;exports.HealthFactor=C;exports.getHFZones=s;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),w=require("lucide-react"),t=require("react"),o=require("../select/select.cjs");function k({items:i,defaultItem:r,onSelected:g,multiple:a=!1,graphsWithNoData:A,loadingGraphs:v,onNoDataSelected:S}){const _=()=>{if(a){const n=Array.isArray(r)?r:[r];return n.length===0?"":String(n[0].value)}const e=Array.isArray(r)?r[0]:r;return String(e?.value||"")},C=()=>{if(a){const n=Array.isArray(r)?r:[r];return new Set(n.map(s=>s.value))}const e=Array.isArray(r)?r[0]:r;return new Set([e?.value].filter(Boolean))},[u,b]=t.useState(C),[d,y]=t.useState(_()),[p,N]=t.useState(!1),f=t.useRef(!1);t.useEffect(()=>{if(a){const e=Array.isArray(r)?r:[r],n=new Set(e.map(s=>s.value));b(n),e.length>0&&y(String(e[0].value))}else{const e=Array.isArray(r)?r[0]:r;e?.value&&y(String(e.value))}},[r,a]);const O=t.useCallback(e=>{if(!e&&a&&f.current){f.current=!1;return}N(e)},[a]),j=t.useCallback(e=>{const n=i.find(s=>String(s.value)===e);if(n&&!v?.has(n.value)){if(A?.has(n.value)&&!(a&&u.has(n.value))){S&&S(n.value,n.label);return}a?(f.current=!0,b(s=>{const c=new Set(s);if(c.has(n.value)){if(c.size<=1)return s;c.delete(n.value)}else c.add(n.value);return g(Array.from(c)),c})):(y(e),g(n.value))}},[a,g,i,A,v,S,u]),x=t.useMemo(()=>{if(!a){const s=i.find(h=>String(h.value)===d),c=Array.isArray(r)?r[0]:r;return s||c}const e=Array.from(u).map(s=>i.find(c=>c.value===s)).filter(s=>!!s);return e.length===0?(Array.isArray(r)?r:[r])[0]:e.length===1?e[0]:{value:e[0].value,label:`${e.length} selected`}},[a,r,i,u,d]),R=t.useMemo(()=>a?"__multiple_placeholder__":d,[a,d]);return!i.length||i.length===1&&!a?l.jsx("div",{className:"flex items-center",style:{width:"max-content"},children:l.jsx("div",{className:"text-xl leading-6",children:x.label})}):l.jsxs(o.Select,{value:R,onValueChange:j,open:p,onOpenChange:O,children:[l.jsx(o.SelectTrigger,{className:"w-auto min-w-[16rem]",children:l.jsx(o.SelectValue,{children:x.label})}),l.jsxs(o.SelectContent,{className:"min-w-[16rem]",children:[a&&l.jsx(o.SelectItem,{value:"__multiple_placeholder__",className:"hidden",disabled:!0,children:x.label}),i.map((e,n)=>{const s=a&&u.has(e.value),c=v?.has(e.value),h=c;return l.jsx(o.SelectItem,{value:String(e.value),disabled:h,onSelect:V=>{a&&V.preventDefault(),j(String(e.value))},className:h?"opacity-50 cursor-not-allowed":"",children:l.jsxs("div",{className:"flex items-center gap-2",children:[a&&l.jsx("span",{className:`flex h-4 w-4 items-center justify-center rounded-[4px] border border-primary shadow transition-colors ${s?"bg-primary text-primary-foreground":""}`,children:s&&l.jsx(w.Check,{className:"h-4 w-4"})}),e.label,c&&l.jsx(w.Loader2,{className:"ml-1 h-4 w-4 animate-spin text-muted-foreground"})]})},`graph-item-${n}-${String(e.value)}`)})]})]})}exports.GraphDropdown=k;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@gearbox-protocol/sdk"),p=10000000000000000n;function E(t){return BigInt(t.toFixed(18).replace(".",""))}function T(t,e){const n=typeof t=="number"&&t<0||typeof t=="bigint"&&t<0n?"-":"",o=typeof t=="number"?E(Math.abs(t)):u.BigIntMath.abs(t),a=o<p&&o>0n,m=a?"0.01":u.formatBN(o,u.WAD_DECIMALS_POW,e),c=`${n}$${m}`;return a?`< ${c}`:c}const N=1e4;function i(t,e,r=!0){const n=typeof t=="number"?t:Number(t);return Number.isNaN(n)||n===void 0||n===null?"0":n===0?0:r&&n>N?n.toExponential(e):n.toFixed(e)}function l(t,e=2){return`${i(t,e)}%`}const s=1e4;function A(t,e=2){const r=Number(t)/Number(s);return`${i(r,e)}%`}const f=1000n;function b(t,e=1){return t===void 0?"-":`${(t/Number(f)).toFixed(e)}%`}exports.PERCENTAGE_FACTOR=s;exports.SLIPPAGE_DECIMALS=f;exports.formatMoney=T;exports.formatPercentAmount=i;exports.percentTemplate=l;exports.percentageTemplate=A;exports.slippageTemplate=b;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=1e-10,h=1e-4,D=1e11;function m(t){const e=Math.abs(t);return e<10?4:e<100?2:1}function u(t){return t.replace(/\.?0+$/,"")}function S(t,e={}){const{format:i="full",minimumFractionDigits:r=0,maximumFractionDigits:o,maxExponentialThreshold:l=D,adaptiveDecimals:a=!1}=e,s=o!==void 0?o:i==="short"?1:0,f=Math.abs(t);if(i==="short"){if(f>=5e8){const n=t/1e9,c=a?m(n):s;return`${u(n.toFixed(c))}B`}if(f>=1e6){const n=t/1e6,c=a?m(n):s;return`${u(n.toFixed(c))}M`}if(f>=1e3){const n=t/1e3,c=a?m(n):s;return`${u(n.toFixed(c))}K`}}return l&&f>l?t.toExponential(2):new Intl.NumberFormat("en-US",{minimumFractionDigits:r,maximumFractionDigits:s}).format(t)}function F(t,e){const i=Math.abs(t);if(i>=1){const r=10**e;return(Math.floor(t*r)/r).toFixed(e).replace(/\.?0+$/,"")}if(i>0){const r=Math.floor(Math.log10(i)),o=Math.max(e,Math.abs(r)+e),a=Math.min(o,10);return t.toFixed(a).replace(/\.?0+$/,"")}return"0"}function M(t){return Math.abs(t)<d}function x(t){const e=Math.abs(t);return e<d&&e>0}function b(t,e){if(!x(t))return null;const i=`<${h}`;return e?`${i}${e}`:i}const g={EPSILON:d,MIN_DISPLAY_THRESHOLD:h,MAX_EXPONENTIAL_THRESHOLD:D};function p(t,e=2,i=6){if(!Number.isFinite(t))return"∞";const r=1/10**e;return t<r&&t!==0?t.toFixed(i).replace(/\.?0+$/,""):t>1?new Intl.NumberFormat("en-US",{minimumFractionDigits:e,maximumFractionDigits:e}).format(t):t.toFixed(e)}exports.FORMAT_CONSTANTS=g;exports.formatNumberWithSuffix=S;exports.formatPrice=p;exports.formatSmallValue=b;exports.getAdaptiveDecimals=m;exports.isBelowDisplayThreshold=x;exports.isEffectivelyZero=M;exports.toSignificantDigits=F;
|
|
@@ -38,7 +38,7 @@ function I({
|
|
|
38
38
|
}
|
|
39
39
|
}, d = () => {
|
|
40
40
|
if (n) return "N/A";
|
|
41
|
-
const f = Number(r) / i, l = v(f, u);
|
|
41
|
+
const f = Number(r) / i, l = v(f, u, !1);
|
|
42
42
|
return String(l);
|
|
43
43
|
};
|
|
44
44
|
return /* @__PURE__ */ g("div", { className: p("font-medium", m(), s), ...a, children: d() });
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { jsx as l, jsxs as S } from "react/jsx-runtime";
|
|
2
2
|
import { Check as L, Loader2 as R } from "lucide-react";
|
|
3
|
-
import { useState as A, useRef as z, useEffect as B, useCallback as
|
|
3
|
+
import { useState as A, useRef as z, useEffect as B, useCallback as _, useMemo as p } from "react";
|
|
4
4
|
import { Select as E, SelectTrigger as M, SelectValue as T, SelectContent as q, SelectItem as C } from "../select/select.js";
|
|
5
5
|
function Q({
|
|
6
6
|
items: i,
|
|
7
7
|
defaultItem: r,
|
|
8
|
-
onSelected:
|
|
8
|
+
onSelected: d,
|
|
9
9
|
multiple: a = !1,
|
|
10
10
|
graphsWithNoData: b,
|
|
11
11
|
loadingGraphs: h,
|
|
12
|
-
onNoDataSelected:
|
|
12
|
+
onNoDataSelected: g
|
|
13
13
|
}) {
|
|
14
14
|
const N = () => {
|
|
15
15
|
if (a) {
|
|
@@ -25,7 +25,7 @@ function Q({
|
|
|
25
25
|
}
|
|
26
26
|
const e = Array.isArray(r) ? r[0] : r;
|
|
27
27
|
return new Set([e?.value].filter(Boolean));
|
|
28
|
-
}, [
|
|
28
|
+
}, [t, w] = A(V), [o, v] = A(N()), [O, $] = A(!1), f = z(!1);
|
|
29
29
|
B(() => {
|
|
30
30
|
if (a) {
|
|
31
31
|
const e = Array.isArray(r) ? r : [r], n = new Set(e.map((s) => s.value));
|
|
@@ -35,7 +35,7 @@ function Q({
|
|
|
35
35
|
e?.value && v(String(e.value));
|
|
36
36
|
}
|
|
37
37
|
}, [r, a]);
|
|
38
|
-
const j =
|
|
38
|
+
const j = _(
|
|
39
39
|
(e) => {
|
|
40
40
|
if (!e && a && f.current) {
|
|
41
41
|
f.current = !1;
|
|
@@ -44,12 +44,12 @@ function Q({
|
|
|
44
44
|
$(e);
|
|
45
45
|
},
|
|
46
46
|
[a]
|
|
47
|
-
), x =
|
|
47
|
+
), x = _(
|
|
48
48
|
(e) => {
|
|
49
49
|
const n = i.find((s) => String(s.value) === e);
|
|
50
50
|
if (n && !h?.has(n.value)) {
|
|
51
|
-
if (b?.has(n.value)) {
|
|
52
|
-
|
|
51
|
+
if (b?.has(n.value) && !(a && t.has(n.value))) {
|
|
52
|
+
g && g(n.value, n.label);
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
a ? (f.current = !0, w((s) => {
|
|
@@ -60,29 +60,30 @@ function Q({
|
|
|
60
60
|
c.delete(n.value);
|
|
61
61
|
} else
|
|
62
62
|
c.add(n.value);
|
|
63
|
-
return
|
|
64
|
-
})) : (v(e),
|
|
63
|
+
return d(Array.from(c)), c;
|
|
64
|
+
})) : (v(e), d(n.value));
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
67
|
[
|
|
68
68
|
a,
|
|
69
|
-
|
|
69
|
+
d,
|
|
70
70
|
i,
|
|
71
71
|
b,
|
|
72
72
|
h,
|
|
73
|
-
|
|
73
|
+
g,
|
|
74
|
+
t
|
|
74
75
|
]
|
|
75
|
-
), y =
|
|
76
|
+
), y = p(() => {
|
|
76
77
|
if (!a) {
|
|
77
|
-
const s = i.find((
|
|
78
|
+
const s = i.find((u) => String(u.value) === o), c = Array.isArray(r) ? r[0] : r;
|
|
78
79
|
return s || c;
|
|
79
80
|
}
|
|
80
|
-
const e = Array.from(
|
|
81
|
+
const e = Array.from(t).map((s) => i.find((c) => c.value === s)).filter((s) => !!s);
|
|
81
82
|
return e.length === 0 ? (Array.isArray(r) ? r : [r])[0] : e.length === 1 ? e[0] : {
|
|
82
83
|
value: e[0].value,
|
|
83
84
|
label: `${e.length} selected`
|
|
84
85
|
};
|
|
85
|
-
}, [a, r, i,
|
|
86
|
+
}, [a, r, i, t, o]), k = p(() => a ? "__multiple_placeholder__" : o, [a, o]);
|
|
86
87
|
return !i.length || i.length === 1 && !a ? /* @__PURE__ */ l("div", { className: "flex items-center", style: { width: "max-content" }, children: /* @__PURE__ */ l("div", { className: "text-xl leading-6", children: y.label }) }) : /* @__PURE__ */ S(
|
|
87
88
|
E,
|
|
88
89
|
{
|
|
@@ -103,16 +104,16 @@ function Q({
|
|
|
103
104
|
}
|
|
104
105
|
),
|
|
105
106
|
i.map((e, n) => {
|
|
106
|
-
const s = a &&
|
|
107
|
+
const s = a && t.has(e.value), c = h?.has(e.value), u = c;
|
|
107
108
|
return /* @__PURE__ */ l(
|
|
108
109
|
C,
|
|
109
110
|
{
|
|
110
111
|
value: String(e.value),
|
|
111
|
-
disabled:
|
|
112
|
+
disabled: u,
|
|
112
113
|
onSelect: (F) => {
|
|
113
114
|
a && F.preventDefault(), x(String(e.value));
|
|
114
115
|
},
|
|
115
|
-
className:
|
|
116
|
+
className: u ? "opacity-50 cursor-not-allowed" : "",
|
|
116
117
|
children: /* @__PURE__ */ S("div", { className: "flex items-center gap-2", children: [
|
|
117
118
|
a && /* @__PURE__ */ l(
|
|
118
119
|
"span",
|
|
@@ -4,21 +4,21 @@ function p(t) {
|
|
|
4
4
|
return BigInt(t.toFixed(18).replace(".", ""));
|
|
5
5
|
}
|
|
6
6
|
function _(t, n) {
|
|
7
|
-
const
|
|
8
|
-
return
|
|
7
|
+
const e = typeof t == "number" && t < 0 || typeof t == "bigint" && t < 0n ? "-" : "", o = typeof t == "number" ? p(Math.abs(t)) : s.abs(t), u = o < N && o > 0n, f = u ? "0.01" : a(o, m, n), i = `${e}$${f}`;
|
|
8
|
+
return u ? `< ${i}` : i;
|
|
9
9
|
}
|
|
10
10
|
const E = 1e4;
|
|
11
|
-
function
|
|
11
|
+
function c(t, n, r = !0) {
|
|
12
12
|
const e = typeof t == "number" ? t : Number(t);
|
|
13
|
-
return Number.isNaN(e) || e === void 0 || e === null ? "0" : e === 0 ? 0 : e > E ? e.toExponential(n) : e.toFixed(n);
|
|
13
|
+
return Number.isNaN(e) || e === void 0 || e === null ? "0" : e === 0 ? 0 : r && e > E ? e.toExponential(n) : e.toFixed(n);
|
|
14
14
|
}
|
|
15
15
|
function d(t, n = 2) {
|
|
16
|
-
return `${
|
|
16
|
+
return `${c(t, n)}%`;
|
|
17
17
|
}
|
|
18
18
|
const T = 1e4;
|
|
19
19
|
function g(t, n = 2) {
|
|
20
|
-
const
|
|
21
|
-
return `${
|
|
20
|
+
const r = Number(t) / Number(T);
|
|
21
|
+
return `${c(r, n)}%`;
|
|
22
22
|
}
|
|
23
23
|
const b = 1000n;
|
|
24
24
|
function l(t, n = 1) {
|
|
@@ -28,7 +28,7 @@ export {
|
|
|
28
28
|
T as PERCENTAGE_FACTOR,
|
|
29
29
|
b as SLIPPAGE_DECIMALS,
|
|
30
30
|
_ as formatMoney,
|
|
31
|
-
|
|
31
|
+
c as formatPercentAmount,
|
|
32
32
|
d as percentTemplate,
|
|
33
33
|
g as percentageTemplate,
|
|
34
34
|
l as slippageTemplate
|
|
@@ -1,73 +1,81 @@
|
|
|
1
1
|
function u(t) {
|
|
2
|
-
const
|
|
3
|
-
return
|
|
2
|
+
const n = Math.abs(t);
|
|
3
|
+
return n < 10 ? 4 : n < 100 ? 2 : 1;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
5
|
+
function l(t) {
|
|
6
6
|
return t.replace(/\.?0+$/, "");
|
|
7
7
|
}
|
|
8
|
-
function
|
|
8
|
+
function d(t, n = {}) {
|
|
9
9
|
const {
|
|
10
|
-
format:
|
|
11
|
-
minimumFractionDigits:
|
|
12
|
-
maximumFractionDigits:
|
|
13
|
-
maxExponentialThreshold:
|
|
14
|
-
adaptiveDecimals:
|
|
15
|
-
} =
|
|
16
|
-
if (
|
|
17
|
-
if (
|
|
18
|
-
const r = t / 1e9,
|
|
19
|
-
return `${
|
|
10
|
+
format: e = "full",
|
|
11
|
+
minimumFractionDigits: i = 0,
|
|
12
|
+
maximumFractionDigits: o,
|
|
13
|
+
maxExponentialThreshold: m = 1e11,
|
|
14
|
+
adaptiveDecimals: a = !1
|
|
15
|
+
} = n, s = o !== void 0 ? o : e === "short" ? 1 : 0, f = Math.abs(t);
|
|
16
|
+
if (e === "short") {
|
|
17
|
+
if (f >= 5e8) {
|
|
18
|
+
const r = t / 1e9, c = a ? u(r) : s;
|
|
19
|
+
return `${l(r.toFixed(c))}B`;
|
|
20
20
|
}
|
|
21
|
-
if (
|
|
22
|
-
const r = t / 1e6,
|
|
23
|
-
return `${
|
|
21
|
+
if (f >= 1e6) {
|
|
22
|
+
const r = t / 1e6, c = a ? u(r) : s;
|
|
23
|
+
return `${l(r.toFixed(c))}M`;
|
|
24
24
|
}
|
|
25
|
-
if (
|
|
26
|
-
const r = t / 1e3,
|
|
27
|
-
return `${
|
|
25
|
+
if (f >= 1e3) {
|
|
26
|
+
const r = t / 1e3, c = a ? u(r) : s;
|
|
27
|
+
return `${l(r.toFixed(c))}K`;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
return
|
|
31
|
-
minimumFractionDigits:
|
|
30
|
+
return m && f > m ? t.toExponential(2) : new Intl.NumberFormat("en-US", {
|
|
31
|
+
minimumFractionDigits: i,
|
|
32
32
|
maximumFractionDigits: s
|
|
33
33
|
}).format(t);
|
|
34
34
|
}
|
|
35
|
-
function
|
|
36
|
-
const
|
|
37
|
-
|
|
35
|
+
function S(t, n) {
|
|
36
|
+
const e = Math.abs(t);
|
|
37
|
+
if (e >= 1) {
|
|
38
|
+
const i = 10 ** n;
|
|
39
|
+
return (Math.floor(t * i) / i).toFixed(n).replace(/\.?0+$/, "");
|
|
40
|
+
}
|
|
41
|
+
if (e > 0) {
|
|
42
|
+
const i = Math.floor(Math.log10(e)), o = Math.max(n, Math.abs(i) + n), a = Math.min(o, 10);
|
|
43
|
+
return t.toFixed(a).replace(/\.?0+$/, "");
|
|
44
|
+
}
|
|
45
|
+
return "0";
|
|
38
46
|
}
|
|
39
|
-
function
|
|
47
|
+
function E(t) {
|
|
40
48
|
return Math.abs(t) < 1e-10;
|
|
41
49
|
}
|
|
42
|
-
function
|
|
43
|
-
const
|
|
44
|
-
return
|
|
50
|
+
function D(t) {
|
|
51
|
+
const n = Math.abs(t);
|
|
52
|
+
return n < 1e-10 && n > 0;
|
|
45
53
|
}
|
|
46
|
-
function
|
|
47
|
-
if (!
|
|
48
|
-
const
|
|
49
|
-
return
|
|
54
|
+
function M(t, n) {
|
|
55
|
+
if (!D(t)) return null;
|
|
56
|
+
const e = `<${1e-4}`;
|
|
57
|
+
return n ? `${e}${n}` : e;
|
|
50
58
|
}
|
|
51
|
-
const
|
|
59
|
+
const N = {
|
|
52
60
|
EPSILON: 1e-10,
|
|
53
61
|
MIN_DISPLAY_THRESHOLD: 1e-4,
|
|
54
62
|
MAX_EXPONENTIAL_THRESHOLD: 1e11
|
|
55
63
|
};
|
|
56
|
-
function
|
|
64
|
+
function x(t, n = 2, e = 6) {
|
|
57
65
|
if (!Number.isFinite(t)) return "∞";
|
|
58
|
-
const
|
|
59
|
-
return t <
|
|
60
|
-
minimumFractionDigits:
|
|
61
|
-
maximumFractionDigits:
|
|
62
|
-
}).format(t) : t.toFixed(
|
|
66
|
+
const i = 1 / 10 ** n;
|
|
67
|
+
return t < i && t !== 0 ? t.toFixed(e).replace(/\.?0+$/, "") : t > 1 ? new Intl.NumberFormat("en-US", {
|
|
68
|
+
minimumFractionDigits: n,
|
|
69
|
+
maximumFractionDigits: n
|
|
70
|
+
}).format(t) : t.toFixed(n);
|
|
63
71
|
}
|
|
64
72
|
export {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
73
|
+
N as FORMAT_CONSTANTS,
|
|
74
|
+
d as formatNumberWithSuffix,
|
|
75
|
+
x as formatPrice,
|
|
76
|
+
M as formatSmallValue,
|
|
69
77
|
u as getAdaptiveDecimals,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
D as isBelowDisplayThreshold,
|
|
79
|
+
E as isEffectivelyZero,
|
|
80
|
+
S as toSignificantDigits
|
|
73
81
|
};
|
|
@@ -18,15 +18,17 @@ export declare function formatMoney(money: number | bigint, precision?: number):
|
|
|
18
18
|
*
|
|
19
19
|
* @param value - The percentage value (already in percent form, e.g., 2.81 for 2.81%)
|
|
20
20
|
* @param decimals - Number of decimal places (default: 2)
|
|
21
|
+
* @param allowExponential - Whether to allow exponential notation for large values (default: true)
|
|
21
22
|
* @returns Formatted number (without % sign)
|
|
22
23
|
*
|
|
23
24
|
* @example
|
|
24
25
|
* ```ts
|
|
25
26
|
* formatPercentAmount(2.81, 2) // "2.81"
|
|
26
27
|
* formatPercentAmount(15000, 2) // "1.50e+4"
|
|
28
|
+
* formatPercentAmount(15000, 2, false) // "15000.00"
|
|
27
29
|
* ```
|
|
28
30
|
*/
|
|
29
|
-
export declare function formatPercentAmount(value: number, decimals: number): string | number;
|
|
31
|
+
export declare function formatPercentAmount(value: number, decimals: number, allowExponential?: boolean): string | number;
|
|
30
32
|
/**
|
|
31
33
|
* Formats a percentage value that is already in percent form
|
|
32
34
|
* Use this when your value is already 2.81 (meaning 2.81%), not 0.0281
|
|
@@ -22,11 +22,15 @@ export interface FormatNumberOptions {
|
|
|
22
22
|
export declare function formatNumberWithSuffix(amount: number, options?: FormatNumberOptions): string;
|
|
23
23
|
/**
|
|
24
24
|
* Convert a number to significant digits string
|
|
25
|
+
* For small values (< 1), uses true significant digits
|
|
26
|
+
* For larger values, uses fixed decimal places
|
|
25
27
|
*
|
|
26
28
|
* @example
|
|
27
29
|
* ```ts
|
|
28
30
|
* toSignificantDigits(1234567, 4) // "1234567"
|
|
29
31
|
* toSignificantDigits(1.234, 2) // "1.23"
|
|
32
|
+
* toSignificantDigits(0.0009400, 4) // "0.00094"
|
|
33
|
+
* toSignificantDigits(0.00001234, 4) // "0.00001234"
|
|
30
34
|
* ```
|
|
31
35
|
*/
|
|
32
36
|
export declare function toSignificantDigits(value: number, decimals: number): string;
|