Skip to content

Commit

Permalink
Merge branch 'master' into allow-path-regex
Browse files Browse the repository at this point in the history
  • Loading branch information
GMierzwa authored Oct 10, 2023
2 parents 7b21368 + 1899009 commit eaf95cd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/core/src/utils/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = {};

export const pascal = (s: string) => {
if (pascalMemory[s]) {
return pascalMemory[s];
}

const isStartWithUnderscore = s?.startsWith('_');

if (regexps.upper.test(s)) {
Expand All @@ -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) => {
Expand Down

0 comments on commit eaf95cd

Please sign in to comment.