@azizbecha/strkit
Version:
strkit is a utility library offering a collection of essential string functions including validation, case conversion, truncation, and more. Ideal for both JavaScript and TypeScript developers to simplify string operations in their applications.
33 lines • 969 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = invertCase;
/**
* Inverts the case of each character in the input string.
* Uppercase characters are converted to lowercase, and lowercase characters are converted to uppercase.
* Non-alphabetical characters remain unchanged.
*
* @param input - The input string to invert case.
* @returns A new string with inverted case for each character.
*
* @example
* // Invert case of a simple string
* invertCase("Hello World!"); // "hELLO wORLD!"
*
* @example
* // Handle mixed case and non-alphabetical characters
* invertCase("123aBc#"); // "123AbC#"
*/
function invertCase(input) {
return input
.split('')
.map((char) => {
if (char === char.toLowerCase()) {
return char.toUpperCase();
}
else {
return char.toLowerCase();
}
})
.join('');
}
//# sourceMappingURL=invertCase.js.map