-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(no ticket): added function for building query params, applied pr…
… comments
- Loading branch information
1 parent
4518d96
commit 17a8c8d
Showing
2 changed files
with
44 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export function buildQueryFromArray(paramName: string, arrayToBuildFrom: string[], maxSize?: number): string { | ||
if (arrayToBuildFrom.length <= 0) { | ||
throw new Error('Tried to work with an unsupported array size.'); | ||
} | ||
|
||
if (maxSize && maxSize >= 1) { | ||
arrayToBuildFrom = arrayToBuildFrom.slice(0, maxSize - 1); | ||
} | ||
|
||
if (arrayToBuildFrom.length > 1) { | ||
let query = `${arrayToBuildFrom[0]}&${paramName}`; | ||
arrayToBuildFrom = arrayToBuildFrom.slice(1); | ||
query += arrayToBuildFrom.join(`&${paramName}=`); | ||
|
||
return query; | ||
} else { | ||
return arrayToBuildFrom[0]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters