UNPKG

@exabytellc/utils

Version:

EB react utils to make everything a little easier!

21 lines (20 loc) 666 B
import { handleTryCatch } from "../_helpers/handleError"; import { isStr } from "../types"; /** * Copies the provided text to the clipboard. * @param {string} text - The text to copy to the clipboard. * @param {string} [alertText="Data copied to clipboard"] - Optional text to display in an alert after copying. * @returns {boolean} - True if the text was successfully copied; otherwise, false. */ export default function copyToClipboard(text) { return handleTryCatch({ n: "copyToClipboard", c: !isStr(text), p: { text }, f: false, e: () => { navigator.clipboard.writeText(text); return true; } }); }