Skip to main content

Built and signed on GitHub Actions

This is my helper functions

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
2 months ago (0.2.2)
function copyToClipboard
copyToClipboard(
text: string,
option?: { onSuccess: (data: string) => void; onError: (error: unknown) => void; },
): Promise<void>

Copy text to the clipboard.

/!\ Works only in browser /!\

Examples

Example 1

import { copyToClipboard } from './copyToClipboard';

copyToClipboard('Hello, World!', {
	onSuccess: (data) => console.log(`Copied: ${data}`),
	onError: (error) => console.error('Error:', error),
});

Parameters

text: string
  • The text to copy to the clipboard.
optional
option: { onSuccess: (data: string) => void; onError: (error: unknown) => void; }
  • An object containing the onSuccess and onError callback functions.

Return Type

Promise<void>

A promise that resolves when the text has been copied to the clipboard.

Add Package

deno add jsr:@pifplif/utils

Import symbol

import { copyToClipboard } from "@pifplif/utils";

---- OR ----

Import directly with a jsr specifier

import { copyToClipboard } from "jsr:@pifplif/utils";

Add Package

npx jsr add @pifplif/utils

Import symbol

import { copyToClipboard } from "@pifplif/utils";

Add Package

yarn dlx jsr add @pifplif/utils

Import symbol

import { copyToClipboard } from "@pifplif/utils";

Add Package

pnpm dlx jsr add @pifplif/utils

Import symbol

import { copyToClipboard } from "@pifplif/utils";

Add Package

bunx jsr add @pifplif/utils

Import symbol

import { copyToClipboard } from "@pifplif/utils";