Skip to content

Commit 85ec203

Browse files
committed
Merge pull request #120 from defcc/defcc-patch-isImage
优化 isImage 函数
2 parents c62e92c + a46940f commit 85ec203

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

src/qiniu.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,21 +182,8 @@ 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+
url = url.split(/[?#]/)[0];
186+
return (/\.(png|jpg|jpeg|gif|bmp)$/i).test(url);
200187
};
201188

202189
/**

0 commit comments

Comments
 (0)