copy-share
v1.2.6
Published
A JavaScript library for copying text, images, videos, links, and code to the clipboard with advanced notification and history management features.
Downloads
76
Maintainers
Readme
CopyShare is a lightweight JavaScript library that provides easy and versatile clipboard operations. It allows you to copy text, code, images, video URLs, and links to the clipboard, with built-in error handling and history management.
Features
Copy Text: Safely copy plain text to the clipboard.
Copy Code: Copy code snippets with syntax sanitization.
Copy Image: Copy images directly to the clipboard or as URLs.
Copy Video URL: Copy video URLs to the clipboard.
Copy Link: Copy HTML links to the clipboard.
History Management: Track copied items and clear history.
Installation
To install CopyShare, use npm:
npm install copy-share
Quick Start
To quickly start using CopyShare in your web project:
- Add this script tag to your HTML:
<script type="module">
import { copyText } from 'https://cdn.jsdelivr.net/npm/copy-share/copyShare.min.js';
// Get the button element
const btn = document.querySelector('#btn');
// Add click event listener to the button
btn.addEventListener('click', () => {
// Get the text from the input element
const text = document.querySelector('#text').value;
// Copy the text to clipboard using copyText function
copyText(text);
});
</script>
Usage
Option 1: Import the Entire Library
:
You can import the entire library and use the methods via the copyShare object:
import copyShare from 'copy-share';
copyShare.copyText('Hello, Adam!');
Option 2: Use Named Imports
:
Alternatively, you can import specific methods directly:
import { copyText, copyCode } from 'copy-share';
copyText('Hello, Adam!');
copyCode('console.log("Hello, world!");', 'javascript');