mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
feature(util) checkExtension -> checkExt
This commit is contained in:
parent
8a4d6bb28f
commit
d31a166e52
3 changed files with 27 additions and 31 deletions
|
|
@ -162,25 +162,17 @@ var CloudCmd, Util, DOM, CloudFunc, $;
|
|||
}
|
||||
|
||||
function isAudio(name) {
|
||||
var isMatch,
|
||||
isStr = Util.isString(name),
|
||||
exts = '\\.(mp3|ogg)$',
|
||||
extsReg = new RegExp(exts);
|
||||
var isMatch;
|
||||
|
||||
if (isStr)
|
||||
isMatch = name.match(extsReg);
|
||||
isMatch = Util.checkExt(name, ['mp3', 'ogg']);
|
||||
|
||||
return isMatch;
|
||||
}
|
||||
|
||||
function isVideo(name) {
|
||||
var isMatch,
|
||||
isStr = Util.isString(name),
|
||||
exts = '\\.(mp4|avi)$',
|
||||
extsReg = new RegExp(exts);
|
||||
var isMatch;
|
||||
|
||||
if (isStr)
|
||||
isMatch = name.match(extsReg);
|
||||
Util.checkExt(name, ['mp4', 'avi']);
|
||||
|
||||
return isMatch;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@
|
|||
AppCache.watch(name);
|
||||
|
||||
name = Path.join(DIR, name);
|
||||
check = checkExtension(name);
|
||||
check = checkExt(name);
|
||||
result = isMin && check;
|
||||
|
||||
Util.ifExec(!result,
|
||||
|
|
@ -250,7 +250,7 @@
|
|||
names[i] = name;
|
||||
|
||||
if (config.minify) {
|
||||
check = checkExtension(name);
|
||||
check = checkExt(name);
|
||||
|
||||
if (check) {
|
||||
minName = Minify.getName(name);
|
||||
|
|
@ -270,10 +270,10 @@
|
|||
});
|
||||
}
|
||||
|
||||
function checkExtension(name) {
|
||||
function checkExt(name) {
|
||||
var ret;
|
||||
|
||||
ret = Util.checkExtension(name, ['.js', '.css', '.html']);
|
||||
ret = Util.checkExt(name, ['js', 'css', 'html']);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
34
lib/util.js
34
lib/util.js
|
|
@ -88,34 +88,38 @@
|
|||
* @param name - получает имя файла
|
||||
* @param ext - расширение
|
||||
*/
|
||||
this.checkExtension = function(name, ext) {
|
||||
var extNum, extSub, ret,
|
||||
this.checkExt = function(name, ext) {
|
||||
var isMatch, str,
|
||||
type = Util.getType(ext),
|
||||
extLength = ext && ext.length,
|
||||
length = name && name.length;
|
||||
regStr = '\\.({{ exts }})$',
|
||||
regExp;
|
||||
|
||||
switch(type) {
|
||||
case 'string':
|
||||
regStr = Util.render(regStr, {
|
||||
exts: ext
|
||||
});
|
||||
|
||||
regExp = new RegExp(regStr);
|
||||
isMatch = name.match(regExp);
|
||||
|
||||
break;
|
||||
|
||||
case 'array':
|
||||
ext.some(function(item) {
|
||||
ret = Util.checkExtension(name, item);
|
||||
str = ext.reduce(function(prev, cur) {
|
||||
var ret = prev += cur + '|';
|
||||
|
||||
return ret;
|
||||
});
|
||||
break;
|
||||
}, '');
|
||||
|
||||
case 'string':
|
||||
extNum = name.lastIndexOf(ext), /* последнее вхождение расширения*/
|
||||
extSub = length - extNum; /* длина расширения*/
|
||||
isMatch = Util.checkExt(name, str);
|
||||
|
||||
/* если ext - расширение pName */
|
||||
ret = extSub === extLength;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return isMatch;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Check is Properties exists and they are true if neaded
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue