@mt-gloss/utils 0.1.148 → 0.1.149
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/index.d.ts +2 -0
- package/index.js +65 -54
- package/lib/formatCurrency.d.ts +35 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export { isStatusModeEnabled, v1_1_status_mode, V1_1_STATUS_MODE_ENV, isEdgeHove
|
|
|
2
2
|
export type { PresetDefinition, MarketPreset, DateRange, MarketEvent } from './lib/types';
|
|
3
3
|
export { formatValue, getValueFontSize, pickMetricTier } from './lib/formatValue';
|
|
4
4
|
export type { FormatValueOptions, FormattedValue, MetricTier, PickMetricTierResult } from './lib/formatValue';
|
|
5
|
+
export { formatCurrency } from './lib/formatCurrency';
|
|
6
|
+
export type { FormatCurrencyOptions } from './lib/formatCurrency';
|
|
5
7
|
export { formatTrend } from './lib/formatTrend';
|
|
6
8
|
export type { TrendDirection, FormattedTrend } from './lib/formatTrend';
|
|
7
9
|
export { formatDateRange, formatMarketDates, isMarketActive, isSameDay, isInRange, generateMarketId } from './lib/dateHelpers';
|
package/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { D as
|
|
1
|
+
import { D as N, y as v, P as A, n as O, o as V, R as x, T as G, d as Y, t as w, f as z, b as k, k as C, l as H, c as B, h as Z, x as K, g as X, q as j, j as q, m as W, u as J, i as Q, v as tt, p as et, a as nt, r as rt, s as at, e as st, w as ot } from "./formatting-dHqp6ksD.js";
|
|
2
2
|
const g = "NEXT_PUBLIC_V1_1_STATUS_MODE";
|
|
3
|
-
function
|
|
3
|
+
function d() {
|
|
4
4
|
return typeof globalThis < "u" && globalThis.__GLOSS_FLAGS__?.v1_1_status_mode === !0 ? !0 : typeof process < "u" && process.env ? process.env[g] === "true" : !1;
|
|
5
5
|
}
|
|
6
6
|
const $ = {
|
|
7
7
|
env: g,
|
|
8
|
-
check:
|
|
8
|
+
check: d
|
|
9
9
|
}, m = "NEXT_PUBLIC_V1_1_EDGE_HOVER_RESIZE";
|
|
10
10
|
function D() {
|
|
11
11
|
return typeof globalThis < "u" && globalThis.__GLOSS_FLAGS__?.v1_1_edge_hover_resize === !0 ? !0 : typeof process < "u" && process.env ? process.env[m] === "true" : !1;
|
|
@@ -14,22 +14,22 @@ const S = {
|
|
|
14
14
|
env: m,
|
|
15
15
|
check: D
|
|
16
16
|
};
|
|
17
|
-
function
|
|
17
|
+
function _(t, { prefix: e = "", suffix: n = "", abbreviated: s = !0, kThreshold: r = 1e3 } = {}) {
|
|
18
18
|
if (t == null) {
|
|
19
19
|
const l = e ? `${e} —${n}` : `—${n}`;
|
|
20
20
|
return { display: l.trim(), full: l.trim(), length: l.trim().length };
|
|
21
21
|
}
|
|
22
|
-
const
|
|
23
|
-
if (isNaN(
|
|
22
|
+
const a = typeof t == "number" ? t : parseFloat(String(t).replace(/,/g, ""));
|
|
23
|
+
if (isNaN(a)) {
|
|
24
24
|
const u = `${e}${t}${n}`;
|
|
25
25
|
return { display: u, full: u, length: u.length };
|
|
26
26
|
}
|
|
27
27
|
let o;
|
|
28
|
-
|
|
29
|
-
const i = `${e}${o}${n}`, c = `${e}${
|
|
28
|
+
s !== !1 && Math.abs(a) >= 1e6 ? o = (a / 1e6).toFixed(1).replace(/\.0$/, "") + "M" : s !== !1 && Math.abs(a) >= r ? o = (a / 1e3).toFixed(1).replace(/\.0$/, "") + "K" : o = a.toLocaleString("en-US");
|
|
29
|
+
const i = `${e}${o}${n}`, c = `${e}${a.toLocaleString("en-US")}${n}`;
|
|
30
30
|
return { display: i, full: c, length: i.length };
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function p(t, e) {
|
|
33
33
|
return (e ?? 1) >= 2 ? t <= 4 || t <= 6 ? 30 : t <= 8 ? 24 : 20 : t <= 5 ? 28 : t <= 8 ? 20 : 17;
|
|
34
34
|
}
|
|
35
35
|
const f = {
|
|
@@ -43,16 +43,26 @@ const f = {
|
|
|
43
43
|
function h(t) {
|
|
44
44
|
return t <= 1 ? f[1] : t >= 3 ? f[3] : f[t] ?? f[1];
|
|
45
45
|
}
|
|
46
|
-
function
|
|
47
|
-
const
|
|
46
|
+
function E(t, e = {}, n = 1) {
|
|
47
|
+
const s = h(n), r = e.prefix ?? "", a = e.suffix ?? "", o = typeof t == "number" ? t : parseFloat(String(t ?? "").replace(/,/g, ""));
|
|
48
48
|
if (t != null && !Number.isNaN(o)) {
|
|
49
|
-
const c = `${
|
|
50
|
-
if (c.length <=
|
|
51
|
-
const u = `${
|
|
52
|
-
if (u.length <=
|
|
49
|
+
const c = `${r}${o.toLocaleString("en-US", { minimumFractionDigits: Number.isInteger(o) ? 0 : 2, maximumFractionDigits: 2 })}${a}`;
|
|
50
|
+
if (c.length <= s) return { formatted: c, tier: "wide", length: c.length };
|
|
51
|
+
const u = `${r}${Math.round(o).toLocaleString("en-US")}${a}`;
|
|
52
|
+
if (u.length <= s) return { formatted: u, tier: "medium", length: u.length };
|
|
53
53
|
}
|
|
54
|
-
const i =
|
|
55
|
-
return i.display.length <=
|
|
54
|
+
const i = _(t, { ...e, abbreviated: !0 });
|
|
55
|
+
return i.display.length <= s ? { formatted: i.display, tier: "narrow", length: i.display.length } : { formatted: i.display, tier: "very-narrow", length: i.display.length };
|
|
56
|
+
}
|
|
57
|
+
function y(t, { notation: e = "standard", fractionDigits: n, currency: s = "USD" } = {}) {
|
|
58
|
+
const r = { style: "currency", currency: s };
|
|
59
|
+
if (e === "compact")
|
|
60
|
+
r.notation = "compact", r.compactDisplay = "short", n !== void 0 && (r.minimumFractionDigits = n, r.maximumFractionDigits = n);
|
|
61
|
+
else {
|
|
62
|
+
const a = n ?? 2;
|
|
63
|
+
r.minimumFractionDigits = a, r.maximumFractionDigits = a;
|
|
64
|
+
}
|
|
65
|
+
return new Intl.NumberFormat("en-US", r).format(t);
|
|
56
66
|
}
|
|
57
67
|
function T(t) {
|
|
58
68
|
if (t == null || t === 0)
|
|
@@ -60,14 +70,14 @@ function T(t) {
|
|
|
60
70
|
const e = t > 0 ? "up" : t < 0 ? "down" : "flat", n = Math.abs(t);
|
|
61
71
|
return { text: n >= 3 ? `${Math.round(n)}%` : `${n.toFixed(1)}%`, direction: e };
|
|
62
72
|
}
|
|
63
|
-
function
|
|
73
|
+
function F(t, e) {
|
|
64
74
|
if (!t || !e) return "";
|
|
65
|
-
const n = t.toLocaleDateString("en-US", { month: "short" }),
|
|
66
|
-
return t.getTime() === e.getTime() || n ===
|
|
75
|
+
const n = t.toLocaleDateString("en-US", { month: "short" }), s = e.toLocaleDateString("en-US", { month: "short" }), r = t.getDate(), a = e.getDate(), o = t.getFullYear(), i = e.getFullYear();
|
|
76
|
+
return t.getTime() === e.getTime() || n === s && r === a && o === i ? `${n} ${r}, ${o}` : n === s && o === i ? `${n} ${r}–${a}` : o === i ? `${n} ${r} – ${s} ${a}` : `${n} ${r}, ${o} – ${s} ${a}, ${i}`;
|
|
67
77
|
}
|
|
68
78
|
function M(t, e) {
|
|
69
|
-
const n = t.toLocaleDateString("en-US", { month: "short" }),
|
|
70
|
-
return n ===
|
|
79
|
+
const n = t.toLocaleDateString("en-US", { month: "short" }), s = e.toLocaleDateString("en-US", { month: "short" }), r = t.getDate(), a = e.getDate();
|
|
80
|
+
return n === s ? `${n} ${r}–${a}` : `${n} ${r} – ${s} ${a}`;
|
|
71
81
|
}
|
|
72
82
|
function R(t, e = /* @__PURE__ */ new Date()) {
|
|
73
83
|
return !t?.startDate || !t?.endDate ? !1 : e >= t.startDate && e <= t.endDate;
|
|
@@ -75,58 +85,59 @@ function R(t, e = /* @__PURE__ */ new Date()) {
|
|
|
75
85
|
function P(t, e) {
|
|
76
86
|
return !t || !e ? !1 : t.getFullYear() === e.getFullYear() && t.getMonth() === e.getMonth() && t.getDate() === e.getDate();
|
|
77
87
|
}
|
|
78
|
-
function
|
|
88
|
+
function b(t, e, n) {
|
|
79
89
|
if (!t || !e || !n) return !1;
|
|
80
|
-
const
|
|
81
|
-
return
|
|
90
|
+
const s = t.getTime(), r = e.getTime(), a = n.getTime();
|
|
91
|
+
return s >= Math.min(r, a) && s <= Math.max(r, a);
|
|
82
92
|
}
|
|
83
93
|
function L() {
|
|
84
94
|
return `custom-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
|
|
85
95
|
}
|
|
86
96
|
export {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
97
|
+
N as DEFAULT_MARKET_PRESETS,
|
|
98
|
+
v as DEFAULT_PINNED,
|
|
99
|
+
A as PERIOD_OPTIONS,
|
|
100
|
+
O as PRESET_ID_MAP,
|
|
101
|
+
V as PRESET_ID_REVERSE_MAP,
|
|
102
|
+
x as ROLLING_OPTIONS,
|
|
93
103
|
G as TODAY_PRESET,
|
|
94
104
|
m as V1_1_EDGE_HOVER_RESIZE_ENV,
|
|
95
105
|
g as V1_1_STATUS_MODE_ENV,
|
|
96
106
|
Y as detectPreset,
|
|
97
|
-
|
|
98
|
-
y as
|
|
107
|
+
w as findPreset,
|
|
108
|
+
y as formatCurrency,
|
|
109
|
+
F as formatDateRange,
|
|
99
110
|
z as formatDateRangeSmart,
|
|
100
111
|
k as formatDateRangeWithPreset,
|
|
101
|
-
|
|
112
|
+
C as formatDuration,
|
|
102
113
|
M as formatMarketDates,
|
|
103
114
|
H as formatPreset,
|
|
104
115
|
B as formatShortYear,
|
|
105
|
-
|
|
116
|
+
Z as formatSingleDate,
|
|
106
117
|
T as formatTrend,
|
|
107
|
-
|
|
118
|
+
_ as formatValue,
|
|
108
119
|
L as generateMarketId,
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
120
|
+
K as getAllPresets,
|
|
121
|
+
X as getDateRangeDisplayInfo,
|
|
122
|
+
j as getDateRangeForPreset,
|
|
123
|
+
q as getDurationDays,
|
|
124
|
+
W as getPresetDateRange,
|
|
125
|
+
J as getPresetLabel,
|
|
126
|
+
p as getValueFontSize,
|
|
116
127
|
D as isEdgeHoverResizeEnabled,
|
|
117
|
-
|
|
128
|
+
b as isInRange,
|
|
118
129
|
R as isMarketActive,
|
|
119
130
|
P as isSameDay,
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
131
|
+
d as isStatusModeEnabled,
|
|
132
|
+
Q as isValidDateRangeFormat,
|
|
133
|
+
tt as normalizePresetId,
|
|
134
|
+
et as parseDateRange,
|
|
135
|
+
E as pickMetricTier,
|
|
136
|
+
nt as resolveEvent,
|
|
137
|
+
rt as resolvePreset,
|
|
138
|
+
at as smartDateFormat,
|
|
139
|
+
st as stripLeadingZeros,
|
|
140
|
+
ot as toUppercasePresetId,
|
|
130
141
|
S as v1_1_edge_hover_resize,
|
|
131
142
|
$ as v1_1_status_mode
|
|
132
143
|
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface FormatCurrencyOptions {
|
|
2
|
+
/** `'standard'` (default) → grouped full amount; `'compact'` → `$22K` / `$1.2M`. */
|
|
3
|
+
notation?: 'standard' | 'compact';
|
|
4
|
+
/**
|
|
5
|
+
* Sets BOTH the minimum and maximum fraction digits.
|
|
6
|
+
* - standard: defaults to `2` (`$1,234.56`); pass `0` for whole dollars (`$18,000`).
|
|
7
|
+
* - compact: when omitted, uses Intl's compact default (`$1.2M`, never `$1.20M`).
|
|
8
|
+
*/
|
|
9
|
+
fractionDigits?: number;
|
|
10
|
+
/** ISO 4217 currency code. Default `'USD'`. */
|
|
11
|
+
currency?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Format a number as a localized currency string (pure, `en-US`).
|
|
15
|
+
*
|
|
16
|
+
* Subsumes the dashboard's three string currency formatters: the default
|
|
17
|
+
* 2-decimal grouped form, the compact `$K`/`$M` form, and the whole-dollar
|
|
18
|
+
* pace form — each selected via options, behavior-preserving.
|
|
19
|
+
*
|
|
20
|
+
* Rules:
|
|
21
|
+
* - `notation: 'standard'` (default): `minimumFractionDigits === maximumFractionDigits === fractionDigits` (default `2`).
|
|
22
|
+
* - `notation: 'compact'`: `compactDisplay: 'short'`; fraction digits left to Intl unless `fractionDigits` is passed.
|
|
23
|
+
* - Locale is fixed to `en-US`; `currency` defaults to `USD`.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { formatCurrency } from '@mt-gloss/utils';
|
|
28
|
+
*
|
|
29
|
+
* formatCurrency(1234.5); // '$1,234.50'
|
|
30
|
+
* formatCurrency(1200000, { notation: 'compact' }); // '$1.2M'
|
|
31
|
+
* formatCurrency(18000, { fractionDigits: 0 }); // '$18,000'
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function formatCurrency(value: number, { notation, fractionDigits, currency }?: FormatCurrencyOptions): string;
|
|
35
|
+
//# sourceMappingURL=formatCurrency.d.ts.map
|