copy-async

复制文本、富文本到剪切板

usage

npm i copy-rich-text
1


 
 
 
 

import copy from 'copy-rich-text';

await copy('hello world');
await copy('<h1>hello world</h1>');
await copy(document.querySelector('#rich-text'));
await copy(document.querySelector('#rich-text'), { html: true });
1
2
3
4
5
6

demos

api

export declare const version = "0.2.0";
export * from './copy';
export { copy as default } from './copy';
1
2
3
export declare type CopyOptions = {
    /**
     * @description 当传入 string 时,复制原始 html 字符串。
     * @description 当传入 HTMLElement 时,复制其 innerHTML
     * @description 默认 false,普通字符串无差别。
     * */
    html?: boolean;
};
/**
 * @description copy,一个promise化的拷贝函数,支持传入文本、dom
 */
export declare function copy(textOrElement: string | HTMLElement, options?: CopyOptions): Promise<void>;
1
2
3
4
5
6
7
8
9
10
11
12

1