• Stars
    star
    1,317
  • Rank 35,709 (Top 0.8 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Copy stuff into clipboard from your browser using JS

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.

Value Default Notes
options.debug false Boolean. Optional. Enable output to console.
options.message Copy to clipboard: #{key}, Enter String. 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.onCopy null function 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';

More Repositories

1

reveal-cleaver-theme

Reveal.js theme for cleaver slides
CSS
29
star
2

copy-button

Web component to copy target text/dom-node value to clipboard
JavaScript
18
star
3

toggle-selection

Remove user selection and then get it back on
JavaScript
15
star
4

nlp-how-to-annotate

Set of guides and references for annotating NLP data
13
star
5

cleaver-template

Jump start your cleaver presentation in no time.
JavaScript
11
star
6

react-textarea-highlight

JavaScript
8
star
7

slides

Some slides for/by me.
HTML
5
star
8

cleaver-editor

Single page editor for cleaver slides in your browser
JavaScript
5
star
9

pivy-print

Easy print tool for task cards in pivotal tracker
JavaScript
4
star
10

raccit

JavaScript
3
star
11

five-cljs-game

Clojure
3
star
12

Rails-4-Streaming-Barcodes

Rails 4 app streaming server events using ActionController::Live and redis pub/sub mechanism for barcode database added by users.
Ruby
3
star
13

gitter-data

CLI tool to dump selected REPO related rooms in Gitter you are part off
Clojure
2
star
14

aleph-box

No backend javascript anything stubber aka Chance.js without all the parens
JavaScript
2
star
15

contacts-firebase-angular

Simple contact app using firebase and angular. As test task for codeangels JS course.
CSS
2
star
16

offline-markdown-previewer

Goal is to create offline previewer for repos with markdown docs similar to github's web interface
JavaScript
1
star
17

fish-npm-scripts-completion

Nevermind, just use oficial thing from fish-shell repo
Shell
1
star
18

exit-on-dirty-git

Exit with status code (1) if something is uncommited in current tree
JavaScript
1
star
19

erl-hw

Homeworks for kottans erlang courses.
Erlang
1
star
20

currency-exchange

JavaScript
1
star
21

Simple-Backbone-App

CoffeeScript
1
star
22

GarageCourse2-Homework

Ruby
1
star