mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(package) kebabToCamelCase -> just-pascal-case
This commit is contained in:
parent
e6dee77695
commit
a86edf1497
5 changed files with 7 additions and 51 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
|
|
|
|||
|
|
@ -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$/, '');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue