Skip to content

Commit 14ee9e7

Browse files
sliweyyyx990803
authored andcommitted
perf: optimize the performance of hyphenate method. (#6274)
1 parent 0b2929a commit 14ee9e7

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/shared/util.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,9 @@ export const capitalize = cached((str: string): string => {
157157
/**
158158
* Hyphenate a camelCase string.
159159
*/
160-
const hyphenateRE = /([^-])([A-Z])/g
160+
const hyphenateRE = /\B([A-Z])/g
161161
export const hyphenate = cached((str: string): string => {
162-
return str
163-
.replace(hyphenateRE, '$1-$2')
164-
.replace(hyphenateRE, '$1-$2')
165-
.toLowerCase()
162+
return str.replace(hyphenateRE, '-$1').toLowerCase()
166163
})
167164

168165
/**

0 commit comments

Comments
 (0)