Skip to content

Commit

Permalink
fix: parsed query types should be string only (#139)
Browse files Browse the repository at this point in the history
Co-Authored-By: gaokefei <260480378@qq.com>
  • Loading branch information
pi0 and zhiyuanzmj committed Jul 28, 2023
1 parent 5bb737f commit afaa7a8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ export type QueryValue =
| undefined
| null
| Record<string, any>;

export type QueryObject = Record<string, QueryValue | QueryValue[]>;
export type ParsedQuery = Record<string, string | string[]>;

export function parseQuery(parametersString = ""): QueryObject {
const object: QueryObject = {};
export function parseQuery(parametersString = ""): ParsedQuery {
const object: ParsedQuery = {};
if (parametersString[0] === "?") {
parametersString = parametersString.slice(1);
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { $URL } from "./url";
import { parseURL, stringifyParsedURL } from "./parse";
import { QueryObject, parseQuery, stringifyQuery } from "./query";
import { ParsedQuery, QueryObject, parseQuery, stringifyQuery } from "./query";
import { decode } from "./encoding";

export function isRelative(inputString: string) {
Expand Down Expand Up @@ -132,7 +132,7 @@ export function withQuery(input: string, query: QueryObject): string {
return stringifyParsedURL(parsed);
}

export function getQuery(input: string): QueryObject {
export function getQuery(input: string): ParsedQuery {
return parseQuery(parseURL(input).search);
}

Expand Down

0 comments on commit afaa7a8

Please sign in to comment.