Socket
Socket
Sign inDemoInstall

clipboard

Package Overview
Dependencies
1
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

clipboard


Version published
Weekly downloads
1.2M
decreased by-20.95%
Maintainers
1
Created
Weekly downloads
 

Package description

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

Readme

Source

node-clipboard

Easy to use utility for reading and writing to the system clipboard.

usage

npm install node-clipboard
var clipboard = require('node-clipboard');

// _Read_
var fromClipboard = clipboard.read();     // defaults to ascii
fromClipboard = clipboard.read('bitmap'); // buffer
fromClipboard = clipboard.readAll();      // all formats

// _Write_
clipboard.write('some text');
clipboard.write([
	{ format: 'ascii', value: 'some text' },
	{ format: 'unicode', value: '\u1059\u0000etc' },
	{ format: 'bitmap', value: someBuffer }
]);

// _Clear_
clipboard.clear();

// _Iterate_

// clipboard.formats() is a shortcut for:

var formats = clipboard.iterate(function(format, formatName, isCustom){
	return formatName;
});

FAQs

Last updated on 17 Feb 2012

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc