| 1 | // copied from vue: https://github.com/vuejs/core/blob/3be4e3cbe34b394096210897c1be8deeb6d748d8/packages/shared/src/general.ts#L90-L112 |
| 2 | function cacheStringFunction<T extends (str: string) => string>(fn: T): T { |
| 3 | const cache: Record<string, string> = Object.create(null) |
| 4 | return ((str: string) => { |
| 5 | const hit = cache[str] |
| 6 | return hit || (cache[str] = fn(str)) |
| 7 | }) as T |
| 8 | } |
| 9 | |
| 10 | const hyphenateRE = /\B([A-Z])/g |
| 11 | export const hyphenate = cacheStringFunction((str: string) => str.replace(hyphenateRE, '-$1').toLowerCase()) |