feature(util) rm checkExt

This commit is contained in:
coderaiser 2015-03-20 08:11:32 -04:00
parent 1a0ffd499e
commit f57c1f3c7e
3 changed files with 7 additions and 79 deletions

View file

@ -182,7 +182,7 @@ var CloudCmd, Util, DOM, CloudFunc, $;
function isImage(name) {
var isMatch;
isMatch = Util.checkExt(name, [
isMatch = [
'jp(e|g|eg)',
'gif',
'png',
@ -190,7 +190,10 @@ var CloudCmd, Util, DOM, CloudFunc, $;
'webp',
'svg',
'ico'
]);
].some(function(ext) {
var reg = RegExp('\\.' + ext + '$');
return reg.test(name);
});
return isMatch;
}
@ -204,19 +207,11 @@ var CloudCmd, Util, DOM, CloudFunc, $;
}
function isAudio(name) {
var isMatch;
isMatch = Util.checkExt(name, ['mp3', 'ogg']);
return isMatch;
return /\.(mp3|ogg)$/.test(name);
}
function isVideo(name) {
var isMatch;
isMatch = Util.checkExt(name, ['mp4', 'avi']);
return isMatch;
return /\.(mp4|avi)$/.test(name);
}
function getType(name) {

View file

@ -11,39 +11,6 @@
function UtilProto() {
var Util = this;
/**
* Функция ищет в имени файла расширение
* и если находит возвращает true
* @param name - получает имя файла
* @param ext - расширение
*/
this.checkExt = function(name, ext) {
var isMatch, str,
type = Util.type(ext),
regStr = '\\.({{ exts }})$',
regExp;
switch(type) {
case 'string':
regStr = Util.render(regStr, {
exts: ext
});
regExp = new RegExp(regStr, 'i');
isMatch = regExp.test(name);
break;
case 'array':
str = ext.join('|');
isMatch = Util.checkExt(name, str);
break;
}
return isMatch;
};
this.check = new checkProto();
function checkProto() {

View file

@ -26,40 +26,6 @@
});
});
describe('checkExt', function() {
it('should return true when extension is same', function() {
var EXT = 'png',
name = 'picture.png',
same = Util.checkExt(name, EXT);
same.should.be.true;
});
it('should return false when extension is not same', function() {
var EXT = 'jpg',
name = 'picture.png',
same = Util.checkExt(name, EXT);
same.should.be.false;
});
it('should return true when one item of extensions array is same', function() {
var EXT = ['jpg', 'png'],
name = 'picture.png',
same = Util.checkExt(name, EXT);
same.should.be.true;
});
it('should return false when no one item of extensions array is same', function() {
var EXT = ['jpg', 'gif'],
name = 'picture.png',
same = Util.checkExt(name, EXT);
same.should.be.false;
});
});
describe('exec', function() {
it('should execute function with parameters', function() {
var WORD = 'hello',