https://github.com/shrpne/clipbrd
Lightweight copy to clipboard for modern browsers
https://github.com/shrpne/clipbrd
browser clipboard copy javascript support
Last synced: 15 days ago
JSON representation
Lightweight copy to clipboard for modern browsers
- Host: GitHub
- URL: https://github.com/shrpne/clipbrd
- Owner: shrpne
- License: mit
- Created: 2018-07-25T23:06:30.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-08-29T10:02:13.000Z (8 months ago)
- Last Synced: 2025-04-10T10:42:02.033Z (17 days ago)
- Topics: browser, clipboard, copy, javascript, support
- Language: JavaScript
- Size: 86.9 KB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# clipbrd
[](https://www.npmjs.org/package/clipbrd)
[](https://bundlephobia.com/result?p=clipbrd)
[](https://travis-ci.com/shrpne/clipbrd)
[](https://github.com/shrpne/clipbrd/blob/master/LICENSE)Lightweight module to copy text to the clipboard in modern browsers *(< 1kB minified)*
[Demo JSFiddle](https://jsfiddle.net/shrpne/eyw596nz/)
## Install
```
npm install clipbrd
```## Usage
```js
import * as clipboard from 'clipbrd';if (clipboard.isSupported()) {
button.addEventListener('click', () => {
clipboard.copy('Custom text');
});
}
```## API
### copy(text)
Copy `text` to the clipboard.
Returns a `boolean` of whether it succeeded.
Must be called in response to a user gesture event, like `click` or `keyup`.
### isSupported()
Check if copy is supported, that way you can hide copy buttons from the UI.
Returns a `boolean`
## Reference
- [hackernoon.com/copying-text-to-clipboard-with-javascript](https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f) - Original Hackernoon article
- [copy-text-to-clipboard](https://github.com/sindresorhus/copy-text-to-clipboard) - Pulled fixes from battle tested realization
- [clipboard.js](https://github.com/zenorocha/clipboard.js/) - Pulled support method## License
MIT License