Skip to content

Commit a65cc4e

Browse files
committed
优化 isImage 函数
1 parent 736799a commit a65cc4e

File tree

1 file changed

+1
-15
lines changed

1 file changed

+1
-15
lines changed

src/qiniu.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,21 +182,7 @@ function QiniuJsSDK() {
182182
* @return {Boolean} file is a image or not
183183
*/
184184
this.isImage = function(url) {
185-
var res, suffix = "";
186-
var imageSuffixes = ["png", "jpg", "jpeg", "gif", "bmp"];
187-
var suffixMatch = /\.([a-zA-Z0-9]+)(\?|\@|$)/;
188-
189-
if (!url || !suffixMatch.test(url)) {
190-
return false;
191-
}
192-
res = suffixMatch.exec(url);
193-
suffix = res[1].toLowerCase();
194-
for (var i = 0, l = imageSuffixes.length; i < l; i++) {
195-
if (suffix === imageSuffixes[i]) {
196-
return true;
197-
}
198-
}
199-
return false;
185+
return /\.(png|jpg|jpeg|gif|bmp)$/i.test(url);
200186
};
201187

202188
/**

0 commit comments

Comments
 (0)