Skip to content

Commit

Permalink
chore: refactoring to decompose if statements
Browse files Browse the repository at this point in the history
  • Loading branch information
soartec-lab committed Aug 31, 2024
1 parent 77393ac commit 36b15bb
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions packages/fetch/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,10 @@ export const generateRequestFunction = (

const explodeArrayImplementation =
explodeParameters.length > 0
? ` else if (value instanceof Array) {
? `if (value instanceof Array) {
value.forEach((v) => normalizedParams.append(key, v === null ? 'null' : v.toString()));
}`
: '';

const normalParamsImplementation =
explodeParameters.length !== parameters.length
? ` else if (value !== undefined) {
normalizedParams.append(key, value.toString());
}`
}
`
: '';

const getUrlFnImplementation = `export const ${getUrlFnName} = (${getUrlFnProps}) => {
Expand All @@ -83,9 +77,10 @@ ${
? ` const normalizedParams = new URLSearchParams();
Object.entries(params || {}).forEach(([key, value]) => {
if (value === null) {
normalizedParams.append(key, 'null');
}${explodeArrayImplementation}${normalParamsImplementation}
${explodeArrayImplementation}
if (value !== undefined) {
normalizedParams.append(key, value === null ? 'null' : value.toString())
}
});`
: ''
}
Expand Down

0 comments on commit 36b15bb

Please sign in to comment.