Skip to content

fix(isImg): 修复创建<LazyIcon>组件时,使用的isImg方法未检测图片资源是否为base64编码的问题 #301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion packages/pro-layout/src/utils/isImg/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// source by https://github.com/ant-design/pro-components/blob/master/packages/utils/src/isImg/index.ts

const imagePattern = 'png|jpg|jpeg|svg|webp|gif|bmp';
const suffixPattern = new RegExp(`\\w.(${imagePattern})$`, 'i');
const base64Pattern = new RegExp(`^data:image\\/(${imagePattern})`, 'i');

/** 判断是否是图片链接 */
function isImg(path: string): boolean {
return /\w.(png|jpg|jpeg|svg|webp|gif|bmp)$/i.test(path);
return suffixPattern.test(path) || base64Pattern.test(path);
}

export default isImg;
6 changes: 5 additions & 1 deletion packages/utils/src/isImg/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// source by https://github.com/ant-design/pro-components/blob/master/packages/utils/src/isImg/index.ts

const imagePattern = 'png|jpg|jpeg|svg|webp|gif|bmp';
const suffixPattern = new RegExp(`\\w.(${imagePattern})$`, 'i');
const base64Pattern = new RegExp(`^data:image\\/(${imagePattern})`, 'i');

/** 判断是否是图片链接 */
function isImg(path: string): boolean {
return /\w.(png|jpg|jpeg|svg|webp|gif|bmp)$/i.test(path);
return suffixPattern.test(path) || base64Pattern.test(path);
}

export default isImg;