-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathutils.ts
29 lines (25 loc) · 987 Bytes
/
utils.ts
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
import specialCodeDictionary from './consts';
import type { TimetableItemResult } from './types';
/** Filter timetable items by their names and labels */
export const keepItem = (item: TimetableItemResult, searchString: string): boolean => {
if (searchString) {
const searchStringInName = item.trainName.toLowerCase().includes(searchString.toLowerCase());
const searchStringInTags = item.labels
? item.labels.join('').toLowerCase().includes(searchString.toLowerCase())
: false;
return searchStringInName || searchStringInTags;
}
return true;
};
export const extractTagCode = (tag?: string | null) => {
if (!tag) {
return 'NO CODE';
}
if (tag in specialCodeDictionary) {
return specialCodeDictionary[tag];
}
const matches = tag.match(/\w+$/);
return matches ? matches[0] : tag;
};
export const timetableHasInvalidItem = (timetableItems: TimetableItemResult[]) =>
timetableItems.some((timetableItem) => timetableItem.invalidReason);