Skip to content

invertCase ​

Inverts the case of each character in a string: uppercase becomes lowercase and vice versa.

Syntax ​

typescript
invertCase(str: string): string

Parameters ​

ParameterTypeDescription
strstringThe string to be processed.

Returns ​

TypeDescription
stringA new string with the case of each character inverted.

Example ​

typescript
invertCase("AbC"); // "aBc"
invertCase("Olá MUNDO!"); // "oLÁ mundo!"
invertCase(""); // ""

Notes ​

  • Throws TypeError if the argument is not a string.
  • Non-alphabetic characters remain unchanged.

References ​

Released under the MIT License.