File tree 1 file changed +46
-0
lines changed
1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ type Query =
2
+ | {
3
+ id : string ;
4
+ type : "text" ;
5
+ by : {
6
+ line : string | RegExp ;
7
+ } ;
8
+ }
9
+ | {
10
+ id : string ;
11
+ type : "text" ;
12
+ by : {
13
+ word : string | RegExp ;
14
+ } ;
15
+ }
16
+ | {
17
+ id : string ;
18
+ type : "window" ;
19
+ by : {
20
+ title : string | RegExp ;
21
+ } ;
22
+ } ;
23
+
24
+ export type TextQuery = Extract < Query , { type : "text" } > ;
25
+
26
+ export type WordQuery = Extract < TextQuery , { by : { word : string | RegExp } } > ;
27
+ export type LineQuery = Extract < TextQuery , { by : { line : string | RegExp } } > ;
28
+
29
+ export type WindowQuery = Extract < Query , { type : "window" } > ;
30
+
31
+ export const isWordQuery = ( possibleQuery : any ) : possibleQuery is WordQuery => {
32
+ return possibleQuery ?. type === "text" && possibleQuery ?. by ?. word != null ;
33
+ } ;
34
+ export const isLineQuery = ( possibleQuery : any ) : possibleQuery is LineQuery => {
35
+ return possibleQuery ?. type === "text" && possibleQuery ?. by ?. line != null ;
36
+ } ;
37
+
38
+ export const isTextQuery = ( possibleQuery : any ) : possibleQuery is TextQuery => {
39
+ return possibleQuery ?. type === "text" ;
40
+ } ;
41
+
42
+ export const isWindowQuery = (
43
+ possibleQuery : any
44
+ ) : possibleQuery is WindowQuery => {
45
+ return possibleQuery ?. type === "window" ;
46
+ } ;
You can’t perform that action at this time.
0 commit comments