@cranberry-money/shared-utils 8.17.6 → 8.17.7

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 (77) hide show
  1. package/dist/auth.d.ts +1 -25
  2. package/dist/auth.d.ts.map +1 -1
  3. package/dist/badge-status.d.ts +2 -6
  4. package/dist/badge-status.d.ts.map +1 -1
  5. package/dist/badge.d.ts +1 -9
  6. package/dist/badge.d.ts.map +1 -1
  7. package/dist/instruments.d.ts +1 -33
  8. package/dist/instruments.d.ts.map +1 -1
  9. package/dist/portfolio-validation.d.ts +1 -5
  10. package/dist/portfolio-validation.d.ts.map +1 -1
  11. package/dist/validation.d.ts +1 -13
  12. package/dist/validation.d.ts.map +1 -1
  13. package/dist/withdrawal.d.ts +1 -9
  14. package/dist/withdrawal.d.ts.map +1 -1
  15. package/package.json +1 -1
  16. package/dist/allocations.d.ts +0 -18
  17. package/dist/allocations.js +0 -20
  18. package/dist/cash-account.d.ts +0 -43
  19. package/dist/cash-account.d.ts.map +0 -1
  20. package/dist/cash-account.js +0 -52
  21. package/dist/collections.d.ts +0 -81
  22. package/dist/collections.d.ts.map +0 -1
  23. package/dist/collections.js +0 -127
  24. package/dist/country.d.ts +0 -108
  25. package/dist/country.d.ts.map +0 -1
  26. package/dist/country.js +0 -116
  27. package/dist/currency.d.ts +0 -99
  28. package/dist/currency.d.ts.map +0 -1
  29. package/dist/currency.js +0 -128
  30. package/dist/dashboard.d.ts +0 -72
  31. package/dist/dashboard.js +0 -121
  32. package/dist/date.d.ts.map +0 -1
  33. package/dist/date.js +0 -91
  34. package/dist/document.d.ts +0 -38
  35. package/dist/document.d.ts.map +0 -1
  36. package/dist/document.js +0 -56
  37. package/dist/downloads.d.ts +0 -46
  38. package/dist/downloads.d.ts.map +0 -1
  39. package/dist/downloads.js +0 -91
  40. package/dist/filters.d.ts +0 -121
  41. package/dist/filters.d.ts.map +0 -1
  42. package/dist/filters.js +0 -206
  43. package/dist/formatting.d.ts +0 -59
  44. package/dist/formatting.d.ts.map +0 -1
  45. package/dist/formatting.js +0 -81
  46. package/dist/holdings.d.ts +0 -79
  47. package/dist/holdings.js +0 -139
  48. package/dist/index.d.ts +0 -36
  49. package/dist/index.js +0 -68
  50. package/dist/industry.d.ts +0 -128
  51. package/dist/industry.d.ts.map +0 -1
  52. package/dist/industry.js +0 -152
  53. package/dist/investment-preference.d.ts +0 -25
  54. package/dist/investment-preference.js +0 -33
  55. package/dist/numbers.d.ts +0 -72
  56. package/dist/numbers.d.ts.map +0 -1
  57. package/dist/numbers.js +0 -101
  58. package/dist/portfolio-template.d.ts +0 -57
  59. package/dist/portfolio-template.d.ts.map +0 -1
  60. package/dist/portfolio-template.js +0 -60
  61. package/dist/portfolio.d.ts +0 -68
  62. package/dist/portfolio.d.ts.map +0 -1
  63. package/dist/portfolio.js +0 -87
  64. package/dist/sector.d.ts +0 -124
  65. package/dist/sector.d.ts.map +0 -1
  66. package/dist/sector.js +0 -134
  67. package/dist/stock-exchange.d.ts +0 -89
  68. package/dist/stock-exchange.d.ts.map +0 -1
  69. package/dist/stock-exchange.js +0 -101
  70. package/dist/tax-residency.d.ts +0 -67
  71. package/dist/tax-residency.d.ts.map +0 -1
  72. package/dist/tax-residency.js +0 -70
  73. package/dist/text.d.ts.map +0 -1
  74. package/dist/text.js +0 -25
  75. package/dist/withdrawal-status.d.ts +0 -72
  76. package/dist/withdrawal-status.d.ts.map +0 -1
  77. package/dist/withdrawal-status.js +0 -127
package/dist/country.d.ts DELETED
@@ -1,108 +0,0 @@
1
- /**
2
- * Base interface for country objects
3
- */
4
- export interface BaseCountry {
5
- readonly name: string;
6
- readonly code: string;
7
- readonly uuid: string;
8
- readonly isAvailable: boolean;
9
- readonly dialCode?: string;
10
- }
11
- /**
12
- * Sort countries by name
13
- *
14
- * @param countries - Array of countries to sort
15
- * @returns Sorted array of countries
16
- *
17
- * @example
18
- * const sorted = sortCountriesByName(countries);
19
- */
20
- export declare const sortCountriesByName: <T extends BaseCountry>(countries: readonly T[]) => T[];
21
- /**
22
- * Filter countries by name (case-insensitive search)
23
- *
24
- * @param countries - Array of countries to filter
25
- * @param searchTerm - Search term to filter by
26
- * @returns Filtered array of countries
27
- *
28
- * @example
29
- * const filtered = filterCountriesByName(countries, 'united');
30
- * // Returns countries with 'united' in the name
31
- */
32
- export declare const filterCountriesByName: <T extends BaseCountry>(countries: readonly T[], searchTerm: string) => T[];
33
- /**
34
- * Filter countries by availability
35
- *
36
- * @param countries - Array of countries to filter
37
- * @returns Array of available countries
38
- *
39
- * @example
40
- * const available = filterAvailableCountries(countries);
41
- */
42
- export declare const filterAvailableCountries: <T extends BaseCountry>(countries: readonly T[]) => T[];
43
- /**
44
- * Find country by exact name match
45
- *
46
- * @param countries - Array of countries to search
47
- * @param name - Exact name to find
48
- * @returns Found country or undefined
49
- *
50
- * @example
51
- * const country = findCountryByName(countries, 'United States');
52
- */
53
- export declare const findCountryByName: <T extends BaseCountry>(countries: readonly T[], name: string) => T | undefined;
54
- /**
55
- * Find country by country code
56
- *
57
- * @param countries - Array of countries to search
58
- * @param code - Country code to find (e.g., 'US', 'CA')
59
- * @returns Found country or undefined
60
- *
61
- * @example
62
- * const country = findCountryByCode(countries, 'US');
63
- */
64
- export declare const findCountryByCode: <T extends BaseCountry>(countries: readonly T[], code: string) => T | undefined;
65
- /**
66
- * Get sorted list of country names
67
- *
68
- * @param countries - Array of countries
69
- * @returns Sorted array of country names
70
- *
71
- * @example
72
- * const names = getCountryNames(countries);
73
- * // ['Australia', 'Canada', 'United States', ...]
74
- */
75
- export declare const getCountryNames: <T extends BaseCountry>(countries: readonly T[]) => string[];
76
- /**
77
- * Group countries alphabetically by first letter
78
- *
79
- * @param countries - Array of countries to group
80
- * @returns Record of countries grouped by first letter
81
- *
82
- * @example
83
- * const grouped = groupCountriesAlphabetically(countries);
84
- * // { 'A': [...], 'B': [...], 'C': [...], ... }
85
- */
86
- export declare const groupCountriesAlphabetically: <T extends BaseCountry>(countries: readonly T[]) => Record<string, T[]>;
87
- /**
88
- * Format country with dial code for display
89
- *
90
- * @param country - Country to format
91
- * @returns Formatted string with country name and dial code
92
- *
93
- * @example
94
- * formatCountryWithDialCode({ name: 'United States', dialCode: '+1', ... });
95
- * // Returns 'United States (+1)'
96
- */
97
- export declare const formatCountryWithDialCode: <T extends BaseCountry>(country: T) => string;
98
- /**
99
- * Check if a country is available
100
- *
101
- * @param country - Country to check
102
- * @returns True if country is available
103
- *
104
- * @example
105
- * const available = isCountryAvailable(country);
106
- */
107
- export declare const isCountryAvailable: <T extends BaseCountry>(country: T) => boolean;
108
- //# sourceMappingURL=country.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"country.d.ts","sourceRoot":"","sources":["../src/country.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,WAAW,EAAE,WAAW,SAAS,CAAC,EAAE,KAAG,CAAC,EAErF,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,GAAI,CAAC,SAAS,WAAW,EAAE,WAAW,SAAS,CAAC,EAAE,EAAE,YAAY,MAAM,KAAG,CAAC,EAE3G,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,GAAI,CAAC,SAAS,WAAW,EAAE,WAAW,SAAS,CAAC,EAAE,KAAG,CAAC,EAE1F,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,WAAW,EAAE,WAAW,SAAS,CAAC,EAAE,EAAE,MAAM,MAAM,KAAG,CAAC,GAAG,SAEpG,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,WAAW,EAAE,WAAW,SAAS,CAAC,EAAE,EAAE,MAAM,MAAM,KAAG,CAAC,GAAG,SAEpG,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,WAAW,EAAE,WAAW,SAAS,CAAC,EAAE,KAAG,MAAM,EAEtF,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,4BAA4B,GAAI,CAAC,SAAS,WAAW,EAAE,WAAW,SAAS,CAAC,EAAE,KAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAE/G,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,yBAAyB,GAAI,CAAC,SAAS,WAAW,EAAE,SAAS,CAAC,KAAG,MAE7E,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,WAAW,EAAE,SAAS,CAAC,KAAG,OAEtE,CAAC"}
package/dist/country.js DELETED
@@ -1,116 +0,0 @@
1
- import { sortByStringField, filterByTextSearch, filterByBooleanField, findByStringField, extractAndSortField, groupByFirstLetter, } from './collections';
2
- /**
3
- * Sort countries by name
4
- *
5
- * @param countries - Array of countries to sort
6
- * @returns Sorted array of countries
7
- *
8
- * @example
9
- * const sorted = sortCountriesByName(countries);
10
- */
11
- export const sortCountriesByName = (countries) => {
12
- return sortByStringField([...countries], 'name');
13
- };
14
- /**
15
- * Filter countries by name (case-insensitive search)
16
- *
17
- * @param countries - Array of countries to filter
18
- * @param searchTerm - Search term to filter by
19
- * @returns Filtered array of countries
20
- *
21
- * @example
22
- * const filtered = filterCountriesByName(countries, 'united');
23
- * // Returns countries with 'united' in the name
24
- */
25
- export const filterCountriesByName = (countries, searchTerm) => {
26
- return filterByTextSearch([...countries], 'name', searchTerm);
27
- };
28
- /**
29
- * Filter countries by availability
30
- *
31
- * @param countries - Array of countries to filter
32
- * @returns Array of available countries
33
- *
34
- * @example
35
- * const available = filterAvailableCountries(countries);
36
- */
37
- export const filterAvailableCountries = (countries) => {
38
- return filterByBooleanField([...countries], 'isAvailable', true);
39
- };
40
- /**
41
- * Find country by exact name match
42
- *
43
- * @param countries - Array of countries to search
44
- * @param name - Exact name to find
45
- * @returns Found country or undefined
46
- *
47
- * @example
48
- * const country = findCountryByName(countries, 'United States');
49
- */
50
- export const findCountryByName = (countries, name) => {
51
- return findByStringField([...countries], 'name', name);
52
- };
53
- /**
54
- * Find country by country code
55
- *
56
- * @param countries - Array of countries to search
57
- * @param code - Country code to find (e.g., 'US', 'CA')
58
- * @returns Found country or undefined
59
- *
60
- * @example
61
- * const country = findCountryByCode(countries, 'US');
62
- */
63
- export const findCountryByCode = (countries, code) => {
64
- return findByStringField([...countries], 'code', code);
65
- };
66
- /**
67
- * Get sorted list of country names
68
- *
69
- * @param countries - Array of countries
70
- * @returns Sorted array of country names
71
- *
72
- * @example
73
- * const names = getCountryNames(countries);
74
- * // ['Australia', 'Canada', 'United States', ...]
75
- */
76
- export const getCountryNames = (countries) => {
77
- return extractAndSortField([...countries], 'name');
78
- };
79
- /**
80
- * Group countries alphabetically by first letter
81
- *
82
- * @param countries - Array of countries to group
83
- * @returns Record of countries grouped by first letter
84
- *
85
- * @example
86
- * const grouped = groupCountriesAlphabetically(countries);
87
- * // { 'A': [...], 'B': [...], 'C': [...], ... }
88
- */
89
- export const groupCountriesAlphabetically = (countries) => {
90
- return groupByFirstLetter([...countries], 'name');
91
- };
92
- /**
93
- * Format country with dial code for display
94
- *
95
- * @param country - Country to format
96
- * @returns Formatted string with country name and dial code
97
- *
98
- * @example
99
- * formatCountryWithDialCode({ name: 'United States', dialCode: '+1', ... });
100
- * // Returns 'United States (+1)'
101
- */
102
- export const formatCountryWithDialCode = (country) => {
103
- return country.dialCode ? `${country.name} (${country.dialCode})` : country.name;
104
- };
105
- /**
106
- * Check if a country is available
107
- *
108
- * @param country - Country to check
109
- * @returns True if country is available
110
- *
111
- * @example
112
- * const available = isCountryAvailable(country);
113
- */
114
- export const isCountryAvailable = (country) => {
115
- return country.isAvailable;
116
- };
@@ -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
- }
@@ -1,72 +0,0 @@
1
- import type { AssetAllocation, AssetHolding } from '@cranberry-money/shared-types';
2
- /**
3
- * Display item interface for allocation data
4
- */
5
- export interface AllocationDisplayItem {
6
- readonly instrumentUuid: string;
7
- readonly symbol: string;
8
- readonly name: string;
9
- readonly targetPercentage?: number;
10
- readonly actualPercentage?: number;
11
- readonly quantity?: number;
12
- readonly value?: number;
13
- readonly currentPrice?: number;
14
- readonly color: string;
15
- readonly hasTarget: boolean;
16
- readonly hasActual: boolean;
17
- }
18
- /**
19
- * Processes allocation and holding data for dashboard display
20
- * Merges target allocations with actual holdings data
21
- *
22
- * @param allocations - Target asset allocations
23
- * @param holdings - Actual asset holdings
24
- * @returns Array of display items sorted by target/actual percentage
25
- *
26
- * @example
27
- * const allocations = [{ instrument: '123', percentage: '50.00', ... }];
28
- * const holdings = [{ instrument: { uuid: '123' }, quantity: 100, ... }];
29
- * processAllocationData(allocations, holdings);
30
- */
31
- export declare const processAllocationData: (allocations: readonly AssetAllocation[], holdings: readonly AssetHolding[]) => AllocationDisplayItem[];
32
- /**
33
- * Calculates totals from allocation display items
34
- *
35
- * @param items - Array of allocation display items
36
- * @returns Object with total calculations
37
- *
38
- * @example
39
- * const items = [{ targetPercentage: 50, actualPercentage: 45, value: 1000, quantity: 10 }];
40
- * calculateTotals(items);
41
- * // returns { totalTarget: 50, totalActual: 45, totalValue: 1000, totalQuantity: 10 }
42
- */
43
- export declare const calculateTotals: (items: readonly AllocationDisplayItem[]) => {
44
- totalTarget: number;
45
- totalActual: number;
46
- totalValue: number;
47
- totalQuantity: number;
48
- };
49
- /**
50
- * Formats a percentage value for display
51
- *
52
- * @param value - The percentage value to format
53
- * @returns Formatted percentage string
54
- *
55
- * @example
56
- * formatPercentage(45.678); // returns "45.7%"
57
- * formatPercentage(undefined); // returns "0.0%"
58
- */
59
- export declare const formatPercentage: (value?: number) => string;
60
- /**
61
- * Formats currency value for dashboard display
62
- *
63
- * @param value - The numeric value to format
64
- * @param currency - Currency code (defaults to DEFAULT_CURRENCY)
65
- * @returns Formatted currency string or "—" for undefined values
66
- *
67
- * @example
68
- * formatDashboardCurrency(1234.56); // returns "$1,234.56"
69
- * formatDashboardCurrency(undefined); // returns "—"
70
- */
71
- export declare const formatDashboardCurrency: (value?: number, currency?: string) => string;
72
- //# sourceMappingURL=dashboard.d.ts.map
package/dist/dashboard.js DELETED
@@ -1,121 +0,0 @@
1
- import { DEFAULT_CURRENCY } from '@cranberry-money/shared-constants';
2
- import { getChartColor } from '@cranberry-money/shared-constants';
3
- import { formatCurrencyWithCode } from './currency';
4
- import { calculateHoldingAllocations } from './holdings';
5
- /**
6
- * Processes allocation and holding data for dashboard display
7
- * Merges target allocations with actual holdings data
8
- *
9
- * @param allocations - Target asset allocations
10
- * @param holdings - Actual asset holdings
11
- * @returns Array of display items sorted by target/actual percentage
12
- *
13
- * @example
14
- * const allocations = [{ instrument: '123', percentage: '50.00', ... }];
15
- * const holdings = [{ instrument: { uuid: '123' }, quantity: 100, ... }];
16
- * processAllocationData(allocations, holdings);
17
- */
18
- export const processAllocationData = (allocations, holdings) => {
19
- const actualAllocations = calculateHoldingAllocations(holdings);
20
- const instrumentMap = new Map();
21
- // Process target allocations
22
- allocations.forEach(allocation => {
23
- instrumentMap.set(allocation.instrument, {
24
- symbol: allocation.instrumentSymbol,
25
- name: allocation.instrumentName,
26
- targetPercentage: parseFloat(allocation.percentage),
27
- });
28
- });
29
- // Process actual holdings
30
- holdings.forEach(holding => {
31
- const existing = instrumentMap.get(holding.instrument.uuid);
32
- const currentPrice = parseFloat(holding.instrument.currentPrice || '0');
33
- const value = holding.quantity * currentPrice;
34
- instrumentMap.set(holding.instrument.uuid, {
35
- symbol: holding.instrumentSymbol,
36
- name: holding.instrumentName,
37
- targetPercentage: existing?.targetPercentage,
38
- actualPercentage: actualAllocations[holding.instrument.uuid] || 0,
39
- quantity: holding.quantity,
40
- currentPrice,
41
- value,
42
- });
43
- });
44
- // Convert to display items
45
- const items = [];
46
- let colorIndex = 0;
47
- instrumentMap.forEach((data, instrumentUuid) => {
48
- items.push({
49
- instrumentUuid,
50
- symbol: data.symbol,
51
- name: data.name,
52
- targetPercentage: data.targetPercentage,
53
- actualPercentage: data.actualPercentage,
54
- quantity: data.quantity,
55
- currentPrice: data.currentPrice,
56
- value: data.value,
57
- color: getChartColor(colorIndex++),
58
- hasTarget: data.targetPercentage !== undefined,
59
- hasActual: data.actualPercentage !== undefined && data.actualPercentage > 0,
60
- });
61
- });
62
- // Sort by target percentage (highest first), then by actual percentage
63
- return items.sort((a, b) => {
64
- const aTarget = a.targetPercentage || 0;
65
- const bTarget = b.targetPercentage || 0;
66
- if (aTarget !== bTarget)
67
- return bTarget - aTarget;
68
- const aActual = a.actualPercentage || 0;
69
- const bActual = b.actualPercentage || 0;
70
- return bActual - aActual;
71
- });
72
- };
73
- /**
74
- * Calculates totals from allocation display items
75
- *
76
- * @param items - Array of allocation display items
77
- * @returns Object with total calculations
78
- *
79
- * @example
80
- * const items = [{ targetPercentage: 50, actualPercentage: 45, value: 1000, quantity: 10 }];
81
- * calculateTotals(items);
82
- * // returns { totalTarget: 50, totalActual: 45, totalValue: 1000, totalQuantity: 10 }
83
- */
84
- export const calculateTotals = (items) => {
85
- const totalTarget = items.reduce((sum, item) => sum + (item.targetPercentage || 0), 0);
86
- const totalActual = items.reduce((sum, item) => sum + (item.actualPercentage || 0), 0);
87
- const totalValue = items.reduce((sum, item) => sum + (item.value || 0), 0);
88
- const totalQuantity = items.reduce((sum, item) => sum + (item.quantity || 0), 0);
89
- return { totalTarget, totalActual, totalValue, totalQuantity };
90
- };
91
- /**
92
- * Formats a percentage value for display
93
- *
94
- * @param value - The percentage value to format
95
- * @returns Formatted percentage string
96
- *
97
- * @example
98
- * formatPercentage(45.678); // returns "45.7%"
99
- * formatPercentage(undefined); // returns "0.0%"
100
- */
101
- export const formatPercentage = (value) => {
102
- if (value === undefined)
103
- return '0.0%';
104
- return `${value.toFixed(1)}%`;
105
- };
106
- /**
107
- * Formats currency value for dashboard display
108
- *
109
- * @param value - The numeric value to format
110
- * @param currency - Currency code (defaults to DEFAULT_CURRENCY)
111
- * @returns Formatted currency string or "—" for undefined values
112
- *
113
- * @example
114
- * formatDashboardCurrency(1234.56); // returns "$1,234.56"
115
- * formatDashboardCurrency(undefined); // returns "—"
116
- */
117
- export const formatDashboardCurrency = (value, currency = DEFAULT_CURRENCY) => {
118
- if (value === undefined || value === null)
119
- return '—';
120
- return formatCurrencyWithCode(value, currency, 'en-AU', 2, 2);
121
- };
@@ -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"}