UNPKG

@technobuddha/library

Version:
37 lines (36 loc) 1.5 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.matchCase = void 0; var isLowerCase_1 = __importDefault(require("../isLowerCase")); var isUpperCase_1 = __importDefault(require("../isUpperCase")); var toCapitalCase_1 = __importDefault(require("../toCapitalCase")); var toSmallCase_1 = __importDefault(require("../toSmallCase")); /** * Attempt to convert the input string into the same case as the target string * * @remarks The best guess is made to try to figure out what case the target is in: * * lowercase * * UPPERCASE * * Capitalcase * * sMALLCASE * * @param input The input string * @param target The target string * @returns The input in the case case as the target string */ function matchCase(input, target) { if (isLowerCase_1.default(target)) return input.toLowerCase(); else if (isUpperCase_1.default(target)) return input.toUpperCase(); else if (target.length > 1 && isUpperCase_1.default(target[0]) && isLowerCase_1.default(target.slice(1))) return toCapitalCase_1.default(input, { lowerCase: true }); else if (target.length > 1 && isLowerCase_1.default(target[0]) && isUpperCase_1.default(target.slice(1))) return toSmallCase_1.default(input, { upperCase: true }); return input; } exports.matchCase = matchCase; exports.default = matchCase;