MCPcopy Create free account
hub / github.com/cn-docs/vueuse / cacheStringFunction

Function cacheStringFunction

packages/shared/utils/port.ts:2–8  ·  view source on GitHub ↗
(fn: T)

Source from the content-addressed store, hash-verified

1// copied from vue: https://github.com/vuejs/core/blob/3be4e3cbe34b394096210897c1be8deeb6d748d8/packages/shared/src/general.ts#L90-L112
2function 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
10const hyphenateRE = /\B([A-Z])/g
11export const hyphenate = cacheStringFunction((str: string) => str.replace(hyphenateRE, '-$1').toLowerCase())

Callers 1

port.tsFile · 0.85

Calls 1

fnFunction · 0.85

Tested by

no test coverage detected