910 B30 lines
Blame
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8import platform from './platform';
9
10/** Copy text to the clipboard */
11export function clipboardCopyText(text: string) {
12 return platform.clipboardCopy(text);
13}
14
15/**
16 * Copy text that refers to a URL to the clipboard.
17 * If pasted into a rich text input, it will paste as text with a URL link.
18 * If pasted into a plain text input, it will just use the text without the url.
19 */
20export function clipboardCopyLink(text: string, url: string) {
21 return platform.clipboardCopy(text, clipboardLinkHtml(text, url));
22}
23
24/**
25 * HTML <a> tag for `text` pointing to `url`. Useful for copying rich text links.
26 */
27export function clipboardLinkHtml(text: string, url: string): string {
28 return `<a href="${url}">${text}</a>`;
29}
30