-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from Automattic/fix/hovercards-issues
Fix: URL params & error msg
- Loading branch information
Showing
3 changed files
with
30 additions
and
8 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
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,16 @@ | ||
/** | ||
* Adds or updates a query parameter to the given URL. | ||
* | ||
* @param {string} url - The URL to which the query parameter will be added. | ||
* @param {string} key - The query parameter key to add or update. | ||
* @param {string} value - The value of the query parameter to add or update. | ||
* @return {string} - The updated URL with the new or updated query parameter, or an empty string if the URL is invalid. | ||
*/ | ||
export default function addQueryArg( url: string, key: string, value: string ): string { | ||
const [ baseUrl, queryStr ] = url.split( '?' ); | ||
const queryParams = new URLSearchParams( queryStr || '' ); | ||
|
||
queryParams.set( key, value ); | ||
|
||
return `${ baseUrl }?${ queryParams.toString() }`; | ||
} |
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