convertParameterToObject

说明

提取 URL 中的 GET 请求参数

源码

用法

convertParameterToObject.test.ts
1
import { convertURLParameterToObject } from "../../utility/others/convertURLParameterToObject";
2
3
describe('convertURLParameterToObject', () => {
4
test('convertURLParameterToObject should return the truthy key-value-pair when received a URL string', () => {
5
const received = [
6
'https://github.com/ddzy?username=duan&age=20&token=kslgjadg',
7
'https://github.com/ddzy??username=duan&&age=20',
8
'https://github.com/ddzy/username=duan?age=20&token=askndg',
9
'https://github.com/ddzy&username=duan?age=20?token=askndg',
10
];
11
const expected = [
12
{
13
username: 'duan',
14
age: '20',
15
token: 'kslgjadg',
16
},
17
{
18
username: 'duan',
19
age: '20',
20
},
21
{
22
age: '20',
23
token: 'askndg',
24
},
25
{
26
age: '20',
27
token: 'askndg',
28
},
29
];
30
31
for (const [i, v] of received.entries()) {
32
expect(convertURLParameterToObject(v)).toEqual(expected[i]);
33
}
34
});
35
});
Copied!
最近更新 1yr ago
复制链接