diff --git a/lib/client/view.js b/lib/client/view.js index 361f5e61..186ceb13 100644 --- a/lib/client/view.js +++ b/lib/client/view.js @@ -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; } diff --git a/lib/server.js b/lib/server.js index 5fe2fbea..18446e49 100644 --- a/lib/server.js +++ b/lib/server.js @@ -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; } diff --git a/lib/util.js b/lib/util.js index 813ea2d4..2449f85e 100644 --- a/lib/util.js +++ b/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 *