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I,EAAE,MAAM,CAAC,CAAC;QACxB,OAAO,MAAM,CAAC;IAChB,CAAC;IAKD,gBAAuB,CAAC;;AAHxB,uFAAuF;AAC/D,YAAM,GAAG,IAAI,OAAO,EAAiC,CAAC;AAKhF,MAAM,QAAQ;IACL,MAAM,CAAC,GAAG,CAAC,IAAS;QACzB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC;QAC5C,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC9B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1C,OAAO,MAAM,CAAC;IAChB,CAAC;IAKD,gBAAuB,CAAC;;AAHxB,iGAAiG;AACzE,cAAK,GAAG,IAAI,GAAG,EAA0B,CAAC","sourcesContent":["import * as Case from 'case';\n\nconst withCache =\n (func: (text: string) => string): ((text: string) => string) =>\n (text: string) =>\n Cache.fetch(text, func);\n\nexport const camel = withCache(Case.camel);\nexport const constant = withCache(Case.constant);\nexport const pascal = withCache(Case.pascal);\nexport const snake = withCache(Case.snake);\nexport const kebab = withCache(Case.kebab);\n\nclass Cache {\n public static fetch(text: string, func: (text: string) => string): string {\n // Check whether we have a cache for this function...\n const cacheKey = CacheKey.for(func);\n let cache = this.CACHES.get(cacheKey);\n if (cache == null) {\n // If not, create one...\n cache = new Map<string, string>();\n this.CACHES.set(cacheKey, cache);\n }\n\n // Check if the current cache has a value for this text...\n const cached = cache.get(text);\n if (cached != null) {\n return cached;\n }\n\n // If not, compute one...\n const result = func(text);\n cache.set(text, result);\n return result;\n }\n\n // Cache is indexed on a weak CacheKey so the cache can be purged under memory pressure\n private static readonly CACHES = new WeakMap<CacheKey, Map<string, string>>();\n\n private constructor() {}\n}\n\nclass CacheKey {\n public static for(data: any) {\n const entry = this.STORE.get(data)?.deref();\n if (entry != null) {\n return entry;\n }\n const newKey = new CacheKey();\n this.STORE.set(data, new WeakRef(newKey));\n return newKey;\n }\n\n // Storing cache keys as weak references to allow garbage collection if there is memory pressure.\n private static readonly STORE = new Map<any, WeakRef<CacheKey>>();\n\n private constructor() {}\n}\n"]} |