|
13 | 13 | export const hasItemByLetterAndFilter = ( |
14 | 14 | letter: string, |
15 | 15 | array: Array<any>, |
16 | | - key: string = "name", |
| 16 | + key: string = 'name', |
17 | 17 | index?: number, |
18 | 18 | filterText?: string, |
19 | 19 | ): boolean => { |
20 | 20 | return array.some((item) => { |
21 | 21 | if (letter.length !== 1) { |
22 | | - throw new Error("Letter must be a single character."); |
| 22 | + throw new Error('Letter must be a single character.') |
23 | 23 | } |
24 | | - const keyValue: string | null = item[key] || null; |
| 24 | + const keyValue: string | null = item[key] || null |
25 | 25 |
|
26 | 26 | if (!keyValue) { |
27 | | - return false; |
| 27 | + return false |
28 | 28 | } |
29 | 29 |
|
30 | 30 | const checkForLetter = (keyValue: string, index = 0): boolean => { |
31 | | - if (typeof index === "undefined") { |
32 | | - index = 0; |
| 31 | + if (typeof index === 'undefined') { |
| 32 | + index = 0 |
33 | 33 | } |
34 | | - const values = [keyValue, keyValue.toLowerCase()]; |
| 34 | + const values = [keyValue, keyValue.toLowerCase()] |
35 | 35 |
|
36 | | - return values.some((value) => value.charAt(index) === letter); |
37 | | - }; |
| 36 | + return values.some((value) => value.charAt(index) === letter) |
| 37 | + } |
38 | 38 |
|
39 | 39 | const checkForFilterText = (keyValue: string): boolean => { |
40 | 40 | if (!filterText) { |
41 | | - return true; |
| 41 | + return true |
42 | 42 | } |
43 | 43 |
|
44 | | - const filterTextValues = [filterText, filterText.toLowerCase()]; |
| 44 | + const filterTextValues = [filterText, filterText.toLowerCase()] |
45 | 45 |
|
46 | 46 | return filterTextValues.every((filterTextValue) => |
47 | 47 | keyValue.includes(filterTextValue), |
48 | | - ); |
49 | | - }; |
| 48 | + ) |
| 49 | + } |
50 | 50 |
|
51 | | - const hasFilterText = checkForFilterText(keyValue); |
52 | | - const hasLetter = checkForLetter(keyValue, index); |
| 51 | + const hasFilterText = checkForFilterText(keyValue) |
| 52 | + const hasLetter = checkForLetter(keyValue, index) |
53 | 53 |
|
54 | | - const hasValue = hasFilterText && hasLetter ? true : false; |
| 54 | + const hasValue = hasFilterText && hasLetter ? true : false |
55 | 55 |
|
56 | | - return hasValue; |
57 | | - }); |
58 | | -}; |
| 56 | + return hasValue |
| 57 | + }) |
| 58 | +} |
0 commit comments