Skip to content

Commit eded16c

Browse files
committed
chore: support 0 as value and remove null from values
1 parent 69f2832 commit eded16c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const buildUrlWithParams = (url, params = {}) => {
2424
const queryParams = Object.keys(params)
2525
.reduce((list, key) => {
2626
const currentValue = params[key]
27-
if (currentValue) {
27+
if (currentValue !== undefined && currentValue !== null) {
2828
return [
2929
...list,
3030
`${encodeURIComponent(key)}=${encodeURIComponent(currentValue)}`

tests/unit/utils.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,13 @@ test.only('undefined values for parameter will be skipped', () => {
3131
}
3232
expect(buildUrlWithParams(url, params)).toBe('http://typeform.com?a=%401')
3333
})
34+
35+
test.only('falsy values should be passed', () => {
36+
const url = 'http://typeform.com'
37+
const params = {
38+
a: '0',
39+
b: 0,
40+
c: null
41+
}
42+
expect(buildUrlWithParams(url, params)).toBe('http://typeform.com?a=0&b=0')
43+
})

0 commit comments

Comments
 (0)