@mt-gloss/utils 0.1.147 → 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 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 U, y as N, P as v, n as A, o as O, R as V, T as G, d as Y, t as x, f as z, b as k, k as w, l as H, c as B, h as C, x as Z, g as K, q as X, j, m as q, u as W, i as J, v as Q, p as tt, a as et, r as nt, s as rt, e as at, w as st } from "./formatting-dHqp6ksD.js";
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 d(t, { prefix: e = "", suffix: n = "", abbreviated: a = !0, kThreshold: s = 1e3 } = {}) {
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 r = typeof t == "number" ? t : parseFloat(String(t).replace(/,/g, ""));
23
- if (isNaN(r)) {
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
- a !== !1 && Math.abs(r) >= 1e6 ? o = (r / 1e6).toFixed(1).replace(/\.0$/, "") + "M" : a !== !1 && Math.abs(r) >= s ? o = (r / 1e3).toFixed(1).replace(/\.0$/, "") + "K" : o = r.toLocaleString("en-US");
29
- const i = `${e}${o}${n}`, c = `${e}${r.toLocaleString("en-US")}${n}`;
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 E(t, e) {
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 p(t, e = {}, n = 1) {
47
- const a = h(n), s = e.prefix ?? "", r = e.suffix ?? "", o = typeof t == "number" ? t : parseFloat(String(t ?? "").replace(/,/g, ""));
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 = `${s}${o.toLocaleString("en-US", { minimumFractionDigits: Number.isInteger(o) ? 0 : 2, maximumFractionDigits: 2 })}${r}`;
50
- if (c.length <= a) return { formatted: c, tier: "wide", length: c.length };
51
- const u = `${s}${Math.round(o).toLocaleString("en-US")}${r}`;
52
- if (u.length <= a) return { formatted: u, tier: "medium", length: 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 = d(t, { ...e, abbreviated: !0 });
55
- return i.display.length <= a ? { formatted: i.display, tier: "narrow", length: i.display.length } : { formatted: i.display, tier: "very-narrow", length: 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 y(t, e) {
73
+ function F(t, e) {
64
74
  if (!t || !e) return "";
65
- const n = t.toLocaleDateString("en-US", { month: "short" }), a = e.toLocaleDateString("en-US", { month: "short" }), s = t.getDate(), r = e.getDate(), o = t.getFullYear(), i = e.getFullYear();
66
- return t.getTime() === e.getTime() || n === a && s === r && o === i ? `${n} ${s}, ${o}` : n === a && o === i ? `${n} ${s}–${r}` : o === i ? `${n} ${s} – ${a} ${r}` : `${n} ${s}, ${o} – ${a} ${r}, ${i}`;
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" }), a = e.toLocaleDateString("en-US", { month: "short" }), s = t.getDate(), r = e.getDate();
70
- return n === a ? `${n} ${s}–${r}` : `${n} ${s} – ${a} ${r}`;
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 F(t, e, n) {
88
+ function b(t, e, n) {
79
89
  if (!t || !e || !n) return !1;
80
- const a = t.getTime(), s = e.getTime(), r = n.getTime();
81
- return a >= Math.min(s, r) && a <= Math.max(s, r);
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
- U as DEFAULT_MARKET_PRESETS,
88
- N as DEFAULT_PINNED,
89
- v as PERIOD_OPTIONS,
90
- A as PRESET_ID_MAP,
91
- O as PRESET_ID_REVERSE_MAP,
92
- V as ROLLING_OPTIONS,
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
- x as findPreset,
98
- y as formatDateRange,
107
+ w as findPreset,
108
+ y as formatCurrency,
109
+ F as formatDateRange,
99
110
  z as formatDateRangeSmart,
100
111
  k as formatDateRangeWithPreset,
101
- w as formatDuration,
112
+ C as formatDuration,
102
113
  M as formatMarketDates,
103
114
  H as formatPreset,
104
115
  B as formatShortYear,
105
- C as formatSingleDate,
116
+ Z as formatSingleDate,
106
117
  T as formatTrend,
107
- d as formatValue,
118
+ _ as formatValue,
108
119
  L as generateMarketId,
109
- Z as getAllPresets,
110
- K as getDateRangeDisplayInfo,
111
- X as getDateRangeForPreset,
112
- j as getDurationDays,
113
- q as getPresetDateRange,
114
- W as getPresetLabel,
115
- E as getValueFontSize,
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
- F as isInRange,
128
+ b as isInRange,
118
129
  R as isMarketActive,
119
130
  P as isSameDay,
120
- _ as isStatusModeEnabled,
121
- J as isValidDateRangeFormat,
122
- Q as normalizePresetId,
123
- tt as parseDateRange,
124
- p as pickMetricTier,
125
- et as resolveEvent,
126
- nt as resolvePreset,
127
- rt as smartDateFormat,
128
- at as stripLeadingZeros,
129
- st as toUppercasePresetId,
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mt-gloss/utils",
3
- "version": "0.1.147",
3
+ "version": "0.1.149",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"