3.3.3 • Published 2 years ago

copy-to-clipboard v3.3.3

Weekly downloads
3,379,014
License
MIT
Repository
github
Last release
2 years ago

Copy to clipboard Build Status

Simple module exposing copy function that will try to use execCommand with fallback to IE-specific clipboardData interface and finally, resort to usual prompt with proper text content and message.

If you are building using Electron, use their API.

Example

import copy from 'copy-to-clipboard';

copy('Text');

// Copy with options
copy('Text', {
  debug: true,
  message: 'Press #{key} to copy',
});

API

copy(text: string, options: object): boolean tries to copy text to clipboard. Returns true if no additional keystrokes were required from user (so, execCommand, IE's clipboardData worked) or false.

ValueDefaultNotes
options.debugfalseBoolean. Optional. Enable output to console.
options.messageCopy to clipboard: #{key}, EnterString. Optional. Prompt message. *
options.format"text/html"String. Optional. Set the MIME type of what you want to copy as. Use text/html to copy as HTML, text/plain to avoid inherited styles showing when pasted into rich text editor.
options.onCopynullfunction onCopy(clipboardData: object): void. Optional. Receives the clipboardData element for adding custom behavior such as additional formats

* all occurrences of #{key} are replaced with ⌘+C for macOS/iOS users, and Ctrl+C otherwise.

Browser support

Works everywhere where prompt* is available. Works best (i.e. without additional keystrokes) in Chrome, FF, Safari 10+, and, supposedly, IE/Edge.

Note: does not work on some older iOS devices.
* – even though Safari 8 has prompt, you cannot specify prefilled content for prompt modal – thus it doesn't work as expected.

Installation

  • Can be used as npm package and then leveraged using commonjs bundler/loader:
npm i --save copy-to-clipboard
  • Can be utilized using wzrd.in. Add following script to your page:
<script src="https://wzrd.in/standalone/copy-to-clipboard@latest" async></script>

You will have window.copyToClipboard exposed for you to use.

UI components based on this package:

See also:

Running Tests

This project has some automated tests, that will run using nightwatch on top of selenium.

npm i
npm test

Typescript

This library has built-in Typescript definitions.

import * as copy from 'copy-to-clipboard';
@storybook/addon-knobs@yattho/gatsby-theme-rigitus@atlr/kit@modern-js/doc-core@dterekhova/components@dterekhova/reducers@verticon/hooks@do-killer/dodo-wallet@do-killer/dodo-wallet2@flyteorg/console@flyteoss/consoledafunda-markdown-editordiscordrpcmaker@thirdweb-dev/react@uponco/admin-ui@mikibot/components@bushuai/uni-testrecipe-doc-siteyzhantdzuz.todt-ai-works@italk/test1creative-gallery-shonpbob-wallet@linkdesign/iot-componentsantd-zpgraphql-playground-react-auth@nebula.ui/engine-uig2_v587_gv587_adminjdc-rc-commontest-rc-commonfind-reactuibot-ui-antdyzxdformdstack-react@sellics/ui-kit@open-raven/react-styleguidemetta-editorss-ui-libadonuxt-testcheerego-redo-undo2signplsignpl-test@tyme-ui/hookszmj-c@meetup/build-meetup-web-componentstalent-app-shell@thesis-co/mechamittens-extensionspankpay-componentspublish-test-spankpay-componentsybbtestui1@stellaris/react-rich-editor@misakey/coredigital-inclusion-map@dustinnewman98/syntax-tree-genyw-supply@techsbcn/storybook-design@tradesolution/ts-react-iceberg@reverb-ui/test-react-package@rafcin/hookssite-tracking-tagsdgiot_amismdt-libaddnewer-uikontenbase-document-editorreactfaberhzero-bootantdscs-libgatsby-theme-arcadiagatsby-theme-arcadia-light@s97712/react-usexc-mobilexcmobiles@healform/ui-librarysimple-antd-management-fast-frameworksid-npm-test3sid-npmtest-1sid-npmtest-2sid-test-create-npm@voplus/antdcn-libcn-lib-4oliver-csupremind-components@cliffdotai/atomiconlinex-test@dibanka/demo@dodoex-io/walletdoc4k_react_uistudio-frontend-vireact-usiescn-4gumroad-api-tester-webappxqshoutenn-uiyopta-editorcn-2022@baolq/antd@beepsoft/ocho
3.3.3

2 years ago

3.3.2

2 years ago

3.3.1

5 years ago

3.3.0

5 years ago

3.2.1

5 years ago

3.2.0

6 years ago

3.1.0

6 years ago

3.0.9

6 years ago

3.0.8

7 years ago

3.0.7

7 years ago

3.0.6

8 years ago

3.0.5

8 years ago

3.0.4

8 years ago

3.0.3

8 years ago

3.0.2

8 years ago

3.0.1

8 years ago

3.0.0

9 years ago

2.1.0

9 years ago

2.0.0

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.4

9 years ago

1.0.2

9 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.0.0

10 years ago