1.0.4 • Published 4 years ago

easyclip v1.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

easyclip

Copy string to clipboard. Just the basics. < 1kB.

Using in JS projects

CodeSandbox demo

Install using npm or yarn

npm install easy-clip
yarn add easy-clip
import copy from 'easyclip';

// copy 'Foobar' to clipboard
const buttonHandler = () => copy('Foobar');

Using in browser (HTML + Vanilla)

CodeSandbox demo

Load script using

<script src="https://cdn.jsdelivr.net/npm/easyclip@latest/dist/easyclip.min.js"></script>

Copy string to clipboard using function easyclip()

easyclip("string to copy")

For a full example

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Static Template</title>
  </head>
  <body>
    <div><button id="button">Copy date and time to clipboard</button></div>
    <p>Paste clipboard contents into textarea to test.</p>
    <textarea
      id="textarea"
      rows="20"
      cols="80"
      placeholder="Paste text here for testing..."
    ></textarea>
    <script src="https://cdn.jsdelivr.net/npm/easyclip@latest/dist/easyclip.min.js"></script>
    <script>
      window.addEventListener("load", function() {
        // wait until DOM is loaded before running scripts
        document.getElementById("button").addEventListener("click", function() {
          // copy current date to clipboard
          easyclip(new Date() + "\n");

          // bring focus to textarea for testing
          document.getElementById("textarea").focus();
        });
      });
    </script>
  </body>
</html>

Building

Install depedencies

yarn

Build to dist/

yarn build

The npm equivalents should work perfectly fine too.

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago