Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#78 and #72 Hide default params when showDefaults is False and the va… #112

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/lib/sveltekit-search-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,15 @@ export function queryParameters<
const newValue = fnToCall((value as any)[field]);
if (newValue == undefined) {
query.delete(field as string);
} else if (
!showDefaults &&
newValue ===
fnToCall(
(optionsKey as EncodeAndDecodeOptions)
?.defaultValue,
)
) {
query.delete(field as string);
} else {
query.set(field as string, newValue);
}
Expand Down Expand Up @@ -411,6 +420,8 @@ export function queryParam<T = string>(
const newValue = encode(value);
if (newValue == undefined) {
query.delete(name);
} else if (!showDefaults && newValue === encode(defaultValue)) {
query.delete(name);
} else {
query.set(name, newValue);
}
Expand Down