@cranberry-money/shared-utils 4.1.0 → 4.2.0

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/date.d.ts ADDED
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Date and time formatting utility functions
3
+ *
4
+ * This module provides pure functions for formatting dates and times
5
+ * in various formats suitable for display in the application.
6
+ */
7
+ /**
8
+ * Formats a date string to a localized date
9
+ *
10
+ * @param dateString - ISO date string or null
11
+ * @param fallback - Fallback text when date is null (default: 'No expiry')
12
+ * @returns Formatted date string
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * formatDate('2024-03-15') // '3/15/2024' (in en-US)
17
+ * formatDate(null) // 'No expiry'
18
+ * formatDate(null, 'Not set') // 'Not set'
19
+ * ```
20
+ */
21
+ export declare function formatDate(dateString: string | null, fallback?: string): string;
22
+ /**
23
+ * Formats a date string to a short date format (e.g., "Jan 15")
24
+ *
25
+ * @param dateString - ISO date string
26
+ * @param locale - Locale for formatting (default: 'en-AU')
27
+ * @returns Formatted short date string
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * formatShortDate('2024-01-15') // 'Jan 15'
32
+ * formatShortDate('2024-12-25', 'en-US') // 'Dec 25'
33
+ * ```
34
+ */
35
+ export declare function formatShortDate(dateString: string, locale?: string): string;
36
+ /**
37
+ * Formats a date string to a time format (24-hour)
38
+ *
39
+ * @param dateString - ISO date string
40
+ * @param locale - Locale for formatting (default: 'en-AU')
41
+ * @returns Formatted time string in 24-hour format
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * formatTime('2024-01-15T14:30:00') // '14:30'
46
+ * formatTime('2024-01-15T09:05:00') // '09:05'
47
+ * ```
48
+ */
49
+ export declare function formatTime(dateString: string, locale?: string): string;
50
+ /**
51
+ * Formats a date string to a combined short date and time format
52
+ *
53
+ * @param dateString - ISO date string
54
+ * @param locale - Locale for formatting (default: 'en-AU')
55
+ * @returns Formatted string like "Jan 15 14:30"
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * formatDateTime('2024-01-15T14:30:00') // 'Jan 15 14:30'
60
+ * formatDateTime('2024-12-25T09:00:00', 'en-US') // 'Dec 25 09:00'
61
+ * ```
62
+ */
63
+ export declare function formatDateTime(dateString: string, locale?: string): string;
64
+ //# sourceMappingURL=date.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../src/date.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,GAAE,MAAoB,GAAG,MAAM,CAG5F;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,GAAE,MAAgB,GAAG,MAAM,CAMpF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,GAAE,MAAgB,GAAG,MAAM,CAM/E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,GAAE,MAAgB,GAAG,MAAM,CAYnF"}
package/dist/date.js ADDED
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Date and time formatting utility functions
3
+ *
4
+ * This module provides pure functions for formatting dates and times
5
+ * in various formats suitable for display in the application.
6
+ */
7
+ /**
8
+ * Formats a date string to a localized date
9
+ *
10
+ * @param dateString - ISO date string or null
11
+ * @param fallback - Fallback text when date is null (default: 'No expiry')
12
+ * @returns Formatted date string
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * formatDate('2024-03-15') // '3/15/2024' (in en-US)
17
+ * formatDate(null) // 'No expiry'
18
+ * formatDate(null, 'Not set') // 'Not set'
19
+ * ```
20
+ */
21
+ export function formatDate(dateString, fallback = 'No expiry') {
22
+ if (!dateString)
23
+ return fallback;
24
+ return new Date(dateString).toLocaleDateString();
25
+ }
26
+ /**
27
+ * Formats a date string to a short date format (e.g., "Jan 15")
28
+ *
29
+ * @param dateString - ISO date string
30
+ * @param locale - Locale for formatting (default: 'en-AU')
31
+ * @returns Formatted short date string
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * formatShortDate('2024-01-15') // 'Jan 15'
36
+ * formatShortDate('2024-12-25', 'en-US') // 'Dec 25'
37
+ * ```
38
+ */
39
+ export function formatShortDate(dateString, locale = 'en-AU') {
40
+ const date = new Date(dateString);
41
+ return date.toLocaleDateString(locale, {
42
+ month: 'short',
43
+ day: 'numeric',
44
+ });
45
+ }
46
+ /**
47
+ * Formats a date string to a time format (24-hour)
48
+ *
49
+ * @param dateString - ISO date string
50
+ * @param locale - Locale for formatting (default: 'en-AU')
51
+ * @returns Formatted time string in 24-hour format
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * formatTime('2024-01-15T14:30:00') // '14:30'
56
+ * formatTime('2024-01-15T09:05:00') // '09:05'
57
+ * ```
58
+ */
59
+ export function formatTime(dateString, locale = 'en-AU') {
60
+ return new Date(dateString).toLocaleTimeString(locale, {
61
+ hour: '2-digit',
62
+ minute: '2-digit',
63
+ hour12: false,
64
+ });
65
+ }
66
+ /**
67
+ * Formats a date string to a combined short date and time format
68
+ *
69
+ * @param dateString - ISO date string
70
+ * @param locale - Locale for formatting (default: 'en-AU')
71
+ * @returns Formatted string like "Jan 15 14:30"
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * formatDateTime('2024-01-15T14:30:00') // 'Jan 15 14:30'
76
+ * formatDateTime('2024-12-25T09:00:00', 'en-US') // 'Dec 25 09:00'
77
+ * ```
78
+ */
79
+ export function formatDateTime(dateString, locale = 'en-AU') {
80
+ const date = new Date(dateString);
81
+ const shortDate = date.toLocaleDateString(locale, {
82
+ month: 'short',
83
+ day: 'numeric',
84
+ });
85
+ const time = date.toLocaleTimeString(locale, {
86
+ hour: '2-digit',
87
+ minute: '2-digit',
88
+ hour12: false,
89
+ });
90
+ return `${shortDate} ${time}`;
91
+ }
package/dist/index.d.ts CHANGED
@@ -5,4 +5,5 @@
5
5
  * All utilities are pure functions with no side effects.
6
6
  */
7
7
  export { truncateText } from './text';
8
+ export { formatDate, formatShortDate, formatTime, formatDateTime } from './date';
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC"}
package/dist/index.js CHANGED
@@ -6,3 +6,5 @@
6
6
  */
7
7
  // Text manipulation utilities
8
8
  export { truncateText } from './text';
9
+ // Date and time formatting utilities
10
+ export { formatDate, formatShortDate, formatTime, formatDateTime } from './date';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cranberry-money/shared-utils",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "description": "Shared utility functions for MyPortfolio platform",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",