All files / utils copyToClipboard.ts

53.33% Statements 8/15
50% Branches 1/2
50% Functions 2/4
53.33% Lines 8/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29  1x 1x                       1x 1x 1x 1x             1x     1x  
function copyToClipboard(generatedString: string) {
    const copyText = new Promise((resolve) => {
        Iif (navigator.clipboard != undefined) {
            // Modern browsers
            navigator.clipboard.writeText(generatedString).then(
                function () {
                    resolve(true);
                },
                function (err) {
                    console.error("Could not copy text: ", err);
                }
            );
        } else {
            // Internet Explorer
            const el = document.createElement("textarea");
            el.value = generatedString;
            document.body.appendChild(el);
            el.focus();
            el.select();
            document.execCommand("copy");
            document.body.removeChild(el);
            resolve(true);
        }
    });
    return copyText;
}
 
export default copyToClipboard;