-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathconstants.search.ts
64 lines (59 loc) · 1.5 KB
/
constants.search.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
type SearchOperatorsShortForm = '' | '=:' | '@:' | '#:' | '?:' | '~:' | 'is:' | 'after:' | 'before:';
export type SearchOperatorsLongForm =
| 'message:'
| 'author:'
| 'commit:'
| 'file:'
| 'change:'
| 'type:'
| 'date:'
| 'after:'
| 'before:';
export type SearchOperators = SearchOperatorsShortForm | SearchOperatorsLongForm;
export const searchOperators = new Set<string>([
'',
'=:',
'message:',
'@:',
'author:',
'#:',
'commit:',
'?:',
'file:',
'~:',
'change:',
'is:',
'type:',
'date:',
'after:',
'before:',
]);
export const searchOperatorsToLongFormMap = new Map<SearchOperators, SearchOperatorsLongForm>([
['', 'message:'],
['=:', 'message:'],
['message:', 'message:'],
['@:', 'author:'],
['author:', 'author:'],
['#:', 'commit:'],
['commit:', 'commit:'],
['?:', 'file:'],
['file:', 'file:'],
['~:', 'change:'],
['change:', 'change:'],
['is:', 'type:'],
['type:', 'type:'],
['after:', 'after:'],
['before:', 'before:'],
['date:', 'date:'],
]);
export const searchOperationRegex =
/(?:(?<op>=:|message:|@:|author:|#:|commit:|\?:|file:|~:|change:|is:|type:|date:|after:|before:)\s?(?<value>".+?"|\S+}?))|(?<text>\S+)(?!(?:=|message|@|author|#|commit|\?|file|~|change|is|type):)/g;
export const searchOperationHelpRegex =
/(?:^|(\b|\s)*)((=:|message:|@:|author:|#:|commit:|\?:|file:|~:|change:|is:|type:|date:|after:|before:)(?:"[^"]*"?|\w*))(?:$|(\b|\s))/g;
export interface SearchQuery {
query: string;
filter?: boolean;
matchAll?: boolean;
matchCase?: boolean;
matchRegex?: boolean;
}