From a86edf1497150fa950bc8fc74ca374effa3662e5 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 5 Dec 2018 14:06:34 +0200 Subject: [PATCH] feature(package) kebabToCamelCase -> just-pascal-case --- client/client.js | 5 +++-- client/load-module.js | 7 +++---- common/util.js | 23 ----------------------- package.json | 1 + test/common/util.js | 22 ---------------------- 5 files changed, 7 insertions(+), 51 deletions(-) diff --git a/client/client.js b/client/client.js index f5d4325d..60ec4392 100644 --- a/client/client.js +++ b/client/client.js @@ -8,7 +8,7 @@ const rendy = require('rendy/legacy'); const exec = require('execon'); const load = require('load.js'); -const {kebabToCamelCase} = require('../common/util'); +const pascalCase = require('just-pascal-case'); const isDev = process.env.NODE_ENV === 'development'; const Images = require('./dom/images'); @@ -21,6 +21,7 @@ const currify = require('currify/legacy'); const bind = (f, ...a) => () => f(...a); const noop = () => {}; +const noJS = (a) => a.replace(/.js$/, ''); const { apiURL, @@ -187,7 +188,7 @@ function CloudCmdProto(DOM) { return; const [kebabModule] = query; - const module = kebabToCamelCase(kebabModule.slice(1)); + const module = noJS(pascalCase(kebabModule.slice(1))); const file = query[1]; const current = DOM.getCurrentByName(file); diff --git a/client/load-module.js b/client/load-module.js index b1e91790..9c203e87 100644 --- a/client/load-module.js +++ b/client/load-module.js @@ -7,9 +7,8 @@ const tryToCatch = require('try-to-catch/legacy'); const {promisify} = require('es6-promisify'); const loadJS = promisify(require('load.js').js); -const { - kebabToCamelCase, -} = require('../common/util'); +const pascalCase = require('just-pascal-case'); +const noJS = (a) => a.replace(/.js$/, ''); /** * function load modules @@ -20,7 +19,7 @@ module.exports = function loadModule(params) { return; const {path} = params; - const name = params.name || path && kebabToCamelCase(path); + const name = params.name || path && noJS(pascalCase(path)); const doBefore = params.dobefore; if (CloudCmd[name]) diff --git a/common/util.js b/common/util.js index 3580b685..77f0a6c6 100644 --- a/common/util.js +++ b/common/util.js @@ -2,9 +2,6 @@ const exec = require('execon'); -module.exports.getStrBigFirst = getStrBigFirst; -module.exports.kebabToCamelCase = kebabToCamelCase; - module.exports.escapeRegExp = (str) => { const isStr = typeof str === 'string'; @@ -106,23 +103,3 @@ module.exports.timeEnd = (name) => { exec.ifExist(console, 'timeEnd', [name]); }; -function getStrBigFirst(str) { - if (!str) - throw Error('str could not be empty!'); - - const 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$/, ''); -} - diff --git a/package.json b/package.json index 8e43d7d0..51aa0d87 100644 --- a/package.json +++ b/package.json @@ -198,6 +198,7 @@ "html-looks-like": "^1.0.2", "html-webpack-plugin": "^3.0.7", "inherits": "^2.0.3", + "just-pascal-case": "^1.1.0", "limier": "^2.0.0", "load.js": "^2.0.0", "memfs": "^2.9.0", diff --git a/test/common/util.js b/test/common/util.js index c862647d..52d6a664 100644 --- a/test/common/util.js +++ b/test/common/util.js @@ -6,8 +6,6 @@ const DIR = '../../'; const UtilPath = DIR + 'common/util'; const Util = require(UtilPath); const { - getStrBigFirst, - kebabToCamelCase, findObjByNameInArr, getRegExp, escapeRegExp, @@ -38,26 +36,6 @@ test('util: getExt: no name', (t) => { t.end(); }); -test('getStrBigFirst: args', (t) => { - t.throws(getStrBigFirst, /str could not be empty!/, 'should throw when no str'); - t.end(); -}); - -test('getStrBigFirst', (t) => { - 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 case'); - t.end(); -}); - test('util: findObjByNameInArr: no array', (t) => { t.throws(findObjByNameInArr, /array should be array!/, 'should throw when no array'); t.end();