Skip to content

Commit

Permalink
utils: Add function to facilitate copying texts
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellehmkuhl committed Jan 24, 2025
1 parent f105fd8 commit 6638347
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/libs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,16 @@ export const isElectron = (): boolean => {

return false
}

/**
* Copy text to clipboard
* @param {string} text The text to copy
* @returns {Promise<void>} A promise that resolves when the text is copied
*/
export const copyToClipboard = async (text: string): Promise<void> => {
try {
await navigator.clipboard.writeText(text)
} catch (err) {
throw new Error(`Failed to copy text. Error: ${err}`)
}
}

0 comments on commit 6638347

Please sign in to comment.