Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(build): components field support PascalCase (#143)
- Loading branch information
Showing
5 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* @file util | ||
* @author zhangwentao | ||
*/ | ||
|
||
/** | ||
* Create a cached version of a pure function. | ||
*/ | ||
|
||
function cached(fn) { | ||
const cache = Object.create(null); | ||
return function cachedFn(str) { | ||
const hit = cache[str]; | ||
return hit || (cache[str] = fn(str)); | ||
}; | ||
} | ||
|
||
/** | ||
* Camelize a hyphen-delimited string. | ||
*/ | ||
|
||
const camelizeRE = /-(\w)/g; | ||
const camelize = cached(str => { | ||
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : ''); | ||
}); | ||
|
||
/** | ||
* Capitalize a string. | ||
*/ | ||
const capitalize = cached(str => { | ||
return str.charAt(0).toUpperCase() + str.slice(1); | ||
}); | ||
|
||
/** | ||
* Hyphenate a camelCase string. | ||
*/ | ||
const hyphenateRE = /\B([A-Z])/g; | ||
const hyphenate = cached(str => { | ||
return str.replace(hyphenateRE, '-$1').toLowerCase(); | ||
}); | ||
|
||
exports.camelize = camelize; | ||
exports.capitalize = capitalize; | ||
exports.hyphenate = hyphenate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,6 @@ function transAttrs(node, options) { | |
attrs[key] = val; | ||
} | ||
} | ||
|
||
}); | ||
|
||
if (null !== showAttr) { | ||
|