| 1247 | predicate.isRegExp(regexp) ? [regexp] : regexp |
| 1248 | |
| 1249 | const normalizeCase = ( |
| 1250 | input: string, |
| 1251 | splitRegExp: ReadonlyArray<RegExp>, |
| 1252 | stripRegExp: ReadonlyArray<RegExp>, |
| 1253 | delimiter: string, |
| 1254 | transform: (part: string, index: number, parts: ReadonlyArray<string>) => string |
| 1255 | ): string => { |
| 1256 | let result = input |
| 1257 | for (const regexp of splitRegExp) { |
| 1258 | result = result.replace(regexp, "$1\0$2") |
| 1259 | } |
| 1260 | for (const regexp of stripRegExp) { |
| 1261 | result = result.replace(regexp, "\0") |
| 1262 | } |
| 1263 | let start = 0 |
| 1264 | let end = result.length |
| 1265 | // Trim the delimiter from around the output string. |
| 1266 | while (result.charAt(start) === "\0") { |
| 1267 | start++ |
| 1268 | } |
| 1269 | while (result.charAt(end - 1) === "\0") { |
| 1270 | end-- |
| 1271 | } |
| 1272 | |
| 1273 | // Transform each token independently. |
| 1274 | return result.slice(start, end).split("\0").map(transform).join(delimiter) |
| 1275 | } |
| 1276 | |
| 1277 | // Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case") |
| 1278 | // and digit boundaries ("camel2case" -> "camel 2 case"). |