From f57c1f3c7e8a2ff6cde1b7c3e6e65d4a37e0ddc9 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 20 Mar 2015 08:11:32 -0400 Subject: [PATCH] feature(util) rm checkExt --- lib/client/view.js | 19 +++++++------------ lib/util.js | 33 --------------------------------- test/lib/util.js | 34 ---------------------------------- 3 files changed, 7 insertions(+), 79 deletions(-) diff --git a/lib/client/view.js b/lib/client/view.js index 0669d5f4..1f92e03f 100644 --- a/lib/client/view.js +++ b/lib/client/view.js @@ -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) { diff --git a/lib/util.js b/lib/util.js index b906fd7b..1a1cda38 100644 --- a/lib/util.js +++ b/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() { diff --git a/test/lib/util.js b/test/lib/util.js index 8b1a6472..b07ddadd 100644 --- a/test/lib/util.js +++ b/test/lib/util.js @@ -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',