MCPcopy Create free account
hub / github.com/Effect-TS/effect / normalizeCase

Function normalizeCase

packages/effect/src/String.ts:1249–1275  ·  view source on GitHub ↗
(
  input: string,
  splitRegExp: ReadonlyArray<RegExp>,
  stripRegExp: ReadonlyArray<RegExp>,
  delimiter: string,
  transform: (part: string, index: number, parts: ReadonlyArray<string>) => string
)

Source from the content-addressed store, hash-verified

1247 predicate.isRegExp(regexp) ? [regexp] : regexp
1248
1249const 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").

Callers 2

String.tsFile · 0.85
configCaseFunction · 0.85

Calls 4

joinMethod · 0.80
replaceMethod · 0.45
mapMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected