diff --git a/packages/core/src/utils/case.ts b/packages/core/src/utils/case.ts index f45a492b2..222a9d29b 100644 --- a/packages/core/src/utils/case.ts +++ b/packages/core/src/utils/case.ts @@ -88,7 +88,14 @@ const lower = (s: string, fillWith: string, isDeapostrophe: boolean) => { return fill(low.call(prep(s, !!fillWith)), fillWith, isDeapostrophe); }; +// Caches the previously converted strings to improve performance +let pascalMemory: Record = {}; + export const pascal = (s: string) => { + if (pascalMemory[s]) { + return pascalMemory[s]; + } + const isStartWithUnderscore = s?.startsWith('_'); if (regexps.upper.test(s)) { @@ -99,7 +106,13 @@ export const pascal = (s: string) => { .map((w) => w.charAt(0).toUpperCase() + w.slice(1)) .join(''); - return isStartWithUnderscore ? `_${pascalString}` : pascalString; + const pascalWithUnderscore = isStartWithUnderscore + ? `_${pascalString}` + : pascalString; + + pascalMemory[s] = pascalWithUnderscore; + + return pascalWithUnderscore; }; export const camel = (s: string) => {