Skip to content

Commit

Permalink
filter undefined from UrlParams Input (#3102)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Smart <tim.smart@arisechurch.com>
  • Loading branch information
tim-smart and Tim Smart authored Jun 27, 2024
1 parent d990544 commit dbd53ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-dots-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/platform": patch
---

filter undefined from UrlParams Input
14 changes: 7 additions & 7 deletions packages/platform/src/UrlParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ export type Input =
* @since 1.0.0
* @category models
*/
export type Coercible = string | number | bigint | boolean
export type Coercible = string | number | bigint | boolean | null | undefined

/**
* @since 1.0.0
* @category constructors
*/
export const fromInput = (input: Input): UrlParams => {
if (Symbol.iterator in input) {
return Arr.fromIterable(input).map(([key, value]) => [key, String(value)])
}
const entries = Symbol.iterator in input ? Arr.fromIterable(input) : Object.entries(input)
const out: Array<readonly [string, string]> = []
for (const [key, value] of Object.entries(input)) {
for (const [key, value] of entries) {
if (Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
out.push([key, String(value[i])])
if (value[i] !== undefined) {
out.push([key, String(value[i])])
}
}
} else {
} else if (value !== undefined) {
out.push([key, String(value)])
}
}
Expand Down

0 comments on commit dbd53ea

Please sign in to comment.