rvx
Version:
A signal based rendering library
47 lines (39 loc) • 983 B
text/typescript
/**
* Represents URL search parameters.
*/
export class Query {
constructor(raw: string, params?: URLSearchParams) {
this.
this.
}
static from(init: QueryInit): Query | undefined {
if (init === undefined) {
return undefined;
}
if (typeof init === "string") {
return new Query(init);
}
const params = new URLSearchParams(init);
return new Query(params.toString(), params);
}
get raw() {
return this.
}
get params(): URLSearchParams {
if (this.
this.
}
return this.
}
}
export type QueryInit = ConstructorParameters<typeof URLSearchParams>[0];
/**
* Format the specified query for use in a URL.
*
* Strings are returned as is.
*/
export function formatQuery(value: QueryInit): string {
return typeof value === "string" ? value : new URLSearchParams(value).toString();
}