clipbrd
v1.0.2
Published
Lightweight copy to clipboard for modern browsers
Downloads
1,328
Readme
clipbrd
Lightweight module to copy text to the clipboard in modern browsers (< 1kB minified)
Install
npm install clipbrd
Usage
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 - Original Hackernoon article
- copy-text-to-clipboard - Pulled fixes from battle tested realization
- clipboard.js - Pulled support method
License
MIT License