Socket
Socket
Sign inDemoInstall

copy-text-to-clipboard

Package Overview
Dependencies
0
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.1 to 2.2.0

28

index.d.ts

@@ -0,1 +1,27 @@

/// <reference lib="dom"/>
declare namespace copyTextToClipboard {
interface Options {
/**
Specify a DOM element where the temporary, behind-the-scenes `textarea` should be appended, in cases where you need to stay within a focus trap, like in a modal.
@default document.body
@example
```
import copy = require('copy-text-to-clipboard');
const modalWithFocusTrap = document.getElementById('modal');
button.addEventListener('click', () => {
copy('🦄🌈', {
target: modalWithFocusTrap
});
});
```
*/
target?: HTMLElement;
}
}
declare const copyTextToClipboard: {

@@ -19,3 +45,3 @@ /**

*/
(text: string): boolean;
(text: string, options?: copyTextToClipboard.Options): boolean;

@@ -22,0 +48,0 @@ // TODO: Remove this for the next major release, refactor the whole definition to:

4

index.js
'use strict';
const copyTextToClipboard = input => {
const copyTextToClipboard = (input, {target = document.body} = {}) => {
const element = document.createElement('textarea');

@@ -23,3 +23,3 @@ const previouslyFocusedElement = document.activeElement;

document.body.append(element);
target.append(element);
element.select();

@@ -26,0 +26,0 @@

{
"name": "copy-text-to-clipboard",
"version": "2.1.1",
"version": "2.2.0",
"description": "Copy text to the clipboard in modern browsers (0.2 kB)",
"license": "MIT",
"repository": "sindresorhus/copy-text-to-clipboard",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},

@@ -12,0 +13,0 @@ "engines": {

@@ -7,3 +7,2 @@ # copy-text-to-clipboard [![Build Status](https://travis-ci.org/sindresorhus/copy-text-to-clipboard.svg?branch=master)](https://travis-ci.org/sindresorhus/copy-text-to-clipboard)

## Comparison

@@ -14,3 +13,2 @@

## Install

@@ -22,3 +20,2 @@

## Usage

@@ -34,6 +31,5 @@

## API
### copy(text)
### copy(text, options?)

@@ -46,5 +42,15 @@ Copy `text` to the clipboard.

#### options
Type: `object`
##### target
Type: `HTMLElement`\
Default: `document.body`
Specify a DOM element where the temporary, behind-the-scenes `textarea` should be appended, in cases where you need to stay within a focus trap, like in a modal.
## Related
- [clipboardy](https://github.com/sindresorhus/clipboardy) - Access the system clipboard (copy/paste) in Node.js

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc