@cara/porter
Advanced tools
Comparing version 4.0.0-beta.8 to 4.0.0-beta.9
{ | ||
"name": "@cara/porter", | ||
"description": "A middleware for web modules", | ||
"version": "4.0.0-beta.8", | ||
"version": "4.0.0-beta.9", | ||
"main": "src/porter.js", | ||
@@ -43,3 +43,3 @@ "repository": { | ||
"license": "BSD-3-Clause", | ||
"gitHead": "523789762c2e217cf2f7c997e153a150cb829c37" | ||
"gitHead": "763577e5a13486f9e46d9c5339200f6b5df4c3be" | ||
} |
@@ -48,3 +48,7 @@ 'use strict'; | ||
function formatImports(declarations, options) { | ||
function formatImports(declarations, options = {}) { | ||
if (options.camel2DashComponentName === false && options.componentCase == null) { | ||
options.componentCase = 'camel'; | ||
} | ||
const { | ||
@@ -54,2 +58,3 @@ libraryName, | ||
style = true, | ||
componentCase = 'kebab' | ||
} = options; | ||
@@ -61,9 +66,10 @@ const scripts = []; | ||
const { name, alias } = declaration; | ||
const chunk = [ libraryName ]; | ||
const chunk = [libraryName]; | ||
if (libraryDirectory) chunk.push(libraryDirectory); | ||
chunk.push(dasherize(name)); | ||
scripts.push(`import ${alias || name} from '${chunk.join('/')}';`); | ||
const transformedChunkName = decamelize(name, componentCase); | ||
chunk.push(transformedChunkName); | ||
scripts.push(`import ${alias || name} from ${JSON.stringify(chunk.join('/'))};`); | ||
if (style) { | ||
const file = typeof style === 'string' ? path.join('style', style) : 'style'; | ||
styles.push(`import '${chunk.join('/')}/${file}';`); | ||
styles.push(`import ${JSON.stringify(chunk.concat(file).join('/'))};`); | ||
} | ||
@@ -75,15 +81,15 @@ } | ||
/** | ||
* Convert strings connected with hyphen or underscore into camel case. e.g. | ||
* @example | ||
* camelCase('FooBar') // => 'fooBar' | ||
* camelCase('foo-bar') // => 'fooBar' | ||
* camelCase('foo_bar') // => 'fooBar' | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
function dasherize(str) { | ||
return str | ||
.replace(/^([A-Z])/, (m, chr) => chr.toLowerCase()) | ||
.replace(/([A-Z])/g, (m, chr) => `-${chr.toLowerCase()}`); | ||
function decamelize(_str, componentCase) { | ||
const str = _str[0].toLowerCase() + _str.substr(1); | ||
switch (componentCase) { | ||
case 'kebab': | ||
return str.replace(/([A-Z])/g, $1 => `-${$1.toLowerCase()}`); | ||
case 'snake': | ||
return str.replace(/([A-Z])/g, $1 => `_${$1.toLowerCase()}`); | ||
case 'camel': | ||
return str; | ||
default: | ||
return _str; | ||
} | ||
} | ||
@@ -90,0 +96,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
109328
2871