Skip to content

Commit

Permalink
fix: params: exclude ''
Browse files Browse the repository at this point in the history
  • Loading branch information
mxlje committed Feb 21, 2022
1 parent 60b4dd0 commit 23f271a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/api/autocomplete/params.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Params, createQuery } from './params'

test('paramsToQuery excludes empty fields', () => {
test('createQuery excludes empty fields', () => {
const params: Params = {
lang: 'de',
layers: undefined,
sources: undefined
sources: []
}

expect(createQuery('ge-abcabccbacbacbac', 'berlin', params)).toStrictEqual({
Expand Down
4 changes: 2 additions & 2 deletions src/api/autocomplete/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ export const createQuery = (apiKey: string, text: string, params: Params = {}):
'boundary.rect.max_lon': params.boundary?.rect?.maxLon?.toString()
}

// don’t return empty values (null & undefined) as to not have ?size=undefined in the actual URL query
return Object.fromEntries(Object.entries(q).filter(([_, v]) => v != null)) as Record<string, string>
// don’t return empty values (null, undefined, '') as to not have ?size=undefined or empty values in the actual URL query
return Object.fromEntries(Object.entries(q).filter(([_, v]) => v != null && v !== '')) as Record<string, string>
}

0 comments on commit 23f271a

Please sign in to comment.