mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-24 15:39:15 +08:00
[improvement] Uploader: support more image types (#4140)
This commit is contained in:
parent
67fc817cfd
commit
b573ba9f6a
@ -6,6 +6,10 @@ test('isImageFile', () => {
|
|||||||
expect(isImageFile({ url: 'https://a.png' })).toBeTruthy();
|
expect(isImageFile({ url: 'https://a.png' })).toBeTruthy();
|
||||||
expect(isImageFile({ url: 'https://a.svg' })).toBeTruthy();
|
expect(isImageFile({ url: 'https://a.svg' })).toBeTruthy();
|
||||||
expect(isImageFile({ url: 'https://a.gif' })).toBeTruthy();
|
expect(isImageFile({ url: 'https://a.gif' })).toBeTruthy();
|
||||||
|
expect(isImageFile({ url: 'https://a.webp' })).toBeTruthy();
|
||||||
|
expect(isImageFile({ url: 'https://a.jfif' })).toBeTruthy();
|
||||||
|
expect(isImageFile({ url: 'https://a.bmp' })).toBeTruthy();
|
||||||
|
expect(isImageFile({ url: 'https://a.dpg' })).toBeTruthy();
|
||||||
expect(isImageFile({ file: { type: 'image/jpg' } })).toBeTruthy();
|
expect(isImageFile({ file: { type: 'image/jpg' } })).toBeTruthy();
|
||||||
expect(isImageFile({ file: { type: 'application/pdf' } })).toBeFalsy();
|
expect(isImageFile({ file: { type: 'application/pdf' } })).toBeFalsy();
|
||||||
expect(isImageFile({ content: 'data:image/xxx' })).toBeTruthy();
|
expect(isImageFile({ content: 'data:image/xxx' })).toBeTruthy();
|
||||||
|
@ -33,10 +33,10 @@ export type FileListItem = {
|
|||||||
isImage?: boolean;
|
isImage?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const IMAGE_EXT = ['jpeg', 'jpg', 'gif', 'png', 'svg'];
|
const IMAGE_REGEXP = /\.(jpeg|jpg|gif|png|svg|webp|jfif|bmp|dpg)/i;
|
||||||
|
|
||||||
export function isImageUrl(url: string): boolean {
|
export function isImageUrl(url: string): boolean {
|
||||||
return IMAGE_EXT.some(ext => url.indexOf(`.${ext}`) !== -1);
|
return IMAGE_REGEXP.test(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isImageFile(item: FileListItem): boolean {
|
export function isImageFile(item: FileListItem): boolean {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user