-
-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy pathsearchable.ts
33 lines (32 loc) · 1.08 KB
/
searchable.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 URI from '@theia/core/lib/common/uri';
export interface Searchable<T, O extends Searchable.Options> {
search(options: O): Promise<T[]>;
}
export namespace Searchable {
export interface Options {
/**
* Defaults to empty an empty string.
*/
readonly query?: string;
}
export namespace UriParser {
/**
* Parses the `URI#fragment` into a query term.
*/
export function parseQuery(uri: URI): { query: string } {
return { query: uri.fragment };
}
/**
* Splits the `URI#path#toString` on the `/` POSIX separator into decoded segments. The first, empty segment representing the root is omitted.
* Examples:
* - `/` -> `['']`
* - `/All` -> `['All']`
* - `/All/Device%20Control` -> `['All', 'Device Control']`
* - `/All/Display` -> `['All', 'Display']`
* - `/Updatable/Signal%20Input%2FOutput` -> `['Updatable', 'Signal Input', 'Output']` (**caveat**!)
*/
export function normalizedSegmentsOf(uri: URI): string[] {
return uri.path.toString().split('/').slice(1).map(decodeURIComponent);
}
}
}