|
1
|
import { Node, NodeType } from "./types" |
|
2
|
|
|
3
|
/** |
|
4
|
* Checks if a node is of a certain type. |
|
5
|
*/ |
|
6
|
export function isNodeType<NType extends NodeType, R = Node<NType>>( |
|
7
|
node: Node<any>, |
|
8
|
type: NType |
|
9
|
): node is R { |
|
10
|
return node.type === type |
|
11
|
} |
|
12
|
|
|
13
|
/** |
|
14
|
* Encodes an object into a query string. |
|
15
|
*/ |
|
16
|
export function encodeQuery(obj: any): string { |
|
17
|
if (!obj) { |
|
18
|
return "" |
|
19
|
} |
|
20
|
|
|
21
|
return Object.entries(obj) |
|
22
|
.map(([k, v]) => k && v && `${k}=${encodeURIComponent(v as any)}`) |
|
23
|
.filter(Boolean) |
|
24
|
.join("&") |
|
25
|
} |