UNPKG

shevchenko

Version:

JavaScript library for declension of Ukrainian anthroponyms

47 lines (45 loc) 1.51 kB
/** * @file JavaScript library for declension of Ukrainian anthroponyms * @module shevchenko * @version 3.1.4 * @author Oleksandr Tolochko <shevchenko-js@tooleks.com> * @license MIT * @copyright 2017-2025 Oleksandr Tolochko <shevchenko-js@tooleks.com> * @see {@link git+https://github.com/tooleks/shevchenko-js.git} */ /** * Copies a letter case pattern from a template word to a target word. * Returns a modified target word in the letter case of the template word. */ function copyLetterCase(templateWord, targetWord) { let resultWord = ''; for (let index = 0; index < targetWord.length; index += 1) { const templateLetter = templateWord[index] || templateWord[templateWord.length - 1]; const targetLetter = targetWord[index]; if (inLowerCase(templateLetter)) { resultWord += targetLetter.toLowerCase(); } else if (inUpperCase(templateLetter)) { resultWord += targetLetter.toUpperCase(); } else { resultWord += targetLetter; } } return resultWord; } /** * Detects if a letter is in the upper case at the specified index. */ function inUpperCase(word, index = 0) { const letter = word.charAt(index); return letter === letter.toUpperCase(); } /** * Detects if a letter is in the lower case at the specified index. */ function inLowerCase(word, index = 0) { const letter = word.charAt(index); return letter === letter.toLowerCase(); } export { copyLetterCase };