diff --git a/client/client.js b/client/client.js index 59f01488..bf7012c1 100644 --- a/client/client.js +++ b/client/client.js @@ -44,6 +44,7 @@ var Util, DOM, CloudFunc, join; }; var getStrBigFirst = Util.getStrBigFirst; + var kebabToCamelCase = Util.kebabToCamelCase; /** * Функция привязываеться ко всем ссылкам и @@ -103,10 +104,8 @@ var Util, DOM, CloudFunc, join; funcName = params.funcName, doBefore = params.dobefore; - if (path && !name) { - name = getStrBigFirst(path); - name = name.replace(/.js$/, ''); - } + if (path && !name) + name = kebabToCamelCase(path); isContain = /\.js/.test(path); diff --git a/common/util.js b/common/util.js index 1b2ec4fa..80f194e0 100644 --- a/common/util.js +++ b/common/util.js @@ -23,13 +23,8 @@ this.check = new checkProto(); - this.getStrBigFirst = function getStrBigFirst(str) { - if (!str) - throw Error('str could not be empty!'); - - var first = str[0].toUpperCase(); - return first + str.slice(1); - } + this.getStrBigFirst = getStrBigFirst; + this.kebabToCamelCase = kebabToCamelCase; function checkProto() { /** @@ -335,6 +330,26 @@ return this; }; + + function getStrBigFirst(str) { + if (!str) + throw Error('str could not be empty!'); + + var first = str[0].toUpperCase(); + return first + str.slice(1); + } + + function kebabToCamelCase(str) { + if (!str) + throw Error('str could not be empty!'); + + return str + .split('-') + .map(getStrBigFirst) + .join('') + .replace(/.js$/, ''); + } + } })(this); diff --git a/package.json b/package.json index 7df3dfa5..865680fe 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "es5:eslint": "eslint -c .es5/.eslintrc --rule 'no-console:0' $npm_package_config_dirs_legacy --ignore-path bin/release.js", "fix:es5:eslint": "redrun es5:eslint -- --fix", "test": "tape 'test/**/*.js'", - "watch:test": "nodemon -w server -w test -x \"npm run test\"", + "watch:test": "nodemon -w server -w test -w common -x \"npm run test\"", "spell": "yaspeller .", "wisdom": "npm run build; npm run docker:rm-old; bin/release.js", "postpublish": "redrun --parallel docker docker:alpine", diff --git a/test/server/cloudfunc.html b/test/common/cloudfunc.html similarity index 100% rename from test/server/cloudfunc.html rename to test/common/cloudfunc.html diff --git a/test/server/cloudfunc.js b/test/common/cloudfunc.js similarity index 98% rename from test/server/cloudfunc.js rename to test/common/cloudfunc.js index 815b9ba1..d9e01d9b 100644 --- a/test/server/cloudfunc.js +++ b/test/common/cloudfunc.js @@ -12,7 +12,7 @@ var DIR = __dirname + '/../../', test = require('tape'), FS_DIR = TMPLDIR + 'fs/', - EXPECT_PATH = DIR + 'test/server/cloudfunc.html', + EXPECT_PATH = __dirname + '/cloudfunc.html', TMPL_PATH = [ 'file', diff --git a/test/server/util.js b/test/common/util.js similarity index 56% rename from test/server/util.js rename to test/common/util.js index 30422ebc..52a604cd 100644 --- a/test/server/util.js +++ b/test/common/util.js @@ -3,6 +3,10 @@ const test = require('tape'); const DIR = '../../'; const Util = require(DIR + 'common/util'); +const { + getStrBigFirst, + kebabToCamelCase +} = Util; test('getExt: no extension', (t) => { const EXT = ''; @@ -23,12 +27,22 @@ test('getExt: return extension', (t) => { }); test('getStrBigFirst: args', (t) => { - t.throws(Util.getStrBigFirst, /str could not be empty!/, 'should throw when no str'); + t.throws(getStrBigFirst, /str could not be empty!/, 'should throw when no str'); t.end(); }); test('getStrBigFirst', (t) => { - t.equal(Util.getStrBigFirst('hello'), 'Hello', 'should return str'); + t.equal(getStrBigFirst('hello'), 'Hello', 'should return str'); + t.end(); +}); + +test('kebabToCamelCase: args', (t) => { + t.throws(kebabToCamelCase, /str could not be empty!/, 'should throw when no str'); + t.end(); +}); + +test('kebabToCamelCase', (t) => { + t.equal(kebabToCamelCase('hello-world'), 'HelloWorld', 'should convert kebab to camel caes'); t.end(); });