MCPcopy Create free account
hub / github.com/chhoumann/quickadd / transformCase

Function transformCase

src/utils/caseTransform.ts:120–170  ·  view source on GitHub ↗
(input: string, style?: string)

Source from the content-addressed store, hash-verified

118}
119
120export function transformCase(input: string, style?: string): string {
121 const normalized = normalizeStyle(style);
122 if (!normalized) return input;
123
124 if (normalized === "lower") return input.toLowerCase();
125 if (normalized === "upper") return input.toUpperCase();
126
127 const words = tokenizeWords(input);
128 if (words.length === 0) return "";
129
130 switch (normalized) {
131 case "kebab":
132 return words.map((w) => w.toLowerCase()).join("-");
133 case "snake":
134 return words.map((w) => w.toLowerCase()).join("_");
135 case "camel": {
136 const [first, ...rest] = words;
137 const firstOut = first
138 ? isLowerLeadingBrandToken(first)
139 ? first
140 : first.toLowerCase()
141 : "";
142 const restOut = rest.map((word) => {
143 if (isAcronym(word) || isMixedCase(word)) return word;
144 return upperFirstLowerRest(word);
145 });
146 return [firstOut, ...restOut].join("");
147 }
148 case "pascal":
149 return words
150 .map((word) => {
151 if (isAcronym(word) || isMixedCase(word)) return word;
152 return upperFirstLowerRest(word);
153 })
154 .join("");
155 case "title":
156 return words
157 .map((word) => {
158 if (isAcronym(word) || isMixedCase(word)) return word;
159 return upperFirstLowerRest(word);
160 })
161 .join(" ");
162 case "slug": {
163 const slug = words.map((w) => w.toLowerCase()).join("-");
164 if (isReservedWindowsDeviceName(slug)) return `${slug}-`;
165 return slug;
166 }
167 default:
168 return input;
169 }
170}

Callers 3

applyValueTextOptionsFunction · 0.90
getChunkProbeVariantsFunction · 0.90

Calls 7

normalizeStyleFunction · 0.85
tokenizeWordsFunction · 0.85
isLowerLeadingBrandTokenFunction · 0.85
isAcronymFunction · 0.85
isMixedCaseFunction · 0.85
upperFirstLowerRestFunction · 0.85

Tested by

no test coverage detected