@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.
43 lines • 1.44 kB
JavaScript
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
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