|
| 1 | +const cacheStringFunction = <T extends (str: string) => string>(fn: T): T => { |
| 2 | + const cache: Record<string, string> = Object.create(null) |
| 3 | + return ((str: string) => { |
| 4 | + const hit = cache[str] |
| 5 | + return hit || (cache[str] = fn(str)) |
| 6 | + }) as any |
| 7 | +} |
| 8 | + |
| 9 | +const camelizeRE = /-(\w)/g |
| 10 | +export const camelize = cacheStringFunction((str: string): string => { |
| 11 | + return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : '')) |
| 12 | +}) |
| 13 | + |
| 14 | +export const capitalize = cacheStringFunction((str: string): string => { |
| 15 | + return str.charAt(0).toUpperCase() + str.slice(1) |
| 16 | +}) |
| 17 | + |
| 18 | +const hyphenateRE = /\B([A-Z])/g |
| 19 | +export const hyphenate = cacheStringFunction((str: string): string => { |
| 20 | + return str.replace(hyphenateRE, '-$1').toLowerCase() |
| 21 | +}) |
| 22 | + |
| 23 | +export const enum ShapeFlags { |
| 24 | + ELEMENT = 1, |
| 25 | + FUNCTIONAL_COMPONENT = 1 << 1, |
| 26 | + STATEFUL_COMPONENT = 1 << 2, |
| 27 | + TEXT_CHILDREN = 1 << 3, |
| 28 | + ARRAY_CHILDREN = 1 << 4, |
| 29 | + SLOTS_CHILDREN = 1 << 5, |
| 30 | + TELEPORT = 1 << 6, |
| 31 | + SUSPENSE = 1 << 7, |
| 32 | + COMPONENT_SHOULD_KEEP_ALIVE = 1 << 8, |
| 33 | + COMPONENT_KEPT_ALIVE = 1 << 9, |
| 34 | + COMPONENT = ShapeFlags.STATEFUL_COMPONENT | ShapeFlags.FUNCTIONAL_COMPONENT |
| 35 | +} |
0 commit comments