@cranberry-money/shared-utils 8.19.0 → 8.19.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 (82) hide show
  1. package/README.md +16 -9
  2. package/package.json +4 -2
  3. package/dist/allocations.d.ts +0 -18
  4. package/dist/allocations.d.ts.map +0 -1
  5. package/dist/allocations.js +0 -20
  6. package/dist/auth.d.ts +0 -54
  7. package/dist/auth.js +0 -135
  8. package/dist/badge-status.d.ts +0 -65
  9. package/dist/badge-status.d.ts.map +0 -1
  10. package/dist/badge-status.js +0 -170
  11. package/dist/badge.d.ts +0 -41
  12. package/dist/badge.d.ts.map +0 -1
  13. package/dist/badge.js +0 -72
  14. package/dist/cash-account.d.ts +0 -43
  15. package/dist/cash-account.d.ts.map +0 -1
  16. package/dist/cash-account.js +0 -52
  17. package/dist/collections.d.ts +0 -80
  18. package/dist/collections.js +0 -127
  19. package/dist/country.d.ts +0 -107
  20. package/dist/country.js +0 -116
  21. package/dist/currency.d.ts +0 -99
  22. package/dist/currency.d.ts.map +0 -1
  23. package/dist/currency.js +0 -128
  24. package/dist/dashboard.d.ts +0 -72
  25. package/dist/dashboard.d.ts.map +0 -1
  26. package/dist/dashboard.js +0 -121
  27. package/dist/date.d.ts +0 -64
  28. package/dist/date.d.ts.map +0 -1
  29. package/dist/date.js +0 -91
  30. package/dist/document.d.ts +0 -37
  31. package/dist/document.js +0 -57
  32. package/dist/downloads.d.ts +0 -12
  33. package/dist/downloads.d.ts.map +0 -1
  34. package/dist/downloads.js +0 -20
  35. package/dist/filters.d.ts +0 -82
  36. package/dist/filters.d.ts.map +0 -1
  37. package/dist/filters.js +0 -109
  38. package/dist/formatting.d.ts +0 -58
  39. package/dist/formatting.js +0 -81
  40. package/dist/holdings.d.ts +0 -16
  41. package/dist/holdings.d.ts.map +0 -1
  42. package/dist/holdings.js +0 -23
  43. package/dist/index.d.ts +0 -26
  44. package/dist/index.d.ts.map +0 -1
  45. package/dist/index.js +0 -46
  46. package/dist/industry.d.ts +0 -127
  47. package/dist/industry.js +0 -152
  48. package/dist/instruments.d.ts +0 -17
  49. package/dist/instruments.d.ts.map +0 -1
  50. package/dist/instruments.js +0 -36
  51. package/dist/investment-preference.d.ts +0 -24
  52. package/dist/investment-preference.js +0 -33
  53. package/dist/numbers.d.ts +0 -16
  54. package/dist/numbers.d.ts.map +0 -1
  55. package/dist/numbers.js +0 -27
  56. package/dist/portfolio-template.d.ts +0 -57
  57. package/dist/portfolio-template.d.ts.map +0 -1
  58. package/dist/portfolio-template.js +0 -61
  59. package/dist/portfolio-validation.d.ts +0 -35
  60. package/dist/portfolio-validation.d.ts.map +0 -1
  61. package/dist/portfolio-validation.js +0 -40
  62. package/dist/portfolio.d.ts +0 -68
  63. package/dist/portfolio.d.ts.map +0 -1
  64. package/dist/portfolio.js +0 -87
  65. package/dist/sector.d.ts +0 -123
  66. package/dist/sector.js +0 -134
  67. package/dist/stock-exchange.d.ts +0 -88
  68. package/dist/stock-exchange.js +0 -101
  69. package/dist/tax-residency.d.ts +0 -66
  70. package/dist/tax-residency.js +0 -70
  71. package/dist/text.d.ts +0 -22
  72. package/dist/text.d.ts.map +0 -1
  73. package/dist/text.js +0 -25
  74. package/dist/validation.d.ts +0 -93
  75. package/dist/validation.d.ts.map +0 -1
  76. package/dist/validation.js +0 -143
  77. package/dist/withdrawal-status.d.ts +0 -68
  78. package/dist/withdrawal-status.d.ts.map +0 -1
  79. package/dist/withdrawal-status.js +0 -127
  80. package/dist/withdrawal.d.ts +0 -48
  81. package/dist/withdrawal.d.ts.map +0 -1
  82. package/dist/withdrawal.js +0 -62
package/dist/badge.js DELETED
@@ -1,72 +0,0 @@
1
- /**
2
- * Badge System Core - Type definitions and factory function
3
- *
4
- * This module provides a standardized way to create and style badges.
5
- * It ensures consistency in colors, typography, and semantic meaning
6
- * while maintaining accessibility standards.
7
- *
8
- * Note: The actual style classes are designed to work with Tailwind CSS
9
- * and assume a specific color system is in place.
10
- */
11
- /**
12
- * Default variant styles using Tailwind CSS classes
13
- * These assume a specific color system with surface and semantic colors
14
- */
15
- const DEFAULT_BADGE_VARIANTS = {
16
- default: 'bg-surface-secondary text-content-body',
17
- primary: 'bg-surface-tertiary text-content-secondary',
18
- secondary: 'bg-surface-secondary text-content-body',
19
- success: 'bg-success-900/80 text-success-300',
20
- warning: 'bg-warning-900/80 text-warning-300',
21
- error: 'bg-error-900/80 text-error-300',
22
- info: 'bg-surface-tertiary text-content-body',
23
- neutral: 'bg-surface-secondary text-content-muted',
24
- };
25
- /**
26
- * Default size styles for badges
27
- */
28
- const DEFAULT_BADGE_SIZES = {
29
- sm: 'text-xs px-1.5 py-0.5',
30
- md: 'text-xs px-2 py-1',
31
- lg: 'text-sm px-3 py-1.5',
32
- };
33
- /**
34
- * Base badge styles that apply to all badges
35
- */
36
- const BASE_BADGE_STYLES = 'inline-flex items-center rounded-md font-medium whitespace-nowrap transition-colors';
37
- /**
38
- * Creates a badge style configuration with appropriate CSS classes
39
- *
40
- * @param config - Badge configuration options
41
- * @param variantStyles - Optional custom variant styles (defaults to DEFAULT_BADGE_VARIANTS)
42
- * @param sizeStyles - Optional custom size styles (defaults to DEFAULT_BADGE_SIZES)
43
- * @returns Badge style object with className and accessibility attributes
44
- *
45
- * @example
46
- * ```typescript
47
- * // Create a success badge
48
- * const successBadge = createBadge({ variant: 'success' });
49
- * // Returns: { className: 'inline-flex items-center rounded-md font-medium whitespace-nowrap transition-colors bg-success-900/80 text-success-300 text-xs px-2 py-1', ariaLabel: 'success status' }
50
- *
51
- * // Create a large warning badge with custom class
52
- * const warningBadge = createBadge({ variant: 'warning', size: 'lg', className: 'ml-2' });
53
- *
54
- * // Use custom variant styles
55
- * const customVariants = { primary: 'bg-blue-500 text-white', ... };
56
- * const customBadge = createBadge({ variant: 'primary' }, customVariants);
57
- * ```
58
- */
59
- export function createBadge({ variant, size = 'md', className = '' }, variantStyles = DEFAULT_BADGE_VARIANTS, sizeStyles = DEFAULT_BADGE_SIZES) {
60
- const variantClasses = variantStyles[variant] || variantStyles.neutral;
61
- const sizeClasses = sizeStyles[size];
62
- return {
63
- className: `${BASE_BADGE_STYLES} ${variantClasses} ${sizeClasses} ${className}`.trim(),
64
- ariaLabel: `${variant} status`,
65
- };
66
- }
67
- /**
68
- * Export the default style mappings for consumers who want to use them directly
69
- * or extend them with their own styles
70
- */
71
- export const BADGE_VARIANTS = DEFAULT_BADGE_VARIANTS;
72
- export const BADGE_SIZES = DEFAULT_BADGE_SIZES;
@@ -1,43 +0,0 @@
1
- /**
2
- * Base transaction type interface for type flexibility
3
- */
4
- export interface BaseTransactionType {
5
- readonly [key: string]: string;
6
- }
7
- /**
8
- * Format cash account balance with AUD currency formatting
9
- *
10
- * @param balance - Balance value to format (string or number)
11
- * @returns Formatted currency string using Australian locale and AUD currency
12
- *
13
- * @example
14
- * formatBalance(1234.56); // returns '$1,234.56'
15
- * formatBalance('1000'); // returns '$1,000.00'
16
- * formatBalance(0); // returns '$0.00'
17
- */
18
- export declare const formatBalance: (balance: string | number) => string;
19
- /**
20
- * Format transaction amount with signed currency formatting (shows + or -)
21
- *
22
- * @param amount - Transaction amount to format (string or number)
23
- * @returns Formatted signed currency string using Australian locale and AUD currency
24
- *
25
- * @example
26
- * formatTransactionAmount(1234.56); // returns '+$1,234.56'
27
- * formatTransactionAmount(-500); // returns '-$500.00'
28
- * formatTransactionAmount('1000'); // returns '+$1,000.00'
29
- */
30
- export declare const formatTransactionAmount: (amount: string | number) => string;
31
- /**
32
- * Get human-readable label for transaction type
33
- *
34
- * @param transactionType - Transaction type key
35
- * @param labels - Optional custom transaction type labels (defaults to shared constants)
36
- * @returns Human-readable transaction type label
37
- *
38
- * @example
39
- * getTransactionTypeLabel('DEPOSIT'); // returns transaction type label from constants
40
- * getTransactionTypeLabel('WITHDRAWAL'); // returns transaction type label from constants
41
- */
42
- export declare const getTransactionTypeLabel: <T extends string>(transactionType: T, labels?: Record<T, string>) => string;
43
- //# sourceMappingURL=cash-account.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cash-account.d.ts","sourceRoot":"","sources":["../src/cash-account.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CAChC;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,GAAG,MAAM,KAAG,MAMxD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,GAAI,QAAQ,MAAM,GAAG,MAAM,KAAG,MAMjE,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,GAAI,CAAC,SAAS,MAAM,EACtD,iBAAiB,CAAC,EAClB,SAAQ,MAAM,CAAC,CAAC,EAAE,MAAM,CAA6D,KACpF,MAEF,CAAC"}
@@ -1,52 +0,0 @@
1
- import { LOCALE_AUSTRALIA, CURRENCY_AUD, CASH_ACCOUNT_TRANSACTION_TYPE_LABELS, } from '@cranberry-money/shared-constants';
2
- import { NUMBER_FORMAT_OPTIONS_CURRENCY, NUMBER_FORMAT_OPTIONS_CURRENCY_SIGNED } from './currency';
3
- /**
4
- * Format cash account balance with AUD currency formatting
5
- *
6
- * @param balance - Balance value to format (string or number)
7
- * @returns Formatted currency string using Australian locale and AUD currency
8
- *
9
- * @example
10
- * formatBalance(1234.56); // returns '$1,234.56'
11
- * formatBalance('1000'); // returns '$1,000.00'
12
- * formatBalance(0); // returns '$0.00'
13
- */
14
- export const formatBalance = (balance) => {
15
- const numBalance = typeof balance === 'string' ? parseFloat(balance) : balance;
16
- return new Intl.NumberFormat(LOCALE_AUSTRALIA, {
17
- ...NUMBER_FORMAT_OPTIONS_CURRENCY,
18
- currency: CURRENCY_AUD,
19
- }).format(numBalance);
20
- };
21
- /**
22
- * Format transaction amount with signed currency formatting (shows + or -)
23
- *
24
- * @param amount - Transaction amount to format (string or number)
25
- * @returns Formatted signed currency string using Australian locale and AUD currency
26
- *
27
- * @example
28
- * formatTransactionAmount(1234.56); // returns '+$1,234.56'
29
- * formatTransactionAmount(-500); // returns '-$500.00'
30
- * formatTransactionAmount('1000'); // returns '+$1,000.00'
31
- */
32
- export const formatTransactionAmount = (amount) => {
33
- const numAmount = typeof amount === 'string' ? parseFloat(amount) : amount;
34
- return new Intl.NumberFormat(LOCALE_AUSTRALIA, {
35
- ...NUMBER_FORMAT_OPTIONS_CURRENCY_SIGNED,
36
- currency: CURRENCY_AUD,
37
- }).format(numAmount);
38
- };
39
- /**
40
- * Get human-readable label for transaction type
41
- *
42
- * @param transactionType - Transaction type key
43
- * @param labels - Optional custom transaction type labels (defaults to shared constants)
44
- * @returns Human-readable transaction type label
45
- *
46
- * @example
47
- * getTransactionTypeLabel('DEPOSIT'); // returns transaction type label from constants
48
- * getTransactionTypeLabel('WITHDRAWAL'); // returns transaction type label from constants
49
- */
50
- export const getTransactionTypeLabel = (transactionType, labels = CASH_ACCOUNT_TRANSACTION_TYPE_LABELS) => {
51
- return labels[transactionType];
52
- };
@@ -1,80 +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 declare function sortByStringField<T>(items: T[], fieldName: keyof T): T[];
12
- /**
13
- * Filter array by text search in a specific field (case-insensitive)
14
- * @param items - Array of objects to filter
15
- * @param fieldName - Name of the field to search in
16
- * @param searchTerm - Search term
17
- * @returns Filtered array
18
- */
19
- export declare function filterByTextSearch<T>(items: T[], fieldName: keyof T, searchTerm: string): T[];
20
- /**
21
- * Filter array by boolean field
22
- * @param items - Array of objects to filter
23
- * @param fieldName - Name of the boolean field
24
- * @param value - Boolean value to filter by
25
- * @returns Filtered array
26
- */
27
- export declare function filterByBooleanField<T>(items: T[], fieldName: keyof T, value: boolean): T[];
28
- /**
29
- * Find item by exact field match
30
- * @param items - Array of objects to search
31
- * @param fieldName - Name of the field to match
32
- * @param value - Value to match
33
- * @returns Found item or undefined
34
- */
35
- export declare function findByField<T>(items: T[], fieldName: keyof T, value: unknown): T | undefined;
36
- /**
37
- * Find item by case-insensitive string field match
38
- * @param items - Array of objects to search
39
- * @param fieldName - Name of the string field to match
40
- * @param value - String value to match (case-insensitive)
41
- * @returns Found item or undefined
42
- */
43
- export declare function findByStringField<T>(items: T[], fieldName: keyof T, value: string): T | undefined;
44
- /**
45
- * Extract values from a specific field and sort them
46
- * @param items - Array of objects
47
- * @param fieldName - Name of the field to extract
48
- * @returns Sorted array of extracted values
49
- */
50
- export declare function extractAndSortField<T, K extends keyof T>(items: T[], fieldName: K): T[K][];
51
- /**
52
- * Group array items by the first character of a string field
53
- * @param items - Array of objects to group
54
- * @param fieldName - Name of the string field to group by
55
- * @returns Object with first letters as keys and arrays of items as values
56
- */
57
- export declare function groupByFirstLetter<T>(items: T[], fieldName: keyof T): Record<string, T[]>;
58
- /**
59
- * Group array items by a field value
60
- * @param items - Array of objects to group
61
- * @param fieldName - Name of the field to group by
62
- * @returns Object with field values as keys and arrays of items as values
63
- */
64
- export declare function groupByField<T, K extends keyof T>(items: T[], fieldName: K): Record<string, T[]>;
65
- /**
66
- * Check if any item in array has a specific boolean field value
67
- * @param items - Array of objects to check
68
- * @param fieldName - Name of the boolean field
69
- * @param value - Boolean value to check for
70
- * @returns true if any item matches, false otherwise
71
- */
72
- export declare function hasItemWithFieldValue<T>(items: T[], fieldName: keyof T, value: unknown): boolean;
73
- /**
74
- * Count items that match a field value
75
- * @param items - Array of objects to count
76
- * @param fieldName - Name of the field to check
77
- * @param value - Value to count
78
- * @returns Number of matching items
79
- */
80
- export declare function countByFieldValue<T>(items: T[], fieldName: keyof T, value: unknown): number;
@@ -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
- }
package/dist/country.d.ts DELETED
@@ -1,107 +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;
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
- };