Skip to content

Commit

Permalink
fix: #92 optimize getQueryParameters's return (#93)
Browse files Browse the repository at this point in the history
Co-authored-by: liuyi <[email protected]>
  • Loading branch information
liuxy0551 and liuyi authored Oct 25, 2023
1 parent 1158b6b commit fb6b482
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,17 @@ const utils = {
*/
getQueryParameters(search: string) {
const searchParams = new URLSearchParams(search);
return Object.fromEntries(searchParams.entries());
const paramValue = Object.fromEntries(searchParams.entries());
for (const key in paramValue) {
if (paramValue[key] === 'null') {
(paramValue[key] as any) = null;
}
if (paramValue[key] === 'undefined') {
(paramValue[key] as any) = undefined;
}
}

return paramValue;
},
/**
* 获取图片的Base64格式
Expand Down
4 changes: 2 additions & 2 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ describe('utils:', () => {
expect(getQueryParameters('?a=1&b=2')).toEqual({ a: '1', b: '2' });
expect(getQueryParameters('?a=1&b=undefined')).toEqual({
a: '1',
b: 'undefined',
b: undefined,
});
expect(getQueryParameters('?a=1&b=null')).toEqual({ a: '1', b: 'null' });
expect(getQueryParameters('?a=1&b=null')).toEqual({ a: '1', b: null });
});
});

0 comments on commit fb6b482

Please sign in to comment.