-
Notifications
You must be signed in to change notification settings - Fork 9
/
common.ts
33 lines (26 loc) · 852 Bytes
/
common.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
30
31
32
33
import Settings, { FilterFunction } from '../settings';
import { Errno } from '../types';
export function isFatalError(settings: Settings, error: Errno): boolean {
if (settings.errorFilter === null) {
return true;
}
return !settings.errorFilter(error);
}
export function isAppliedFilter<T>(filter: FilterFunction<T> | null, value: T): boolean {
return filter === null || filter(value);
}
export function replacePathSegmentSeparator(filepath: string, separator: string): string {
return filepath.split(/[/\\]/).join(separator);
}
export function joinPathSegments(a: string, b: string, separator: string): string {
if (a === '') {
return b;
}
/**
* The correct handling of cases when the first segment is a root (`/`, `C:/`) or UNC path (`//?/C:/`).
*/
if (a.endsWith(separator)) {
return a + b;
}
return a + separator + b;
}