Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clipboard

Package Overview
Dependencies
Maintainers
3
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clipboard

Modern copy to clipboard. No Flash. Just 2kb

  • 2.0.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4M
decreased by-11.13%
Maintainers
3
Weekly downloads
 
Created

What is clipboard?

The clipboard npm package is a simple interface for copying text to the clipboard. It does not rely on Flash and is typically used in web applications to enhance the user experience by providing copy-to-clipboard functionality with minimal effort.

What are clipboard's main functionalities?

Copy text from a trigger element

This code binds a new ClipboardJS instance to elements with the class 'btn'. When these elements are clicked, the text target they are associated with is copied to the clipboard.

new ClipboardJS('.btn');

Copy text programmatically

This code allows you to define a function that returns the text to be copied when the trigger element is activated.

const clipboard = new ClipboardJS('.btn', { text: function(trigger) { return 'Text to copy'; } });

Cut text from an input

This code sets up the clipboard instance to cut text from an input field when the trigger element is used.

new ClipboardJS('.btn', { action: function(trigger) { return 'cut'; } });

Customize via data attributes

This HTML markup shows how to use data attributes to specify the text to be copied when the button is clicked.

<button class='btn' data-clipboard-text='Text to copy'>Copy</button>

Event handling

This code adds an event listener for the 'success' event, which is fired when text is successfully copied to the clipboard. It logs information about the event and clears the selection.

clipboard.on('success', function(e) { console.info('Action:', e.action); console.info('Text:', e.text); console.info('Trigger:', e.trigger); e.clearSelection(); });

Other packages similar to clipboard

Keywords

FAQs

Package last updated on 02 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc