-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.js
37 lines (37 loc) · 1.39 KB
/
utilities.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* Checks if a string is meets the CPA code format.
* @param cpaCode - A CPA code.
* @returns - True when the string validates to the CPA code format.
*/
export function _validateCPACodeStringFormat(cpaCode) {
return /^\d{3}$/.test(cpaCode);
}
/**
* Retrieves a category object from a given list.
* @param categoryList - A list of CPA code category objects.
* @param cpaCode - A CPA code.
* @returns - A CPA code category object.
*/
export function _getCodeCategory(categoryList, cpaCode) {
if (!_validateCPACodeStringFormat(cpaCode)) {
return undefined;
}
return categoryList.find((possibleCategory) => {
return (cpaCode >= possibleCategory.cpaCodeMin &&
cpaCode <= possibleCategory.cpaCodeMax);
});
}
/**
* Retrieves a list of CPA code objects that correspond to a given abbreviation.
* @param codeList - A list of CPA code objects.
* @param cpaCodeAbbreviation - A CPA code abbreviation, English or French.
* @returns - A filtered list of CPA code objects.
*/
export function _getCodesByAbbreviation(codeList, cpaCodeAbbreviation) {
const upperCaseCpaCodeAbbreviation = cpaCodeAbbreviation.toUpperCase();
return codeList.filter((possibleCode) => {
return (upperCaseCpaCodeAbbreviation ===
possibleCode.cpaCodeAbbreviationEnglish ||
upperCaseCpaCodeAbbreviation === possibleCode.cpaCodeAbbreviationFrench);
});
}