@cranberry-money/shared-utils 8.8.0 → 8.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/document.d.ts +38 -0
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +56 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/industry.d.ts +128 -0
- package/dist/industry.d.ts.map +1 -0
- package/dist/industry.js +152 -0
- package/package.json +1 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate filename for document downloads
|
|
3
|
+
*
|
|
4
|
+
* @param documentType - Type of the document
|
|
5
|
+
* @param documentUuid - UUID of the document
|
|
6
|
+
* @returns Timestamped filename with .pdf extension
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* generateDocumentFilename('agreement', '123-456-789');
|
|
10
|
+
* // returns 'agreement-123-456-789-2024-03-15-10-30-45.pdf'
|
|
11
|
+
*/
|
|
12
|
+
export declare const generateDocumentFilename: (documentType: string, documentUuid: string) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Format document type for display
|
|
15
|
+
*
|
|
16
|
+
* @param documentType - Document type to format
|
|
17
|
+
* @returns Human-readable document type label
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* formatDocumentType('mda'); // returns 'Management Discussion & Analysis'
|
|
21
|
+
* formatDocumentType('soa'); // returns 'Statement of Account'
|
|
22
|
+
* formatDocumentType('agreement'); // returns 'Agreement'
|
|
23
|
+
* formatDocumentType('custom'); // returns 'Custom' (capitalized)
|
|
24
|
+
*/
|
|
25
|
+
export declare const formatDocumentType: (documentType: string) => string;
|
|
26
|
+
/**
|
|
27
|
+
* Format document status for display
|
|
28
|
+
*
|
|
29
|
+
* @param status - Status to format
|
|
30
|
+
* @returns Formatted status string
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* formatDocumentStatus('pending_review'); // returns 'Pending Review'
|
|
34
|
+
* formatDocumentStatus('active'); // returns 'Active'
|
|
35
|
+
* formatDocumentStatus('archived'); // returns 'Archived'
|
|
36
|
+
*/
|
|
37
|
+
export declare const formatDocumentStatus: (status: string) => string;
|
|
38
|
+
//# sourceMappingURL=document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AASA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,wBAAwB,GAAI,cAAc,MAAM,EAAE,cAAc,MAAM,KAAG,MAErF,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,GAAI,cAAc,MAAM,KAAG,MAgBzD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,GAAI,QAAQ,MAAM,KAAG,MAErD,CAAC"}
|
package/dist/document.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { generateTimestampedFilename } from './downloads';
|
|
2
|
+
import { formatStatus } from './formatting';
|
|
3
|
+
import { DOCUMENT_TYPE_MDA, DOCUMENT_TYPE_SOA, DOCUMENT_TYPE_AGREEMENT, DOCUMENT_TYPE_LABELS, } from '@cranberry-money/shared-constants';
|
|
4
|
+
/**
|
|
5
|
+
* Generate filename for document downloads
|
|
6
|
+
*
|
|
7
|
+
* @param documentType - Type of the document
|
|
8
|
+
* @param documentUuid - UUID of the document
|
|
9
|
+
* @returns Timestamped filename with .pdf extension
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* generateDocumentFilename('agreement', '123-456-789');
|
|
13
|
+
* // returns 'agreement-123-456-789-2024-03-15-10-30-45.pdf'
|
|
14
|
+
*/
|
|
15
|
+
export const generateDocumentFilename = (documentType, documentUuid) => {
|
|
16
|
+
return generateTimestampedFilename(`${documentType}-${documentUuid}`, 'pdf');
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Format document type for display
|
|
20
|
+
*
|
|
21
|
+
* @param documentType - Document type to format
|
|
22
|
+
* @returns Human-readable document type label
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* formatDocumentType('mda'); // returns 'Management Discussion & Analysis'
|
|
26
|
+
* formatDocumentType('soa'); // returns 'Statement of Account'
|
|
27
|
+
* formatDocumentType('agreement'); // returns 'Agreement'
|
|
28
|
+
* formatDocumentType('custom'); // returns 'Custom' (capitalized)
|
|
29
|
+
*/
|
|
30
|
+
export const formatDocumentType = (documentType) => {
|
|
31
|
+
const lowerType = documentType.toLowerCase();
|
|
32
|
+
if (lowerType === DOCUMENT_TYPE_MDA && DOCUMENT_TYPE_LABELS[DOCUMENT_TYPE_MDA]) {
|
|
33
|
+
return DOCUMENT_TYPE_LABELS[DOCUMENT_TYPE_MDA];
|
|
34
|
+
}
|
|
35
|
+
if (lowerType === DOCUMENT_TYPE_SOA && DOCUMENT_TYPE_LABELS[DOCUMENT_TYPE_SOA]) {
|
|
36
|
+
return DOCUMENT_TYPE_LABELS[DOCUMENT_TYPE_SOA];
|
|
37
|
+
}
|
|
38
|
+
if (lowerType === DOCUMENT_TYPE_AGREEMENT && DOCUMENT_TYPE_LABELS[DOCUMENT_TYPE_AGREEMENT]) {
|
|
39
|
+
return DOCUMENT_TYPE_LABELS[DOCUMENT_TYPE_AGREEMENT];
|
|
40
|
+
}
|
|
41
|
+
return documentType.charAt(0).toUpperCase() + documentType.slice(1);
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Format document status for display
|
|
45
|
+
*
|
|
46
|
+
* @param status - Status to format
|
|
47
|
+
* @returns Formatted status string
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* formatDocumentStatus('pending_review'); // returns 'Pending Review'
|
|
51
|
+
* formatDocumentStatus('active'); // returns 'Active'
|
|
52
|
+
* formatDocumentStatus('archived'); // returns 'Archived'
|
|
53
|
+
*/
|
|
54
|
+
export const formatDocumentStatus = (status) => {
|
|
55
|
+
return formatStatus(status);
|
|
56
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -27,4 +27,6 @@ export { getStatusColor, getStatusLabel, getWithdrawalTypeLabel, getReasonLabel,
|
|
|
27
27
|
export { findPrimaryTaxResidency, filterTaxResidenciesByCountry, hasTaxResidencyInCountry, getNonExemptedTaxResidencies, type BaseTaxResidency, } from './tax-residency';
|
|
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
|
+
export { generateDocumentFilename, formatDocumentType, formatDocumentStatus, } from './document';
|
|
31
|
+
export { sortIndustriesByName, filterIndustriesByName, filterIndustriesBySector, findIndustryByName, getIndustryNames, groupIndustriesBySector, groupIndustriesAlphabetically, getIndustriesWithoutSector, getIndustriesWithSector, countIndustriesBySector, isIndustryInSector, type BaseIndustry, } from './industry';
|
|
30
32
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,EAC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AClB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,wBAAwB,EACxB,kBAAkB,EAClB,gBAAgB,EAChB,uBAAuB,EACvB,6BAA6B,EAC7B,0BAA0B,EAC1B,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,KAAK,YAAY,GAClB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -54,3 +54,7 @@ export { findPrimaryTaxResidency, filterTaxResidenciesByCountry, hasTaxResidency
|
|
|
54
54
|
export { getCountriesFromExchanges, groupExchangesByCountry, findExchangeByShortName, sortExchangesByName, filterExchangesByCountry, } from './stock-exchange';
|
|
55
55
|
// Sector utilities
|
|
56
56
|
export { sortSectorsByName, filterSectorsByName, findSectorByName, getSectorNames, groupSectorsAlphabetically, sectorExists, findSectorsByPartialName, } from './sector';
|
|
57
|
+
// Document utilities
|
|
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';
|
|
@@ -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,KACj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,EACX,YAAY,MAAM,KACjB,OAEF,CAAC"}
|
package/dist/industry.js
ADDED
|
@@ -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
|
+
};
|