From 9601355097485c0d22c9b6d7280de51dd6708dcb Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 19 Dec 2014 09:54:12 -0500 Subject: [PATCH] feature(util) rm rmStrOnce --- lib/client/listeners.js | 6 +++--- lib/client/load.js | 2 +- lib/server/rest.js | 6 ++++-- lib/server/rest/markdown.js | 2 +- lib/server/route.js | 2 +- lib/util.js | 13 ------------- 6 files changed, 10 insertions(+), 21 deletions(-) diff --git a/lib/client/listeners.js b/lib/client/listeners.js index 2da12c68..75c38560 100644 --- a/lib/client/listeners.js +++ b/lib/client/listeners.js @@ -88,14 +88,14 @@ var Util, DOM, CloudFunc, CloudCmd; case 'js-path-link': url = CloudCmd.HOST; href = element.href; - link = Util.rmStr(href, url); + link = href.replace(url, ''); /* * browser do not replace % -> %25% * do it for him */ link = Util.replaceStr(link, '%%', '%25%'); link = decodeURI(link); - link = Util.rmStrOnce(link, CloudFunc.FS) || '/'; + link = link.replace(CloudFunc.FS, '') || '/'; CloudCmd.loadDir({ path : link, @@ -306,7 +306,7 @@ var Util, DOM, CloudFunc, CloudCmd; Events.add('popstate', function(event) { var path = event.state; - path = Util.rmStrOnce(path, CloudFunc.FS); + path = path.replace(CloudFunc.FS, ''); if (path) CloudCmd.loadDir({ diff --git a/lib/client/load.js b/lib/client/load.js index ad7efbe4..7723a28e 100644 --- a/lib/client/load.js +++ b/lib/client/load.js @@ -145,7 +145,7 @@ var Util, DOM; num = src.lastIndexOf('/') + 1, sub = src.substr(src, num), - id = Util.rmStrOnce(src, sub); + id = src.replace(sub, ''); /* убираем точки */ id = id.replace(/\./g, '-'); diff --git a/lib/server/rest.js b/lib/server/rest.js index a2f322f0..61f28041 100644 --- a/lib/server/rest.js +++ b/lib/server/rest.js @@ -56,7 +56,7 @@ if (!is) { next(); } else { - params.name = Util.rmStrOnce(name, apiURL) || '/'; + params.name = name.replace(apiURL, '') || '/'; sendData(params, function(error, options, data) { params.gzip = !error; @@ -264,7 +264,9 @@ if (files.to) to = mellow.convertPath(files.to); else - to = Util.rmStrOnce(files.from, ['.zip', '.tar.gz', '.gz']); + ['.zip', '.tar.gz', '.gz'].forEach(function(str) { + to = files.from.replace(str); + }); packer.unpack(from, to, function(error) { var name = path.basename(files.from), diff --git a/lib/server/rest/markdown.js b/lib/server/rest/markdown.js index 63ce4456..913876aa 100644 --- a/lib/server/rest/markdown.js +++ b/lib/server/rest/markdown.js @@ -26,7 +26,7 @@ switch(method) { case 'GET': - name = Util.rmStrOnce(name, '/markdown'); + name = name.replace('/markdown', ''); query = ponse.getQuery(request); if (query === 'relative') diff --git a/lib/server/route.js b/lib/server/route.js index 7ca0d545..6db8645e 100644 --- a/lib/server/route.js +++ b/lib/server/route.js @@ -138,7 +138,7 @@ p.name = DIR_HTML + name + '.html'; ponse.sendFile(p); } else if (isFS) { - name = Util.rmStrOnce(name, CloudFunc.FS) || '/'; + name = name.replace(CloudFunc.FS, '') || '/'; path = mellow.convertPath(name); mellow.read(path, function(error, dir) { diff --git a/lib/util.js b/lib/util.js index b2725952..46aae627 100644 --- a/lib/util.js +++ b/lib/util.js @@ -299,19 +299,6 @@ return str; }; - /** - * function remove substring from string one time - * @param str - * @param substr - */ - this.rmStrOnce = function(str, substr) { - var ONCE = true; - - str = Util.rmStr(str, substr, ONCE); - - return str; - }; - /** * function replase pFrom to pTo in pStr * @param str