From 45171cfc94b342787286009b0360d95c0c0d6aab Mon Sep 17 00:00:00 2001 From: Erwan Leroy Date: Fri, 20 Sep 2024 15:55:27 -0700 Subject: [PATCH 1/2] #78 and #72 Hide default params when showDefaults is False and the values are equivalent to the default --- src/lib/sveltekit-search-params.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib/sveltekit-search-params.ts b/src/lib/sveltekit-search-params.ts index b628bcb..f0f3a39 100644 --- a/src/lib/sveltekit-search-params.ts +++ b/src/lib/sveltekit-search-params.ts @@ -298,6 +298,12 @@ 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); @@ -411,6 +417,8 @@ export function queryParam( const newValue = encode(value); if (newValue == undefined) { query.delete(name); + } else if (!showDefaults && newValue === encode(defaultValue)) { + query.delete(name) } else { query.set(name, newValue); } From 9591a72cdeb94e899759e359c2e3f3942676858a Mon Sep 17 00:00:00 2001 From: Erwan Leroy Date: Fri, 20 Sep 2024 16:01:04 -0700 Subject: [PATCH 2/2] Run pretty on the changed file --- src/lib/sveltekit-search-params.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/lib/sveltekit-search-params.ts b/src/lib/sveltekit-search-params.ts index f0f3a39..b683cf4 100644 --- a/src/lib/sveltekit-search-params.ts +++ b/src/lib/sveltekit-search-params.ts @@ -298,12 +298,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 if ( + !showDefaults && + newValue === + fnToCall( + (optionsKey as EncodeAndDecodeOptions) + ?.defaultValue, + ) + ) { query.delete(field as string); } else { query.set(field as string, newValue); @@ -417,8 +420,8 @@ export function queryParam( const newValue = encode(value); if (newValue == undefined) { query.delete(name); - } else if (!showDefaults && newValue === encode(defaultValue)) { - query.delete(name) + } else if (!showDefaults && newValue === encode(defaultValue)) { + query.delete(name); } else { query.set(name, newValue); }