fix(v-on): capitalize dynamic event names

This commit is contained in:
Evan You
2020-07-13 17:36:46 -04:00
parent 576344d2c3
commit 9152a89016
5 changed files with 23 additions and 16 deletions

View File

@@ -94,6 +94,9 @@ const cacheStringFunction = <T extends (str: string) => string>(fn: T): T => {
}
const camelizeRE = /-(\w)/g
/**
* @private
*/
export const camelize = cacheStringFunction(
(str: string): string => {
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''))
@@ -101,12 +104,18 @@ export const camelize = cacheStringFunction(
)
const hyphenateRE = /\B([A-Z])/g
/**
* @private
*/
export const hyphenate = cacheStringFunction(
(str: string): string => {
return str.replace(hyphenateRE, '-$1').toLowerCase()
}
)
/**
* @private
*/
export const capitalize = cacheStringFunction(
(str: string): string => {
return str.charAt(0).toUpperCase() + str.slice(1)