@cranberry-money/shared-utils 8.9.0 → 8.11.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.
@@ -0,0 +1,108 @@
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
@@ -0,0 +1 @@
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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0,0 +1,116 @@
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
+ };
package/dist/index.d.ts CHANGED
@@ -28,4 +28,6 @@ export { findPrimaryTaxResidency, filterTaxResidenciesByCountry, hasTaxResidency
28
28
  export { getCountriesFromExchanges, groupExchangesByCountry, findExchangeByShortName, sortExchangesByName, filterExchangesByCountry, type BaseCountry, type BaseStockExchange, type SortDirection, } from './stock-exchange';
29
29
  export { sortSectorsByName, filterSectorsByName, findSectorByName, getSectorNames, groupSectorsAlphabetically, sectorExists, findSectorsByPartialName, type BaseSector, } from './sector';
30
30
  export { generateDocumentFilename, formatDocumentType, formatDocumentStatus, } from './document';
31
+ export { sortIndustriesByName, filterIndustriesByName, filterIndustriesBySector, findIndustryByName, getIndustryNames, groupIndustriesBySector, groupIndustriesAlphabetically, getIndustriesWithoutSector, getIndustriesWithSector, countIndustriesBySector, isIndustryInSector, type BaseIndustry, } from './industry';
32
+ export { sortCountriesByName, filterCountriesByName, filterAvailableCountries, findCountryByName, findCountryByCode, getCountryNames, groupCountriesAlphabetically, formatCountryWithDialCode, isCountryAvailable, type BaseCountry as BaseCountryType, } from './country';
31
33
  //# 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;AAGtC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAGjF,OAAO,EACL,8BAA8B,EAC9B,qCAAqC,EACrC,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,YAAY,GACb,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGnE,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhH,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,4BAA4B,EAC5B,sBAAsB,GACvB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,uBAAuB,EACvB,yBAAyB,EACzB,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,QAAQ,EACR,wBAAwB,EACxB,kBAAkB,EAClB,kBAAkB,EAClB,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,cAAc,EACd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/dist/index.js CHANGED
@@ -56,3 +56,7 @@ export { getCountriesFromExchanges, groupExchangesByCountry, findExchangeByShort
56
56
  export { sortSectorsByName, filterSectorsByName, findSectorByName, getSectorNames, groupSectorsAlphabetically, sectorExists, findSectorsByPartialName, } from './sector';
57
57
  // Document utilities
58
58
  export { generateDocumentFilename, formatDocumentType, formatDocumentStatus, } from './document';
59
+ // Industry utilities
60
+ export { sortIndustriesByName, filterIndustriesByName, filterIndustriesBySector, findIndustryByName, getIndustryNames, groupIndustriesBySector, groupIndustriesAlphabetically, getIndustriesWithoutSector, getIndustriesWithSector, countIndustriesBySector, isIndustryInSector, } from './industry';
61
+ // Country utilities
62
+ export { sortCountriesByName, filterCountriesByName, filterAvailableCountries, findCountryByName, findCountryByCode, getCountryNames, groupCountriesAlphabetically, formatCountryWithDialCode, isCountryAvailable, } from './country';
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Base interface for industry objects
3
+ */
4
+ export interface BaseIndustry {
5
+ readonly name: string;
6
+ readonly sector?: string;
7
+ readonly uuid: string;
8
+ }
9
+ /**
10
+ * Sort industries by name
11
+ *
12
+ * @param industries - Array of industries to sort
13
+ * @param direction - Sort direction ('asc' or 'desc')
14
+ * @returns Sorted array of industries
15
+ *
16
+ * @example
17
+ * const sorted = sortIndustriesByName(industries, 'asc');
18
+ */
19
+ export declare const sortIndustriesByName: <T extends BaseIndustry>(industries: readonly T[], direction?: "asc" | "desc") => T[];
20
+ /**
21
+ * Filter industries by name (case-insensitive search)
22
+ *
23
+ * @param industries - Array of industries to filter
24
+ * @param searchTerm - Search term to filter by
25
+ * @returns Filtered array of industries
26
+ *
27
+ * @example
28
+ * const filtered = filterIndustriesByName(industries, 'tech');
29
+ */
30
+ export declare const filterIndustriesByName: <T extends BaseIndustry>(industries: readonly T[], searchTerm: string) => T[];
31
+ /**
32
+ * Filter industries by sector
33
+ *
34
+ * @param industries - Array of industries to filter
35
+ * @param sectorUuid - UUID of the sector to filter by
36
+ * @returns Filtered array of industries
37
+ *
38
+ * @example
39
+ * const filtered = filterIndustriesBySector(industries, 'sector-123');
40
+ */
41
+ export declare const filterIndustriesBySector: <T extends BaseIndustry>(industries: readonly T[], sectorUuid: string) => T[];
42
+ /**
43
+ * Find industry by exact name match
44
+ *
45
+ * @param industries - Array of industries to search
46
+ * @param name - Exact name to find
47
+ * @returns Found industry or undefined
48
+ *
49
+ * @example
50
+ * const industry = findIndustryByName(industries, 'Technology');
51
+ */
52
+ export declare const findIndustryByName: <T extends BaseIndustry>(industries: readonly T[], name: string) => T | undefined;
53
+ /**
54
+ * Get sorted list of industry names
55
+ *
56
+ * @param industries - Array of industries
57
+ * @returns Sorted array of industry names
58
+ *
59
+ * @example
60
+ * const names = getIndustryNames(industries);
61
+ * // ['Automotive', 'Banking', 'Technology', ...]
62
+ */
63
+ export declare const getIndustryNames: <T extends BaseIndustry>(industries: readonly T[]) => string[];
64
+ /**
65
+ * Group industries by sector
66
+ *
67
+ * @param industries - Array of industries to group
68
+ * @returns Record of industries grouped by sector UUID
69
+ *
70
+ * @example
71
+ * const grouped = groupIndustriesBySector(industries);
72
+ * // { 'sector-123': [...], 'no-sector': [...] }
73
+ */
74
+ export declare const groupIndustriesBySector: <T extends BaseIndustry>(industries: readonly T[]) => Record<string, T[]>;
75
+ /**
76
+ * Group industries alphabetically by first letter
77
+ *
78
+ * @param industries - Array of industries to group
79
+ * @returns Record of industries grouped by first letter
80
+ *
81
+ * @example
82
+ * const grouped = groupIndustriesAlphabetically(industries);
83
+ * // { 'A': [...], 'B': [...], ... }
84
+ */
85
+ export declare const groupIndustriesAlphabetically: <T extends BaseIndustry>(industries: readonly T[]) => Record<string, T[]>;
86
+ /**
87
+ * Get industries that don't belong to any sector
88
+ *
89
+ * @param industries - Array of industries to filter
90
+ * @returns Array of industries without sector
91
+ *
92
+ * @example
93
+ * const orphaned = getIndustriesWithoutSector(industries);
94
+ */
95
+ export declare const getIndustriesWithoutSector: <T extends BaseIndustry>(industries: readonly T[]) => T[];
96
+ /**
97
+ * Get industries that belong to a sector
98
+ *
99
+ * @param industries - Array of industries to filter
100
+ * @returns Array of industries with sector
101
+ *
102
+ * @example
103
+ * const sectored = getIndustriesWithSector(industries);
104
+ */
105
+ export declare const getIndustriesWithSector: <T extends BaseIndustry>(industries: readonly T[]) => T[];
106
+ /**
107
+ * Count industries by sector
108
+ *
109
+ * @param industries - Array of industries to count
110
+ * @returns Record of sector UUIDs to industry counts
111
+ *
112
+ * @example
113
+ * const counts = countIndustriesBySector(industries);
114
+ * // { 'sector-123': 5, 'no-sector': 3 }
115
+ */
116
+ export declare const countIndustriesBySector: <T extends BaseIndustry>(industries: readonly T[]) => Record<string, number>;
117
+ /**
118
+ * Check if an industry belongs to a specific sector
119
+ *
120
+ * @param industry - Industry to check
121
+ * @param sectorUuid - UUID of the sector
122
+ * @returns True if industry belongs to sector
123
+ *
124
+ * @example
125
+ * const belongsToSector = isIndustryInSector(industry, 'sector-123');
126
+ */
127
+ export declare const isIndustryInSector: <T extends BaseIndustry>(industry: T, sectorUuid: string) => boolean;
128
+ //# sourceMappingURL=industry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"industry.d.ts","sourceRoot":"","sources":["../src/industry.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS,YAAY,EACzD,YAAY,SAAS,CAAC,EAAE,EACxB,YAAW,KAAK,GAAG,MAAc,KAChC,CAAC,EAGH,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,GAAI,CAAC,SAAS,YAAY,EAC3D,YAAY,SAAS,CAAC,EAAE,EACxB,YAAY,MAAM,KACjB,CAAC,EAEH,C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M,KACjB,OAEF,CAAC"}
@@ -0,0 +1,152 @@
1
+ import { sortByStringField, filterByTextSearch, findByStringField, extractAndSortField, groupByFirstLetter, } from './collections';
2
+ import { NO_SECTOR_KEY } from '@cranberry-money/shared-constants';
3
+ /**
4
+ * Sort industries by name
5
+ *
6
+ * @param industries - Array of industries to sort
7
+ * @param direction - Sort direction ('asc' or 'desc')
8
+ * @returns Sorted array of industries
9
+ *
10
+ * @example
11
+ * const sorted = sortIndustriesByName(industries, 'asc');
12
+ */
13
+ export const sortIndustriesByName = (industries, direction = 'asc') => {
14
+ const sorted = sortByStringField([...industries], 'name');
15
+ return direction === 'asc' ? sorted : sorted.reverse();
16
+ };
17
+ /**
18
+ * Filter industries by name (case-insensitive search)
19
+ *
20
+ * @param industries - Array of industries to filter
21
+ * @param searchTerm - Search term to filter by
22
+ * @returns Filtered array of industries
23
+ *
24
+ * @example
25
+ * const filtered = filterIndustriesByName(industries, 'tech');
26
+ */
27
+ export const filterIndustriesByName = (industries, searchTerm) => {
28
+ return filterByTextSearch([...industries], 'name', searchTerm);
29
+ };
30
+ /**
31
+ * Filter industries by sector
32
+ *
33
+ * @param industries - Array of industries to filter
34
+ * @param sectorUuid - UUID of the sector to filter by
35
+ * @returns Filtered array of industries
36
+ *
37
+ * @example
38
+ * const filtered = filterIndustriesBySector(industries, 'sector-123');
39
+ */
40
+ export const filterIndustriesBySector = (industries, sectorUuid) => {
41
+ return industries.filter((industry) => industry.sector === sectorUuid);
42
+ };
43
+ /**
44
+ * Find industry by exact name match
45
+ *
46
+ * @param industries - Array of industries to search
47
+ * @param name - Exact name to find
48
+ * @returns Found industry or undefined
49
+ *
50
+ * @example
51
+ * const industry = findIndustryByName(industries, 'Technology');
52
+ */
53
+ export const findIndustryByName = (industries, name) => {
54
+ return findByStringField([...industries], 'name', name);
55
+ };
56
+ /**
57
+ * Get sorted list of industry names
58
+ *
59
+ * @param industries - Array of industries
60
+ * @returns Sorted array of industry names
61
+ *
62
+ * @example
63
+ * const names = getIndustryNames(industries);
64
+ * // ['Automotive', 'Banking', 'Technology', ...]
65
+ */
66
+ export const getIndustryNames = (industries) => {
67
+ return extractAndSortField([...industries], 'name');
68
+ };
69
+ /**
70
+ * Group industries by sector
71
+ *
72
+ * @param industries - Array of industries to group
73
+ * @returns Record of industries grouped by sector UUID
74
+ *
75
+ * @example
76
+ * const grouped = groupIndustriesBySector(industries);
77
+ * // { 'sector-123': [...], 'no-sector': [...] }
78
+ */
79
+ export const groupIndustriesBySector = (industries) => {
80
+ return industries.reduce((groups, industry) => {
81
+ const sectorKey = industry.sector || NO_SECTOR_KEY;
82
+ if (!groups[sectorKey]) {
83
+ groups[sectorKey] = [];
84
+ }
85
+ groups[sectorKey].push(industry);
86
+ return groups;
87
+ }, {});
88
+ };
89
+ /**
90
+ * Group industries alphabetically by first letter
91
+ *
92
+ * @param industries - Array of industries to group
93
+ * @returns Record of industries grouped by first letter
94
+ *
95
+ * @example
96
+ * const grouped = groupIndustriesAlphabetically(industries);
97
+ * // { 'A': [...], 'B': [...], ... }
98
+ */
99
+ export const groupIndustriesAlphabetically = (industries) => {
100
+ return groupByFirstLetter([...industries], 'name');
101
+ };
102
+ /**
103
+ * Get industries that don't belong to any sector
104
+ *
105
+ * @param industries - Array of industries to filter
106
+ * @returns Array of industries without sector
107
+ *
108
+ * @example
109
+ * const orphaned = getIndustriesWithoutSector(industries);
110
+ */
111
+ export const getIndustriesWithoutSector = (industries) => {
112
+ return industries.filter((industry) => !industry.sector);
113
+ };
114
+ /**
115
+ * Get industries that belong to a sector
116
+ *
117
+ * @param industries - Array of industries to filter
118
+ * @returns Array of industries with sector
119
+ *
120
+ * @example
121
+ * const sectored = getIndustriesWithSector(industries);
122
+ */
123
+ export const getIndustriesWithSector = (industries) => {
124
+ return industries.filter((industry) => industry.sector);
125
+ };
126
+ /**
127
+ * Count industries by sector
128
+ *
129
+ * @param industries - Array of industries to count
130
+ * @returns Record of sector UUIDs to industry counts
131
+ *
132
+ * @example
133
+ * const counts = countIndustriesBySector(industries);
134
+ * // { 'sector-123': 5, 'no-sector': 3 }
135
+ */
136
+ export const countIndustriesBySector = (industries) => {
137
+ const groups = groupIndustriesBySector(industries);
138
+ return Object.fromEntries(Object.entries(groups).map(([sector, industryList]) => [sector, industryList.length]));
139
+ };
140
+ /**
141
+ * Check if an industry belongs to a specific sector
142
+ *
143
+ * @param industry - Industry to check
144
+ * @param sectorUuid - UUID of the sector
145
+ * @returns True if industry belongs to sector
146
+ *
147
+ * @example
148
+ * const belongsToSector = isIndustryInSector(industry, 'sector-123');
149
+ */
150
+ export const isIndustryInSector = (industry, sectorUuid) => {
151
+ return industry.sector === sectorUuid;
152
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cranberry-money/shared-utils",
3
- "version": "8.9.0",
3
+ "version": "8.11.0",
4
4
  "description": "Shared utility functions for MyPortfolio platform",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",