heartraite 1.0.143 → 1.0.145

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.
@@ -61,4 +61,5 @@ export type EventMatchStats = {
61
61
  export type FullEvent = Omit<Event, "participants"> & {
62
62
  participants: FullParticipant[];
63
63
  matchStats?: EventMatchStats;
64
+ summaries: CompatibilitySummary[];
64
65
  };
@@ -1,3 +1,9 @@
1
1
  type SupportedLocale = "sv-SE" | "en-US" | "sv_SE" | "en_US";
2
2
  export declare const formatDate: (isoDate?: string | null, locale?: SupportedLocale) => string;
3
+ /**
4
+ * Formats a date + time in a concise, nice-looking format.
5
+ * sv-SE → "25 apr 2025 09:30"
6
+ * en-US → "Apr 25, 2025, 09:30 AM"
7
+ */
8
+ export declare const formatPrettyDateTime: (isoDate?: string | Date | null, locale?: SupportedLocale) => string;
3
9
  export {};
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatDate = void 0;
3
+ exports.formatPrettyDateTime = exports.formatDate = void 0;
4
4
  const normalizeLocale = (locale) => {
5
5
  return locale.replace("_", "-"); // Convert sv_SE → sv-SE
6
6
  };
7
- const formatDate = (isoDate, locale = "en-US") => {
7
+ const formatDate = (isoDate, locale = "sv-SE") => {
8
8
  if (!isoDate)
9
9
  return "";
10
10
  try {
@@ -21,3 +21,30 @@ const formatDate = (isoDate, locale = "en-US") => {
21
21
  }
22
22
  };
23
23
  exports.formatDate = formatDate;
24
+ /**
25
+ * Formats a date + time in a concise, nice-looking format.
26
+ * sv-SE → "25 apr 2025 09:30"
27
+ * en-US → "Apr 25, 2025, 09:30 AM"
28
+ */
29
+ const formatPrettyDateTime = (isoDate, locale = "sv-SE") => {
30
+ if (!isoDate)
31
+ return "";
32
+ try {
33
+ const normalizedLocale = normalizeLocale(locale);
34
+ const date = typeof isoDate === "string" ? new Date(isoDate) : isoDate;
35
+ const use12Hour = normalizedLocale.startsWith("en");
36
+ return new Intl.DateTimeFormat(normalizedLocale, {
37
+ year: "numeric",
38
+ month: "short",
39
+ day: "2-digit",
40
+ hour: "2-digit",
41
+ minute: "2-digit",
42
+ hour12: use12Hour,
43
+ }).format(date);
44
+ }
45
+ catch (e) {
46
+ console.warn("Invalid locale or date:", e);
47
+ return String(isoDate);
48
+ }
49
+ };
50
+ exports.formatPrettyDateTime = formatPrettyDateTime;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "heartraite",
3
- "version": "1.0.143",
3
+ "version": "1.0.145",
4
4
  "description": "Heartraite npm package for common functionality",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -69,4 +69,5 @@ export type EventMatchStats = {
69
69
  export type FullEvent = Omit<Event, "participants"> & {
70
70
  participants: FullParticipant[];
71
71
  matchStats?: EventMatchStats;
72
+ summaries: CompatibilitySummary[];
72
73
  };
@@ -6,7 +6,7 @@ const normalizeLocale = (locale: SupportedLocale): string => {
6
6
 
7
7
  export const formatDate = (
8
8
  isoDate?: string | null,
9
- locale: SupportedLocale = "en-US"
9
+ locale: SupportedLocale = "sv-SE"
10
10
  ) => {
11
11
  if (!isoDate) return "";
12
12
 
@@ -22,3 +22,33 @@ export const formatDate = (
22
22
  return isoDate;
23
23
  }
24
24
  };
25
+
26
+ /**
27
+ * Formats a date + time in a concise, nice-looking format.
28
+ * sv-SE → "25 apr 2025 09:30"
29
+ * en-US → "Apr 25, 2025, 09:30 AM"
30
+ */
31
+ export const formatPrettyDateTime = (
32
+ isoDate?: string | Date | null,
33
+ locale: SupportedLocale = "sv-SE"
34
+ ) => {
35
+ if (!isoDate) return "";
36
+
37
+ try {
38
+ const normalizedLocale = normalizeLocale(locale);
39
+ const date = typeof isoDate === "string" ? new Date(isoDate) : isoDate;
40
+ const use12Hour = normalizedLocale.startsWith("en");
41
+
42
+ return new Intl.DateTimeFormat(normalizedLocale, {
43
+ year: "numeric",
44
+ month: "short",
45
+ day: "2-digit",
46
+ hour: "2-digit",
47
+ minute: "2-digit",
48
+ hour12: use12Hour,
49
+ }).format(date);
50
+ } catch (e) {
51
+ console.warn("Invalid locale or date:", e);
52
+ return String(isoDate);
53
+ }
54
+ };