Socket
Socket
Sign inDemoInstall

copy-to-clipboard

Package Overview
Dependencies
1
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.2.1 to 3.3.0

2

example/index.js

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

!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).copyToClipboard=e()}}(function(){return function a(i,l,c){function s(t,e){if(!l[t]){if(!i[t]){var o="function"==typeof require&&require;if(!e&&o)return o(t,!0);if(u)return u(t,!0);var n=new Error("Cannot find module '"+t+"'");throw n.code="MODULE_NOT_FOUND",n}var r=l[t]={exports:{}};i[t][0].call(r.exports,function(e){return s(i[t][1][e]||e)},r,r.exports,a,i,l,c)}return l[t].exports}for(var u="function"==typeof require&&require,e=0;e<c.length;e++)s(c[e]);return s}({1:[function(e,t,o){"use strict";var s=e("toggle-selection"),u={"text/plain":"Text","text/html":"Url",default:"Text"};t.exports=function(o,n){var r,t,e,a,i,l,c=!1;r=(n=n||{}).debug||!1;try{if(e=s(),a=document.createRange(),i=document.getSelection(),(l=document.createElement("span")).textContent=o,l.style.all="unset",l.style.position="fixed",l.style.top=0,l.style.clip="rect(0, 0, 0, 0)",l.style.whiteSpace="pre",l.style.webkitUserSelect="text",l.style.MozUserSelect="text",l.style.msUserSelect="text",l.style.userSelect="text",l.addEventListener("copy",function(e){if(e.stopPropagation(),n.format)if(e.preventDefault(),void 0===e.clipboardData){r&&console.warn("unable to use e.clipboardData"),r&&console.warn("trying IE specific stuff"),window.clipboardData.clearData();var t=u[n.format]||u.default;window.clipboardData.setData(t,o)}else e.clipboardData.clearData(),e.clipboardData.setData(n.format,o)}),document.body.appendChild(l),a.selectNodeContents(l),i.addRange(a),!document.execCommand("copy"))throw new Error("copy command was unsuccessful");c=!0}catch(e){r&&console.error("unable to copy using execCommand: ",e),r&&console.error("unable to copy using clipboardData: ",e),r&&console.error("falling back to prompt"),t=function(e){var t=(/mac os x/i.test(navigator.userAgent)?"⌘":"Ctrl")+"+C";return e.replace(/#{\s*key\s*}/g,t)}("message"in n?n.message:"Copy to clipboard: #{key}, Enter"),window.prompt(t,o)}finally{i&&("function"==typeof i.removeRange?i.removeRange(a):i.removeAllRanges()),l&&document.body.removeChild(l),e()}return c}},{"toggle-selection":2}],2:[function(e,t,o){t.exports=function(){var t=document.getSelection();if(!t.rangeCount)return function(){};for(var e=document.activeElement,o=[],n=0;n<t.rangeCount;n++)o.push(t.getRangeAt(n));switch(e.tagName.toUpperCase()){case"INPUT":case"TEXTAREA":e.blur();break;default:e=null}return t.removeAllRanges(),function(){"Caret"===t.type&&t.removeAllRanges(),t.rangeCount||o.forEach(function(e){t.addRange(e)}),e&&e.focus()}}},{}]},{},[1])(1)});
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).copyToClipboard=e()}}(function(){return function a(i,c,l){function s(t,e){if(!c[t]){if(!i[t]){var o="function"==typeof require&&require;if(!e&&o)return o(t,!0);if(u)return u(t,!0);var n=new Error("Cannot find module '"+t+"'");throw n.code="MODULE_NOT_FOUND",n}var r=c[t]={exports:{}};i[t][0].call(r.exports,function(e){return s(i[t][1][e]||e)},r,r.exports,a,i,c,l)}return c[t].exports}for(var u="function"==typeof require&&require,e=0;e<l.length;e++)s(l[e]);return s}({1:[function(e,t,o){"use strict";var s=e("toggle-selection"),u={"text/plain":"Text","text/html":"Url",default:"Text"};t.exports=function(o,n){var r,t,e,a,i,c,l=!1;n||(n={}),r=n.debug||!1;try{if(e=s(),a=document.createRange(),i=document.getSelection(),(c=document.createElement("span")).textContent=o,c.style.all="unset",c.style.position="fixed",c.style.top=0,c.style.clip="rect(0, 0, 0, 0)",c.style.whiteSpace="pre",c.style.webkitUserSelect="text",c.style.MozUserSelect="text",c.style.msUserSelect="text",c.style.userSelect="text",c.addEventListener("copy",function(e){if(e.stopPropagation(),n.format)if(e.preventDefault(),void 0===e.clipboardData){r&&console.warn("unable to use e.clipboardData"),r&&console.warn("trying IE specific stuff"),window.clipboardData.clearData();var t=u[n.format]||u.default;window.clipboardData.setData(t,o)}else e.clipboardData.clearData(),e.clipboardData.setData(n.format,o);n.onCopy&&(e.preventDefault(),n.onCopy(e.clipboardData))}),document.body.appendChild(c),a.selectNodeContents(c),i.addRange(a),!document.execCommand("copy"))throw new Error("copy command was unsuccessful");l=!0}catch(e){r&&console.error("unable to copy using execCommand: ",e),r&&console.warn("trying IE specific stuff");try{window.clipboardData.setData(n.format||"text",o),n.onCopy&&n.onCopy(window.clipboardData),l=!0}catch(e){r&&console.error("unable to copy using clipboardData: ",e),r&&console.error("falling back to prompt"),t=function(e){var t=(/mac os x/i.test(navigator.userAgent)?"⌘":"Ctrl")+"+C";return e.replace(/#{\s*key\s*}/g,t)}("message"in n?n.message:"Copy to clipboard: #{key}, Enter"),window.prompt(t,o)}}finally{i&&("function"==typeof i.removeRange?i.removeRange(a):i.removeAllRanges()),c&&document.body.removeChild(c),e()}return l}},{"toggle-selection":2}],2:[function(e,t,o){t.exports=function(){var t=document.getSelection();if(!t.rangeCount)return function(){};for(var e=document.activeElement,o=[],n=0;n<t.rangeCount;n++)o.push(t.getRangeAt(n));switch(e.tagName.toUpperCase()){case"INPUT":case"TEXTAREA":e.blur();break;default:e=null}return t.removeAllRanges(),function(){"Caret"===t.type&&t.removeAllRanges(),t.rangeCount||o.forEach(function(e){t.addRange(e)}),e&&e.focus()}}},{}]},{},[1])(1)});

@@ -9,2 +9,3 @@ // Type definitions for copy-to-clipboard 3.0

format?: string; // MIME type
onCopy?: function(clipboardData: object): void;
}

@@ -11,0 +12,0 @@

@@ -66,2 +66,6 @@ "use strict";

}
if (options.onCopy) {
e.preventDefault();
options.onCopy(e.clipboardData);
}
});

@@ -81,6 +85,13 @@

debug && console.error("unable to copy using execCommand: ", err);
debug && console.error("unable to copy using clipboardData: ", err);
debug && console.error("falling back to prompt");
message = format("message" in options ? options.message : defaultMessage);
window.prompt(message, text);
debug && console.warn("trying IE specific stuff");
try {
window.clipboardData.setData(options.format || "text", text);
options.onCopy && options.onCopy(window.clipboardData);
success = true;
} catch (err) {
debug && console.error("unable to copy using clipboardData: ", err);
debug && console.error("falling back to prompt");
message = format("message" in options ? options.message : defaultMessage);
window.prompt(message, text);
}
} finally {

@@ -87,0 +98,0 @@ if (selection) {

{
"name": "copy-to-clipboard",
"version": "3.2.1",
"version": "3.3.0",
"description": "Copy stuff into clipboard using JS with fallbacks",

@@ -5,0 +5,0 @@ "main": "index.js",

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

|options.format|"text/html"| `String`. Optional. Set the MIME type of what you want to copy as. Use `text/html` to copy as HTML, `text/plain` to avoid inherited styles showing when pasted into rich text editor. |
|options.onCopy|null| `function onCopy(clipboardData: object): void`. Optional. Receives the clipboardData element for adding custom behavior such as additional formats |

@@ -30,0 +31,0 @@ `*` all occurrences of `#{key}` are replaced with `⌘+C` for macOS/iOS users, and `Ctrl+C` otherwise.

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