mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-18 00:47:01 +00:00
feature(util) rm checkExt
This commit is contained in:
parent
1a0ffd499e
commit
f57c1f3c7e
3 changed files with 7 additions and 79 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
33
lib/util.js
33
lib/util.js
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue