(input: string, style?: string)
| 118 | } |
| 119 | |
| 120 | export 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 | } |
no test coverage detected