1.0.0 • Published 4 months ago

clipboard-service v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Clipboard Service

The clipboard-service package is a lightweight, easy-to-use library that simplifies interaction with the browser’s Clipboard API. With ClipboardService, you can easily read from and write to the clipboard with just a few lines of code. It provides a straightforward, promise-based API for copying and pasting text or other content, allowing you to focus on building your application without worrying about clipboard intricacies.

Getting Started

Install the package:

npm install -S clipboard-service

Usage

import { ClipboardService } from 'clipboard-service';

// check if the Clipboard API is supported by the browser
if (ClipboardService.isCompatible) {
  // write text to the system clipboard
  try {
    await ClipboardService.writeText(code);
  } catch (e) {
    console.error(e);
  }

  // request text from the system clipboard
  try {
    const otpToken = await ClipboardService.readText();
  } catch (e) {
    console.error(e);
  }
}

Types

type IClipboardItem = ClipboardItem;

Object in charge of interacting with the Clipboard API.

type IClipboardService = {
  // properties
  isSupported: boolean;

  // actions
  write: (data: IClipboardItem[]) => Promise<void>;
  writeText: (data: string) => Promise<void>;
  read: () => Promise<IClipboardItem[]>;
  readText: () => Promise<string>;
};

Built With

  • TypeScript

Running the Tests

# integration tests
npm run test:integration

# unit tests
npm run test:unit

License

MIT

Deployment

Install dependencies:

npm install

Build the library:

npm start

Publish to npm:

npm publish
1.0.0

4 months ago