export function highlightCharacter(str, char, charClass) {
    if (!str.includes(char)) {
        return str;
    }

    const pattern = new RegExp(`\\${char}+`, "g");
    const replacement = `<span class="${charClass}">$&</span>`;

    return str.replace(pattern, replacement);
}

export function createImageElements(images, alt) {
    return images.map((link) => {
        return $('<img>').attr('src', link).attr('alt', alt);
    })
}

export function countLetters(str) {
    const letterRegex = /[a-zA-Z]/g;
    const matchedLetters = str.match(letterRegex);
    return matchedLetters ? matchedLetters.length : 0;
}

export function scrollToTop($element) {
    $element.scrollTop(0);
}

export function isHasSymbol(str, symbol) {
    return str.includes(symbol);
}

export function isKeyboardOpen() {
    const screenHeight = window.innerHeight;
    const screenHeightWithoutKeyboard = window.visualViewport.height;
    return screenHeight !== screenHeightWithoutKeyboard;
}
