@cranberry-money/shared-utils 5.0.0 → 5.0.1

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.
Files changed (49) hide show
  1. package/package.json +1 -1
  2. package/dist/auth.d.ts +0 -55
  3. package/dist/auth.d.ts.map +0 -1
  4. package/dist/auth.js +0 -135
  5. package/dist/badge-status.d.ts +0 -65
  6. package/dist/badge-status.d.ts.map +0 -1
  7. package/dist/badge-status.js +0 -170
  8. package/dist/badge.d.ts +0 -41
  9. package/dist/badge.d.ts.map +0 -1
  10. package/dist/badge.js +0 -72
  11. package/dist/collections.d.ts +0 -81
  12. package/dist/collections.d.ts.map +0 -1
  13. package/dist/collections.js +0 -127
  14. package/dist/currency.d.ts +0 -99
  15. package/dist/currency.d.ts.map +0 -1
  16. package/dist/currency.js +0 -128
  17. package/dist/date.d.ts +0 -64
  18. package/dist/date.d.ts.map +0 -1
  19. package/dist/date.js +0 -91
  20. package/dist/downloads.d.ts +0 -46
  21. package/dist/downloads.d.ts.map +0 -1
  22. package/dist/downloads.js +0 -91
  23. package/dist/filters.d.ts +0 -121
  24. package/dist/filters.d.ts.map +0 -1
  25. package/dist/filters.js +0 -206
  26. package/dist/formatting.d.ts +0 -59
  27. package/dist/formatting.d.ts.map +0 -1
  28. package/dist/formatting.js +0 -81
  29. package/dist/index.d.ts +0 -22
  30. package/dist/index.d.ts.map +0 -1
  31. package/dist/index.js +0 -40
  32. package/dist/instruments.d.ts +0 -66
  33. package/dist/instruments.d.ts.map +0 -1
  34. package/dist/instruments.js +0 -135
  35. package/dist/numbers.d.ts +0 -72
  36. package/dist/numbers.d.ts.map +0 -1
  37. package/dist/numbers.js +0 -101
  38. package/dist/portfolio.d.ts +0 -68
  39. package/dist/portfolio.d.ts.map +0 -1
  40. package/dist/portfolio.js +0 -87
  41. package/dist/text.d.ts +0 -22
  42. package/dist/text.d.ts.map +0 -1
  43. package/dist/text.js +0 -25
  44. package/dist/validation.d.ts +0 -226
  45. package/dist/validation.d.ts.map +0 -1
  46. package/dist/validation.js +0 -337
  47. package/dist/withdrawal.d.ts +0 -87
  48. package/dist/withdrawal.d.ts.map +0 -1
  49. package/dist/withdrawal.js +0 -119
@@ -1,127 +0,0 @@
1
- /**
2
- * Generic collection and array utilities
3
- * Pure functions for common array operations with type safety
4
- */
5
- /**
6
- * Sort array of objects by a string field
7
- * @param items - Array of objects to sort
8
- * @param fieldName - Name of the field to sort by
9
- * @returns New sorted array
10
- */
11
- export function sortByStringField(items, fieldName) {
12
- return [...items].sort((a, b) => {
13
- const aValue = String(a[fieldName]);
14
- const bValue = String(b[fieldName]);
15
- return aValue.localeCompare(bValue);
16
- });
17
- }
18
- /**
19
- * Filter array by text search in a specific field (case-insensitive)
20
- * @param items - Array of objects to filter
21
- * @param fieldName - Name of the field to search in
22
- * @param searchTerm - Search term
23
- * @returns Filtered array
24
- */
25
- export function filterByTextSearch(items, fieldName, searchTerm) {
26
- const lowercaseSearch = searchTerm.toLowerCase();
27
- return items.filter(item => {
28
- const fieldValue = String(item[fieldName]).toLowerCase();
29
- return fieldValue.includes(lowercaseSearch);
30
- });
31
- }
32
- /**
33
- * Filter array by boolean field
34
- * @param items - Array of objects to filter
35
- * @param fieldName - Name of the boolean field
36
- * @param value - Boolean value to filter by
37
- * @returns Filtered array
38
- */
39
- export function filterByBooleanField(items, fieldName, value) {
40
- return items.filter(item => Boolean(item[fieldName]) === value);
41
- }
42
- /**
43
- * Find item by exact field match
44
- * @param items - Array of objects to search
45
- * @param fieldName - Name of the field to match
46
- * @param value - Value to match
47
- * @returns Found item or undefined
48
- */
49
- export function findByField(items, fieldName, value) {
50
- return items.find(item => item[fieldName] === value);
51
- }
52
- /**
53
- * Find item by case-insensitive string field match
54
- * @param items - Array of objects to search
55
- * @param fieldName - Name of the string field to match
56
- * @param value - String value to match (case-insensitive)
57
- * @returns Found item or undefined
58
- */
59
- export function findByStringField(items, fieldName, value) {
60
- const lowercaseValue = value.toLowerCase();
61
- return items.find(item => {
62
- const fieldValue = String(item[fieldName]).toLowerCase();
63
- return fieldValue === lowercaseValue;
64
- });
65
- }
66
- /**
67
- * Extract values from a specific field and sort them
68
- * @param items - Array of objects
69
- * @param fieldName - Name of the field to extract
70
- * @returns Sorted array of extracted values
71
- */
72
- export function extractAndSortField(items, fieldName) {
73
- return items.map(item => item[fieldName]).sort();
74
- }
75
- /**
76
- * Group array items by the first character of a string field
77
- * @param items - Array of objects to group
78
- * @param fieldName - Name of the string field to group by
79
- * @returns Object with first letters as keys and arrays of items as values
80
- */
81
- export function groupByFirstLetter(items, fieldName) {
82
- return items.reduce((groups, item) => {
83
- const fieldValue = String(item[fieldName]);
84
- const firstLetter = fieldValue.charAt(0).toUpperCase();
85
- if (!groups[firstLetter]) {
86
- groups[firstLetter] = [];
87
- }
88
- groups[firstLetter].push(item);
89
- return groups;
90
- }, {});
91
- }
92
- /**
93
- * Group array items by a field value
94
- * @param items - Array of objects to group
95
- * @param fieldName - Name of the field to group by
96
- * @returns Object with field values as keys and arrays of items as values
97
- */
98
- export function groupByField(items, fieldName) {
99
- return items.reduce((groups, item) => {
100
- const fieldValue = String(item[fieldName]);
101
- if (!groups[fieldValue]) {
102
- groups[fieldValue] = [];
103
- }
104
- groups[fieldValue].push(item);
105
- return groups;
106
- }, {});
107
- }
108
- /**
109
- * Check if any item in array has a specific boolean field value
110
- * @param items - Array of objects to check
111
- * @param fieldName - Name of the boolean field
112
- * @param value - Boolean value to check for
113
- * @returns true if any item matches, false otherwise
114
- */
115
- export function hasItemWithFieldValue(items, fieldName, value) {
116
- return items.some(item => item[fieldName] === value);
117
- }
118
- /**
119
- * Count items that match a field value
120
- * @param items - Array of objects to count
121
- * @param fieldName - Name of the field to check
122
- * @param value - Value to count
123
- * @returns Number of matching items
124
- */
125
- export function countByFieldValue(items, fieldName, value) {
126
- return items.filter(item => item[fieldName] === value).length;
127
- }
@@ -1,99 +0,0 @@
1
- /**
2
- * Currency formatting utility functions and constants
3
- *
4
- * This module provides pure functions for formatting currency values,
5
- * parsing currency inputs, and working with different currency formats.
6
- */
7
- /**
8
- * Number formatting options for currency display
9
- */
10
- export declare const NUMBER_FORMAT_OPTIONS_CURRENCY: {
11
- readonly style: "currency";
12
- readonly minimumFractionDigits: 2;
13
- readonly maximumFractionDigits: 2;
14
- };
15
- /**
16
- * Number formatting options for currency with explicit sign display
17
- */
18
- export declare const NUMBER_FORMAT_OPTIONS_CURRENCY_SIGNED: {
19
- readonly signDisplay: "always";
20
- readonly style: "currency";
21
- readonly minimumFractionDigits: 2;
22
- readonly maximumFractionDigits: 2;
23
- };
24
- /**
25
- * Formats a number as currency with commas and 2 decimal places
26
- *
27
- * @param value - Number or string value to format
28
- * @returns Formatted currency string without currency symbol
29
- *
30
- * @example
31
- * ```typescript
32
- * formatCurrency(1234.5) // '1,234.50'
33
- * formatCurrency('1234.5') // '1,234.50'
34
- * formatCurrency(0) // '0.00'
35
- * ```
36
- */
37
- export declare function formatCurrency(value: number | string): string;
38
- /**
39
- * Parses a currency string input into a number
40
- *
41
- * @param value - Currency string to parse
42
- * @returns Parsed number value (or 0 if invalid)
43
- *
44
- * @example
45
- * ```typescript
46
- * parseCurrencyInput('$1,234.56') // 1234.56
47
- * parseCurrencyInput('1234.567') // 1234.56
48
- * parseCurrencyInput('abc') // 0
49
- * ```
50
- */
51
- export declare function parseCurrencyInput(value: string): number;
52
- /**
53
- * Formats a number as currency with specific currency code and locale
54
- *
55
- * @param value - Number to format
56
- * @param currencyCode - ISO 4217 currency code (default: DEFAULT_CURRENCY)
57
- * @param locale - Locale for formatting (default: 'en-AU')
58
- * @param minimumFractionDigits - Minimum decimal places (default: 0)
59
- * @param maximumFractionDigits - Maximum decimal places (default: 0)
60
- * @returns Formatted currency string
61
- *
62
- * @example
63
- * ```typescript
64
- * formatCurrencyWithCode(1234.5) // 'A$1,235'
65
- * formatCurrencyWithCode(1234.5, 'USD', 'en-US') // '$1,235'
66
- * formatCurrencyWithCode(1234.56, 'AUD', 'en-AU', 2, 2) // 'A$1,234.56'
67
- * ```
68
- */
69
- export declare function formatCurrencyWithCode(value: number, currencyCode?: string, locale?: string, minimumFractionDigits?: number, maximumFractionDigits?: number): string;
70
- /**
71
- * Convenience function to format currency with the default currency (AUD)
72
- *
73
- * @param value - Number to format
74
- * @param minimumFractionDigits - Minimum decimal places (default: 0)
75
- * @param maximumFractionDigits - Maximum decimal places (default: 0)
76
- * @returns Formatted currency string with default currency
77
- *
78
- * @example
79
- * ```typescript
80
- * formatDefaultCurrency(1234.5) // 'A$1,235'
81
- * formatDefaultCurrency(1234.56, 2, 2) // 'A$1,234.56'
82
- * ```
83
- */
84
- export declare function formatDefaultCurrency(value: number, minimumFractionDigits?: number, maximumFractionDigits?: number): string;
85
- /**
86
- * Formats a number for displaying share quantities (no decimals)
87
- *
88
- * @param shares - Number of shares to format
89
- * @param locale - Locale for formatting (default: 'en-AU')
90
- * @returns Formatted shares string with commas as thousands separators
91
- *
92
- * @example
93
- * ```typescript
94
- * formatShares(1234) // '1,234'
95
- * formatShares(1234567) // '1,234,567'
96
- * ```
97
- */
98
- export declare function formatShares(shares: number, locale?: string): string;
99
- //# sourceMappingURL=currency.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../src/currency.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;GAEG;AACH,eAAO,MAAM,8BAA8B;;;;CAIjC,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,qCAAqC;;;;;CAGxC,CAAC;AAEX;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAW7D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOxD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,MAAM,EACb,YAAY,GAAE,MAAyB,EACvC,MAAM,GAAE,MAAgB,EACxB,qBAAqB,GAAE,MAAU,EACjC,qBAAqB,GAAE,MAAU,GAChC,MAAM,CASR;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,EACb,qBAAqB,GAAE,MAAU,EACjC,qBAAqB,GAAE,MAAU,GAChC,MAAM,CAER;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,MAAgB,GAAG,MAAM,CAK7E"}
package/dist/currency.js DELETED
@@ -1,128 +0,0 @@
1
- /**
2
- * Currency formatting utility functions and constants
3
- *
4
- * This module provides pure functions for formatting currency values,
5
- * parsing currency inputs, and working with different currency formats.
6
- */
7
- import { DEFAULT_CURRENCY, DECIMAL_PLACES } from '@cranberry-money/shared-constants';
8
- /**
9
- * Number formatting options for currency display
10
- */
11
- export const NUMBER_FORMAT_OPTIONS_CURRENCY = {
12
- style: 'currency',
13
- minimumFractionDigits: DECIMAL_PLACES,
14
- maximumFractionDigits: DECIMAL_PLACES,
15
- };
16
- /**
17
- * Number formatting options for currency with explicit sign display
18
- */
19
- export const NUMBER_FORMAT_OPTIONS_CURRENCY_SIGNED = {
20
- ...NUMBER_FORMAT_OPTIONS_CURRENCY,
21
- signDisplay: 'always',
22
- };
23
- /**
24
- * Formats a number as currency with commas and 2 decimal places
25
- *
26
- * @param value - Number or string value to format
27
- * @returns Formatted currency string without currency symbol
28
- *
29
- * @example
30
- * ```typescript
31
- * formatCurrency(1234.5) // '1,234.50'
32
- * formatCurrency('1234.5') // '1,234.50'
33
- * formatCurrency(0) // '0.00'
34
- * ```
35
- */
36
- export function formatCurrency(value) {
37
- if (!value && value !== 0)
38
- return '';
39
- const numValue = typeof value === 'string' ? parseFloat(value) : value;
40
- if (isNaN(numValue))
41
- return '';
42
- return numValue.toLocaleString('en-AU', {
43
- minimumFractionDigits: 2,
44
- maximumFractionDigits: 2,
45
- });
46
- }
47
- /**
48
- * Parses a currency string input into a number
49
- *
50
- * @param value - Currency string to parse
51
- * @returns Parsed number value (or 0 if invalid)
52
- *
53
- * @example
54
- * ```typescript
55
- * parseCurrencyInput('$1,234.56') // 1234.56
56
- * parseCurrencyInput('1234.567') // 1234.56
57
- * parseCurrencyInput('abc') // 0
58
- * ```
59
- */
60
- export function parseCurrencyInput(value) {
61
- const cleanValue = value.replace(/[^0-9.]/g, '');
62
- const parts = cleanValue.split('.');
63
- const formattedValue = parts[0] + (parts.length > 1 && parts[1] ? '.' + parts[1].slice(0, 2) : '');
64
- return parseFloat(formattedValue) || 0;
65
- }
66
- /**
67
- * Formats a number as currency with specific currency code and locale
68
- *
69
- * @param value - Number to format
70
- * @param currencyCode - ISO 4217 currency code (default: DEFAULT_CURRENCY)
71
- * @param locale - Locale for formatting (default: 'en-AU')
72
- * @param minimumFractionDigits - Minimum decimal places (default: 0)
73
- * @param maximumFractionDigits - Maximum decimal places (default: 0)
74
- * @returns Formatted currency string
75
- *
76
- * @example
77
- * ```typescript
78
- * formatCurrencyWithCode(1234.5) // 'A$1,235'
79
- * formatCurrencyWithCode(1234.5, 'USD', 'en-US') // '$1,235'
80
- * formatCurrencyWithCode(1234.56, 'AUD', 'en-AU', 2, 2) // 'A$1,234.56'
81
- * ```
82
- */
83
- export function formatCurrencyWithCode(value, currencyCode = DEFAULT_CURRENCY, locale = 'en-AU', minimumFractionDigits = 0, maximumFractionDigits = 0) {
84
- if (value == null || isNaN(value))
85
- return '';
86
- return new Intl.NumberFormat(locale, {
87
- style: 'currency',
88
- currency: currencyCode,
89
- minimumFractionDigits,
90
- maximumFractionDigits,
91
- }).format(value);
92
- }
93
- /**
94
- * Convenience function to format currency with the default currency (AUD)
95
- *
96
- * @param value - Number to format
97
- * @param minimumFractionDigits - Minimum decimal places (default: 0)
98
- * @param maximumFractionDigits - Maximum decimal places (default: 0)
99
- * @returns Formatted currency string with default currency
100
- *
101
- * @example
102
- * ```typescript
103
- * formatDefaultCurrency(1234.5) // 'A$1,235'
104
- * formatDefaultCurrency(1234.56, 2, 2) // 'A$1,234.56'
105
- * ```
106
- */
107
- export function formatDefaultCurrency(value, minimumFractionDigits = 0, maximumFractionDigits = 0) {
108
- return formatCurrencyWithCode(value, DEFAULT_CURRENCY, 'en-AU', minimumFractionDigits, maximumFractionDigits);
109
- }
110
- /**
111
- * Formats a number for displaying share quantities (no decimals)
112
- *
113
- * @param shares - Number of shares to format
114
- * @param locale - Locale for formatting (default: 'en-AU')
115
- * @returns Formatted shares string with commas as thousands separators
116
- *
117
- * @example
118
- * ```typescript
119
- * formatShares(1234) // '1,234'
120
- * formatShares(1234567) // '1,234,567'
121
- * ```
122
- */
123
- export function formatShares(shares, locale = 'en-AU') {
124
- return new Intl.NumberFormat(locale, {
125
- minimumFractionDigits: 0,
126
- maximumFractionDigits: 0,
127
- }).format(shares);
128
- }
package/dist/date.d.ts DELETED
@@ -1,64 +0,0 @@
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
@@ -1 +0,0 @@
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 DELETED
@@ -1,91 +0,0 @@
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
- }
@@ -1,46 +0,0 @@
1
- /**
2
- * File download utilities
3
- * Browser-based file download functionality
4
- */
5
- /**
6
- * Download a blob as a file
7
- * Creates a temporary download link and triggers the download
8
- * @param blob - The blob to download
9
- * @param filename - The filename for the downloaded file
10
- */
11
- export declare function downloadBlob(blob: Blob, filename: string): void;
12
- /**
13
- * Download text content as a file
14
- * @param content - Text content to download
15
- * @param filename - The filename for the downloaded file
16
- * @param mimeType - MIME type for the file (default: text/plain)
17
- */
18
- export declare function downloadTextFile(content: string, filename: string, mimeType?: string): void;
19
- /**
20
- * Download JSON data as a file
21
- * @param data - JavaScript object to serialize and download
22
- * @param filename - The filename for the downloaded file (should end with .json)
23
- */
24
- export declare function downloadJsonFile(data: unknown, filename: string): void;
25
- /**
26
- * Generate a timestamped filename
27
- * @param baseName - Base name for the file (without extension)
28
- * @param extension - File extension (with or without leading dot)
29
- * @param includeTime - Whether to include time in timestamp (default: false)
30
- * @returns Timestamped filename
31
- */
32
- export declare function generateTimestampedFilename(baseName: string, extension: string, includeTime?: boolean): string;
33
- /**
34
- * Download data URL as a file
35
- * @param dataUrl - Data URL (data:mime/type;base64,data)
36
- * @param filename - The filename for the downloaded file
37
- */
38
- export declare function downloadDataUrl(dataUrl: string, filename: string): void;
39
- /**
40
- * Download CSV data as a file
41
- * @param data - Array of objects to convert to CSV
42
- * @param filename - The filename for the downloaded file (should end with .csv)
43
- * @param headers - Optional custom headers (uses object keys if not provided)
44
- */
45
- export declare function downloadCsvFile<T extends Record<string, unknown>>(data: T[], filename: string, headers?: string[]): void;
46
- //# sourceMappingURL=downloads.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"downloads.d.ts","sourceRoot":"","sources":["../src/downloads.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAS/D;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAqB,GAAG,IAAI,CAGzG;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAGtE;AAED;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,GAAE,OAAe,GAAG,MAAM,CASrH;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAOvE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/D,IAAI,EAAE,CAAC,EAAE,EACT,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,EAAE,GACjB,IAAI,CAqBN"}
package/dist/downloads.js DELETED
@@ -1,91 +0,0 @@
1
- /**
2
- * File download utilities
3
- * Browser-based file download functionality
4
- */
5
- /**
6
- * Download a blob as a file
7
- * Creates a temporary download link and triggers the download
8
- * @param blob - The blob to download
9
- * @param filename - The filename for the downloaded file
10
- */
11
- export function downloadBlob(blob, filename) {
12
- const url = window.URL.createObjectURL(blob);
13
- const link = document.createElement('a');
14
- link.href = url;
15
- link.setAttribute('download', filename);
16
- document.body.appendChild(link);
17
- link.click();
18
- document.body.removeChild(link);
19
- window.URL.revokeObjectURL(url);
20
- }
21
- /**
22
- * Download text content as a file
23
- * @param content - Text content to download
24
- * @param filename - The filename for the downloaded file
25
- * @param mimeType - MIME type for the file (default: text/plain)
26
- */
27
- export function downloadTextFile(content, filename, mimeType = 'text/plain') {
28
- const blob = new Blob([content], { type: mimeType });
29
- downloadBlob(blob, filename);
30
- }
31
- /**
32
- * Download JSON data as a file
33
- * @param data - JavaScript object to serialize and download
34
- * @param filename - The filename for the downloaded file (should end with .json)
35
- */
36
- export function downloadJsonFile(data, filename) {
37
- const jsonString = JSON.stringify(data, null, 2);
38
- downloadTextFile(jsonString, filename, 'application/json');
39
- }
40
- /**
41
- * Generate a timestamped filename
42
- * @param baseName - Base name for the file (without extension)
43
- * @param extension - File extension (with or without leading dot)
44
- * @param includeTime - Whether to include time in timestamp (default: false)
45
- * @returns Timestamped filename
46
- */
47
- export function generateTimestampedFilename(baseName, extension, includeTime = false) {
48
- const now = new Date();
49
- const dateString = now.toISOString().split('T')[0]; // YYYY-MM-DD
50
- const timeString = now.toTimeString().split(' ')[0]?.replace(/:/g, '-') || '00-00-00'; // HH-MM-SS
51
- const cleanExtension = extension.startsWith('.') ? extension : `.${extension}`;
52
- const timestamp = includeTime ? `${dateString}-${timeString}` : dateString;
53
- return `${baseName}-${timestamp}${cleanExtension}`;
54
- }
55
- /**
56
- * Download data URL as a file
57
- * @param dataUrl - Data URL (data:mime/type;base64,data)
58
- * @param filename - The filename for the downloaded file
59
- */
60
- export function downloadDataUrl(dataUrl, filename) {
61
- const link = document.createElement('a');
62
- link.href = dataUrl;
63
- link.setAttribute('download', filename);
64
- document.body.appendChild(link);
65
- link.click();
66
- document.body.removeChild(link);
67
- }
68
- /**
69
- * Download CSV data as a file
70
- * @param data - Array of objects to convert to CSV
71
- * @param filename - The filename for the downloaded file (should end with .csv)
72
- * @param headers - Optional custom headers (uses object keys if not provided)
73
- */
74
- export function downloadCsvFile(data, filename, headers) {
75
- if (data.length === 0) {
76
- throw new Error('Cannot create CSV from empty data array');
77
- }
78
- const csvHeaders = headers || Object.keys(data[0] || {});
79
- const csvRows = data.map(row => csvHeaders
80
- .map(header => {
81
- const value = row[header];
82
- // Escape commas and quotes in CSV values
83
- const stringValue = String(value ?? '');
84
- return stringValue.includes(',') || stringValue.includes('"')
85
- ? `"${stringValue.replace(/"/g, '""')}"`
86
- : stringValue;
87
- })
88
- .join(','));
89
- const csvContent = [csvHeaders.join(','), ...csvRows].join('\n');
90
- downloadTextFile(csvContent, filename, 'text/csv');
91
- }