@@ -5,30 +5,23 @@ interface RequestData {
5
5
type RouteParams = { [ key : string ] : string } | null
6
6
7
7
export class Request {
8
- private query : { [ key : string ] : string } = { }
8
+ private query : RequestData = { }
9
9
private params : RouteParams = null
10
10
11
11
public addQuery ( url : URL ) : void {
12
- const query = url . searchParams
13
-
14
- const paramObject : RequestData = { }
15
-
16
- for ( const [ key , value ] of query . entries ( ) )
17
- paramObject [ key ] = value
18
-
19
- this . query = paramObject
12
+ this . query = Object . fromEntries ( url . searchParams )
20
13
}
21
14
22
15
public get ( element : string ) : string | number | undefined {
23
16
return this . query [ element ]
24
17
}
25
18
26
- public all ( ) : { [ key : string ] : string } {
19
+ public all ( ) : RequestData {
27
20
return this . query
28
21
}
29
22
30
23
public has ( element : string ) : boolean {
31
- return Object . prototype . hasOwnProperty . call ( this . query , element )
24
+ return element in this . query
32
25
}
33
26
34
27
public isEmpty ( ) : boolean {
@@ -41,7 +34,7 @@ export class Request {
41
34
42
35
if ( match ?. groups )
43
36
this . params = match ?. groups
44
- } ;
37
+ }
45
38
46
39
public getParams ( key : string ) : number | string | null {
47
40
return this . params ? ( this . params [ key ] || null ) : null
0 commit comments