@cranberry-money/shared-utils 8.7.0 → 8.9.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/sector.d.ts +124 -0
- package/dist/sector.d.ts.map +1 -0
- package/dist/sector.js +134 -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
|
@@ -26,4 +26,6 @@ export { isValidTemplateSelection, validatePortfolioSelection, type PortfolioSel
|
|
|
26
26
|
export { getStatusColor, getStatusLabel, getWithdrawalTypeLabel, getReasonLabel, getLiquidationStatusColor, getLiquidationStatusLabel, type WithdrawalStatus, type WithdrawalType, type WithdrawalReason, type LiquidationStatus, } from './withdrawal-status';
|
|
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
|
+
export { sortSectorsByName, filterSectorsByName, findSectorByName, getSectorNames, groupSectorsAlphabetically, sectorExists, findSectorsByPartialName, type BaseSector, } from './sector';
|
|
30
|
+
export { generateDocumentFilename, formatDocumentType, formatDocumentStatus, } from './document';
|
|
29
31
|
//# 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,EACnB,wBAAwB,EACxB,yBAAyB,EAC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AGnB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAGpD,OAAO,EACL,uBAAuB,EACvB,2BAA2B,EAC3B,yBAAyB,EACzB,2BAA2B,EAC3B,YAAY,GACb,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EAChB,uBAAuB,EACvB,KAAK,qBAAqB,GAC3B,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC1B,KAAK,4BAA4B,EACjC,KAAK,uBAAuB,GAC7B,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,cAAc,EACd,cAAc,EACd,sBAAsB,EACtB,cAAc,EACd,yBAAyB,EACzB,yBAAyB,EACzB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,GACvB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,uBAAuB,EACvB,6BAA6B,EAC7B,wBAAwB,EACxB,4BAA4B,EAC5B,KAAK,gBAAgB,GACtB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,yBAAyB,EACzB,uBAAuB,EACvB,uBAAuB,EACvB,mBAAmB,EACnB,wBAAwB,EACxB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,aAAa,GACnB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,0BAA0B,EAC1B,YAAY,EACZ,wBAAwB,EACxB,KAAK,UAAU,GAChB,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -52,3 +52,7 @@ export { getStatusColor, getStatusLabel, getWithdrawalTypeLabel, getReasonLabel,
|
|
|
52
52
|
export { findPrimaryTaxResidency, filterTaxResidenciesByCountry, hasTaxResidencyInCountry, getNonExemptedTaxResidencies, } from './tax-residency';
|
|
53
53
|
// Stock exchange utilities
|
|
54
54
|
export { getCountriesFromExchanges, groupExchangesByCountry, findExchangeByShortName, sortExchangesByName, filterExchangesByCountry, } from './stock-exchange';
|
|
55
|
+
// Sector utilities
|
|
56
|
+
export { sortSectorsByName, filterSectorsByName, findSectorByName, getSectorNames, groupSectorsAlphabetically, sectorExists, findSectorsByPartialName, } from './sector';
|
|
57
|
+
// Document utilities
|
|
58
|
+
export { generateDocumentFilename, formatDocumentType, formatDocumentStatus, } from './document';
|
package/dist/sector.d.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
export interface BaseSector {
|
|
2
|
+
readonly uuid: string;
|
|
3
|
+
readonly name: string;
|
|
4
|
+
}
|
|
5
|
+
export type { SortDirection } from './stock-exchange';
|
|
6
|
+
/**
|
|
7
|
+
* Sort sectors by name
|
|
8
|
+
*
|
|
9
|
+
* @param sectors - List of sectors
|
|
10
|
+
* @param direction - Sort direction ('asc' or 'desc')
|
|
11
|
+
* @returns New sorted array of sectors
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const sectors = [
|
|
15
|
+
* { uuid: '1', name: 'Technology' },
|
|
16
|
+
* { uuid: '2', name: 'Healthcare' }
|
|
17
|
+
* ];
|
|
18
|
+
* sortSectorsByName(sectors); // returns [Healthcare, Technology]
|
|
19
|
+
* sortSectorsByName(sectors, 'desc'); // returns [Technology, Healthcare]
|
|
20
|
+
*/
|
|
21
|
+
export declare const sortSectorsByName: <T extends BaseSector>(sectors: readonly T[], direction?: "asc" | "desc") => T[];
|
|
22
|
+
/**
|
|
23
|
+
* Filter sectors by name (case-insensitive search)
|
|
24
|
+
*
|
|
25
|
+
* @param sectors - List of sectors
|
|
26
|
+
* @param searchTerm - Search term to filter by
|
|
27
|
+
* @returns Filtered array of sectors
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const sectors = [
|
|
31
|
+
* { uuid: '1', name: 'Technology' },
|
|
32
|
+
* { uuid: '2', name: 'Healthcare' },
|
|
33
|
+
* { uuid: '3', name: 'Financial Services' }
|
|
34
|
+
* ];
|
|
35
|
+
* filterSectorsByName(sectors, 'tech'); // returns [Technology]
|
|
36
|
+
* filterSectorsByName(sectors, 'care'); // returns [Healthcare]
|
|
37
|
+
*/
|
|
38
|
+
export declare const filterSectorsByName: <T extends BaseSector>(sectors: readonly T[], searchTerm: string) => T[];
|
|
39
|
+
/**
|
|
40
|
+
* Find sector by exact name match
|
|
41
|
+
*
|
|
42
|
+
* @param sectors - List of sectors
|
|
43
|
+
* @param name - Exact name to search for
|
|
44
|
+
* @returns The sector if found, undefined otherwise
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const sectors = [
|
|
48
|
+
* { uuid: '1', name: 'Technology' },
|
|
49
|
+
* { uuid: '2', name: 'Healthcare' }
|
|
50
|
+
* ];
|
|
51
|
+
* findSectorByName(sectors, 'Technology'); // returns Technology sector
|
|
52
|
+
* findSectorByName(sectors, 'Tech'); // returns undefined
|
|
53
|
+
*/
|
|
54
|
+
export declare const findSectorByName: <T extends BaseSector>(sectors: readonly T[], name: string) => T | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Get sorted list of sector names
|
|
57
|
+
*
|
|
58
|
+
* @param sectors - List of sectors
|
|
59
|
+
* @returns Sorted array of sector names
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* const sectors = [
|
|
63
|
+
* { uuid: '1', name: 'Technology' },
|
|
64
|
+
* { uuid: '2', name: 'Healthcare' },
|
|
65
|
+
* { uuid: '3', name: 'Energy' }
|
|
66
|
+
* ];
|
|
67
|
+
* getSectorNames(sectors); // returns ['Energy', 'Healthcare', 'Technology']
|
|
68
|
+
*/
|
|
69
|
+
export declare const getSectorNames: <T extends BaseSector>(sectors: readonly T[]) => string[];
|
|
70
|
+
/**
|
|
71
|
+
* Group sectors alphabetically by first letter
|
|
72
|
+
*
|
|
73
|
+
* @param sectors - List of sectors
|
|
74
|
+
* @returns Object with first letters as keys and sectors as values
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* const sectors = [
|
|
78
|
+
* { uuid: '1', name: 'Technology' },
|
|
79
|
+
* { uuid: '2', name: 'Healthcare' },
|
|
80
|
+
* { uuid: '3', name: 'Energy' },
|
|
81
|
+
* { uuid: '4', name: 'Telecommunications' }
|
|
82
|
+
* ];
|
|
83
|
+
* groupSectorsAlphabetically(sectors);
|
|
84
|
+
* // returns {
|
|
85
|
+
* // 'E': [Energy],
|
|
86
|
+
* // 'H': [Healthcare],
|
|
87
|
+
* // 'T': [Technology, Telecommunications]
|
|
88
|
+
* // }
|
|
89
|
+
*/
|
|
90
|
+
export declare const groupSectorsAlphabetically: <T extends BaseSector>(sectors: readonly T[]) => Record<string, T[]>;
|
|
91
|
+
/**
|
|
92
|
+
* Check if a sector name exists in the list
|
|
93
|
+
*
|
|
94
|
+
* @param sectors - List of sectors
|
|
95
|
+
* @param sectorName - Name to check for existence
|
|
96
|
+
* @returns True if sector exists, false otherwise
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* const sectors = [
|
|
100
|
+
* { uuid: '1', name: 'Technology' },
|
|
101
|
+
* { uuid: '2', name: 'Healthcare' }
|
|
102
|
+
* ];
|
|
103
|
+
* sectorExists(sectors, 'Technology'); // returns true
|
|
104
|
+
* sectorExists(sectors, 'Manufacturing'); // returns false
|
|
105
|
+
*/
|
|
106
|
+
export declare const sectorExists: <T extends BaseSector>(sectors: readonly T[], sectorName: string) => boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Get sectors by partial name match (fuzzy search)
|
|
109
|
+
*
|
|
110
|
+
* @param sectors - List of sectors
|
|
111
|
+
* @param partialName - Partial name to search for
|
|
112
|
+
* @returns Array of matching sectors
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* const sectors = [
|
|
116
|
+
* { uuid: '1', name: 'Technology' },
|
|
117
|
+
* { uuid: '2', name: 'Biotechnology' },
|
|
118
|
+
* { uuid: '3', name: 'Healthcare Technology' }
|
|
119
|
+
* ];
|
|
120
|
+
* findSectorsByPartialName(sectors, 'tech');
|
|
121
|
+
* // returns [Technology, Biotechnology, Healthcare Technology]
|
|
122
|
+
*/
|
|
123
|
+
export declare const findSectorsByPartialName: <T extends BaseSector>(sectors: readonly T[], partialName: string) => T[];
|
|
124
|
+
//# sourceMappingURL=sector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sector.d.ts","sourceRoot":"","sources":["../src/sector.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAGD,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,UAAU,EACpD,SAAS,SAAS,CAAC,EAAE,EACrB,YAAW,KAAK,GAAG,MAAc,KAChC,CAAC,EAGH,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,UAAU,EACtD,SAAS,SAAS,CAAC,EAAE,EACrB,YAAY,MAAM,KACjB,CAAC,EAEH,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,UAAU,EACnD,SAAS,SAAS,CAAC,EAAE,EACrB,MAAM,MAAM,KACX,CAAC,GAAG,SAEN,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,UAAU,EACjD,SAAS,SAAS,CAAC,EAAE,KACpB,MAAM,EAER,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,0BAA0B,GAAI,CAAC,SAAS,UAAU,EAC7D,SAAS,SAAS,CAAC,EAAE,KACpB,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAEpB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,UAAU,EAC/C,SAAS,SAAS,CAAC,EAAE,EACrB,YAAY,MAAM,KACjB,OAEF,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,wBAAwB,GAAI,CAAC,SAAS,UAAU,EAC3D,SAAS,SAAS,CAAC,EAAE,EACrB,aAAa,MAAM,KAClB,CAAC,EAEH,CAAC"}
|
package/dist/sector.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { sortByStringField, filterByTextSearch, findByStringField, extractAndSortField, groupByFirstLetter, } from './collections';
|
|
2
|
+
/**
|
|
3
|
+
* Sort sectors by name
|
|
4
|
+
*
|
|
5
|
+
* @param sectors - List of sectors
|
|
6
|
+
* @param direction - Sort direction ('asc' or 'desc')
|
|
7
|
+
* @returns New sorted array of sectors
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const sectors = [
|
|
11
|
+
* { uuid: '1', name: 'Technology' },
|
|
12
|
+
* { uuid: '2', name: 'Healthcare' }
|
|
13
|
+
* ];
|
|
14
|
+
* sortSectorsByName(sectors); // returns [Healthcare, Technology]
|
|
15
|
+
* sortSectorsByName(sectors, 'desc'); // returns [Technology, Healthcare]
|
|
16
|
+
*/
|
|
17
|
+
export const sortSectorsByName = (sectors, direction = 'asc') => {
|
|
18
|
+
const sorted = sortByStringField([...sectors], 'name');
|
|
19
|
+
return direction === 'asc' ? sorted : sorted.reverse();
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Filter sectors by name (case-insensitive search)
|
|
23
|
+
*
|
|
24
|
+
* @param sectors - List of sectors
|
|
25
|
+
* @param searchTerm - Search term to filter by
|
|
26
|
+
* @returns Filtered array of sectors
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* const sectors = [
|
|
30
|
+
* { uuid: '1', name: 'Technology' },
|
|
31
|
+
* { uuid: '2', name: 'Healthcare' },
|
|
32
|
+
* { uuid: '3', name: 'Financial Services' }
|
|
33
|
+
* ];
|
|
34
|
+
* filterSectorsByName(sectors, 'tech'); // returns [Technology]
|
|
35
|
+
* filterSectorsByName(sectors, 'care'); // returns [Healthcare]
|
|
36
|
+
*/
|
|
37
|
+
export const filterSectorsByName = (sectors, searchTerm) => {
|
|
38
|
+
return filterByTextSearch([...sectors], 'name', searchTerm);
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Find sector by exact name match
|
|
42
|
+
*
|
|
43
|
+
* @param sectors - List of sectors
|
|
44
|
+
* @param name - Exact name to search for
|
|
45
|
+
* @returns The sector if found, undefined otherwise
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const sectors = [
|
|
49
|
+
* { uuid: '1', name: 'Technology' },
|
|
50
|
+
* { uuid: '2', name: 'Healthcare' }
|
|
51
|
+
* ];
|
|
52
|
+
* findSectorByName(sectors, 'Technology'); // returns Technology sector
|
|
53
|
+
* findSectorByName(sectors, 'Tech'); // returns undefined
|
|
54
|
+
*/
|
|
55
|
+
export const findSectorByName = (sectors, name) => {
|
|
56
|
+
return findByStringField([...sectors], 'name', name);
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Get sorted list of sector names
|
|
60
|
+
*
|
|
61
|
+
* @param sectors - List of sectors
|
|
62
|
+
* @returns Sorted array of sector names
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* const sectors = [
|
|
66
|
+
* { uuid: '1', name: 'Technology' },
|
|
67
|
+
* { uuid: '2', name: 'Healthcare' },
|
|
68
|
+
* { uuid: '3', name: 'Energy' }
|
|
69
|
+
* ];
|
|
70
|
+
* getSectorNames(sectors); // returns ['Energy', 'Healthcare', 'Technology']
|
|
71
|
+
*/
|
|
72
|
+
export const getSectorNames = (sectors) => {
|
|
73
|
+
return extractAndSortField([...sectors], 'name');
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Group sectors alphabetically by first letter
|
|
77
|
+
*
|
|
78
|
+
* @param sectors - List of sectors
|
|
79
|
+
* @returns Object with first letters as keys and sectors as values
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* const sectors = [
|
|
83
|
+
* { uuid: '1', name: 'Technology' },
|
|
84
|
+
* { uuid: '2', name: 'Healthcare' },
|
|
85
|
+
* { uuid: '3', name: 'Energy' },
|
|
86
|
+
* { uuid: '4', name: 'Telecommunications' }
|
|
87
|
+
* ];
|
|
88
|
+
* groupSectorsAlphabetically(sectors);
|
|
89
|
+
* // returns {
|
|
90
|
+
* // 'E': [Energy],
|
|
91
|
+
* // 'H': [Healthcare],
|
|
92
|
+
* // 'T': [Technology, Telecommunications]
|
|
93
|
+
* // }
|
|
94
|
+
*/
|
|
95
|
+
export const groupSectorsAlphabetically = (sectors) => {
|
|
96
|
+
return groupByFirstLetter([...sectors], 'name');
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Check if a sector name exists in the list
|
|
100
|
+
*
|
|
101
|
+
* @param sectors - List of sectors
|
|
102
|
+
* @param sectorName - Name to check for existence
|
|
103
|
+
* @returns True if sector exists, false otherwise
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* const sectors = [
|
|
107
|
+
* { uuid: '1', name: 'Technology' },
|
|
108
|
+
* { uuid: '2', name: 'Healthcare' }
|
|
109
|
+
* ];
|
|
110
|
+
* sectorExists(sectors, 'Technology'); // returns true
|
|
111
|
+
* sectorExists(sectors, 'Manufacturing'); // returns false
|
|
112
|
+
*/
|
|
113
|
+
export const sectorExists = (sectors, sectorName) => {
|
|
114
|
+
return findByStringField([...sectors], 'name', sectorName) !== undefined;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Get sectors by partial name match (fuzzy search)
|
|
118
|
+
*
|
|
119
|
+
* @param sectors - List of sectors
|
|
120
|
+
* @param partialName - Partial name to search for
|
|
121
|
+
* @returns Array of matching sectors
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* const sectors = [
|
|
125
|
+
* { uuid: '1', name: 'Technology' },
|
|
126
|
+
* { uuid: '2', name: 'Biotechnology' },
|
|
127
|
+
* { uuid: '3', name: 'Healthcare Technology' }
|
|
128
|
+
* ];
|
|
129
|
+
* findSectorsByPartialName(sectors, 'tech');
|
|
130
|
+
* // returns [Technology, Biotechnology, Healthcare Technology]
|
|
131
|
+
*/
|
|
132
|
+
export const findSectorsByPartialName = (sectors, partialName) => {
|
|
133
|
+
return filterByTextSearch([...sectors], 'name', partialName);
|
|
134
|
+
};
|