Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,15 @@ const utils = {
if (!results[2]) {
return '';
}
return decodeURIComponent(results[2].replace(/\+/g, ' '));

const paramValue = decodeURIComponent(results[2].replace(/\+/g, ' '));
if (paramValue === 'null') {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其实就是把string类型的null和undefined,转换为null和undefined,方便在调用接口传参做过滤么

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,省得子产品自己处理了,如果直接返回字符串,子产品的判空会不生效的

return null;
}
if (paramValue === 'undefined') {
return undefined;
}
return paramValue;
},
/**
*
Expand Down
12 changes: 12 additions & 0 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ describe('utils:', () => {
'张三'
);
});
test('getParameterByName()=>null', () => {
assert.strictEqual(
getParameterByName('name', 'http://gitlab.prod.dtstack.cn?name=null'),
null
);
});
test('getParameterByName()=>undefined', () => {
assert.strictEqual(
getParameterByName('name', 'http://gitlab.prod.dtstack.cn?name=undefined'),
undefined
);
});
test('percent(1)=>100%', () => {
assert.strictEqual(percent(1), '100%');
});
Expand Down