This repository has been archived by the owner on Jul 28, 2024. It is now read-only.
-
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.
support search query in redirect URL (#23)
* support search query in redirect URL * commit file
- Loading branch information
Showing
6 changed files
with
63 additions
and
2 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
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,21 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
|
||
/* | ||
Merges multiple search params into one. | ||
It will override according to the order of the search params | ||
Examples: | ||
- mergeSearchParams('?a=1', '?b=2') => 'a=1&b=2' | ||
- mergeSearchParams('?a=1', '?a=2') => 'a=2' | ||
- mergeSearchParams('?a=1', '?a=2', '?b=3') => 'a=2&b=3' | ||
*/ | ||
export const mergeSearchParams = (...searchParams: string[]): string => { | ||
const res = searchParams.reduce((acc, curr) => { | ||
const currParams = new URLSearchParams(curr); | ||
currParams.forEach((value, key) => { | ||
acc.set(key, value); | ||
}); | ||
return acc; | ||
}, new URLSearchParams()); | ||
|
||
return res.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
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,15 @@ | ||
import { mergeSearchParams } from '../../src/server/utils'; | ||
|
||
describe('utils', () => { | ||
describe('mergeSearchParams', () => { | ||
it('should merge search params', () => { | ||
const searchParams = mergeSearchParams('a=1&b=2', 'c=3&d=4'); | ||
expect(searchParams).toBe('a=1&b=2&c=3&d=4'); | ||
}); | ||
|
||
it('should merge search params with duplicate keys', () => { | ||
const searchParams = mergeSearchParams('a=1&b=2', 'a=3&d=4'); | ||
expect(searchParams).toBe('a=3&b=2&d=4'); | ||
}); | ||
}); | ||
}); |