1. clipboard-copy
Lightweight copy to clipboard for the web
clipboard-copy
Package: clipboard-copy
Created by: feross
Last modified: Mon, 13 Jun 2022 06:10:49 GMT
Version: 4.0.1
License: MIT
Downloads: 1,381,249
Repository: https://github.com/feross/clipboard-copy

Install

npm install clipboard-copy
yarn add clipboard-copy

clipboard-copy travis npm downloads size javascript style guide

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!

install

npm install clipboard-copy

usage

 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

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.

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code