Skip to content
Snippets Groups Projects
Commit 6c2ed295 authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt :koala:
Browse files

refactor: externalize query sanitizer

parent 3fe33c4c
No related branches found
No related tags found
No related merge requests found
...@@ -403,17 +403,21 @@ export function humanJoin(iterable: Iterable<string>, glue: string, lastGlue: st ...@@ -403,17 +403,21 @@ export function humanJoin(iterable: Iterable<string>, glue: string, lastGlue: st
return `${array.join(glue)}${lastGlue}${lastValue}` return `${array.join(glue)}${lastGlue}${lastValue}`
} }
export function toQuery(
query: Record<string, string | number | null | undefined>,
): URLSearchParams {
const _query: Record<string, string> = {}
for (const [key, value] of Object.entries(query)) {
if (value === null || value === undefined) continue
_query[key] = value.toString()
}
return new URLSearchParams(_query)
}
export function useQuery( export function useQuery(
query: MaybeRefOrGetter<Record<string, string | number | null | undefined>>, query: MaybeRefOrGetter<Record<string, string | number | null | undefined>>,
) { ) {
return computed(() => { return computed(() => toQuery(toValue(query)))
const _query: Record<string, string> = {}
for (const [key, value] of Object.entries(toValue(query))) {
if (value === null || value === undefined) continue
_query[key] = value.toString()
}
return new URLSearchParams(_query)
})
} }
export async function fromAsync<T>(iterable: AsyncIterable<T>): Promise<T[]> { export async function fromAsync<T>(iterable: AsyncIterable<T>): Promise<T[]> {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment