Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/feross/clipboard-copy
Lightweight copy to clipboard for the web
https://github.com/feross/clipboard-copy
browser browserify clipboard clipboard-copy clipboard-js clipboardjs copy javascript
Last synced: 18 days ago
JSON representation
Lightweight copy to clipboard for the web
- Host: GitHub
- URL: https://github.com/feross/clipboard-copy
- Owner: feross
- License: mit
- Created: 2017-03-17T23:19:11.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-08-11T10:28:19.000Z (about 3 years ago)
- Last Synced: 2024-04-13T17:20:18.539Z (7 months ago)
- Topics: browser, browserify, clipboard, clipboard-copy, clipboard-js, clipboardjs, copy, javascript
- Language: JavaScript
- Homepage:
- Size: 44.9 KB
- Stars: 609
- Watchers: 12
- Forks: 40
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# clipboard-copy [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![size][size-image]][size-url] [![javascript style guide][standard-image]][standard-url]
[travis-image]: https://img.shields.io/travis/feross/clipboard-copy/master.svg
[travis-url]: https://travis-ci.org/feross/clipboard-copy
[npm-image]: https://img.shields.io/npm/v/clipboard-copy.svg
[npm-url]: https://npmjs.org/package/clipboard-copy
[downloads-image]: https://img.shields.io/npm/dm/clipboard-copy.svg
[downloads-url]: https://npmjs.org/package/clipboard-copy
[size-image]: https://img.shields.io/bundlephobia/minzip/clipboard-copy
[size-url]: https://bundlephobia.com/result?p=clipboard-copy
[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
[standard-url]: https://standardjs.com### Lightweight copy to clipboard for the web
The goal of this package is to offer simple copy-to-clipboard functionality in
modern web browsers using the fewest bytes. To do so, this package only supports
modern browsers. No fallback using Adobe Flash, no hacks. Just 30 lines of code.Unlike other implementations, text copied with `clipboard-copy` is clean and
unstyled. Copied text will not inherit HTML/CSS styling like the page's background
color.**Supported browsers:** Chrome, Firefox, Edge, Safari.
Works in the browser with [browserify](http://browserify.org/)!
## install
```
npm install clipboard-copy
```## usage
```js
const copy = require('clipboard-copy')button.addEventListener('click', function () {
copy('This is some cool text')
})
```## API
### `successPromise = copy(text)`
Copy the given text to the user's clipboard. Returns `successPromise`, a promise that resolves if the copy was successful and rejects if the copy failed.
Note: in most browsers, copying to the clipboard is only allowed if `copy()` is
triggered in direct response to a user gesture like a `'click'` or a `'keypress'`.## comparison to alternatives
- **`clipboard-copy` (this package): [508 B gzipped](https://bundlephobia.com/result?p=clipboard-copy)**
- [`clipboard-js`](https://www.npmjs.com/package/clipboard-js): [1.7 kB gzipped](https://bundlephobia.com/result?p=clipboard-js)
- [`clipboard`](https://www.npmjs.com/package/clipboard): [3.2 kB gzipped](https://bundlephobia.com/result?p=clipboard)## testing
Testing this module is currently a manual process. Open `test.html` in your web browser and follow the short instructions. The web page will always load the latest version of the module, no bundling is necessary.
## license
MIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org).