Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(createReusableTemplate): camelize props (#3253)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com> Co-authored-by: Kasper Seweryn <github@wvffle.net>
- Loading branch information
1 parent
d0fd3f0
commit d79e174
Showing
7 changed files
with
63 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,18 @@ | ||
// copied from vue: https://github.com/vuejs/core/blob/3be4e3cbe34b394096210897c1be8deeb6d748d8/packages/shared/src/general.ts#L90-L112 | ||
function cacheStringFunction<T extends (str: string) => string>(fn: T): T { | ||
const cache: Record<string, string> = Object.create(null) | ||
return ((str: string) => { | ||
const hit = cache[str] | ||
return hit || (cache[str] = fn(str)) | ||
}) as T | ||
} | ||
|
||
const hyphenateRE = /\B([A-Z])/g | ||
export const hyphenate = cacheStringFunction((str: string) => | ||
str.replace(hyphenateRE, '-$1').toLowerCase(), | ||
) | ||
|
||
const camelizeRE = /-(\w)/g | ||
export const camelize = cacheStringFunction((str: string): string => { | ||
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : '')) | ||
}) |
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