Launch Week Day 3: Introducing Organization Notifications in Socket.Learn More
Socket
Book a DemoSign in
Socket

clipboard-copy

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clipboard-copy - npm Package Compare versions

Comparing version
1.3.0
to
1.4.0
+41
test.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>clipboard-copy test</title>
</head>
<body>
<p>
1. Click this button: <button>Copy</button>
</p>
<p>
2. Paste into this input: <input />
</p>
<p>
3. Test status: <strong>pending</strong>
</p>
<script type="text/javascript">
window.module = {}
</script>
<script src="index.js"></script>
<script type="text/javascript">
var secret = Math.random().toFixed(10).slice(2)
function setStatus (success) {
document.querySelector('strong').style.color = (success ? 'green' : 'red')
document.querySelector('strong').textContent = (success ? 'passed' : 'failed')
}
document.querySelector('button').addEventListener('click', function () {
if (!window.module.exports(secret)) setStatus(false)
})
document.querySelector('input').addEventListener('input', function (ev) {
setStatus(ev.target.value === secret)
})
</script>
</body>
</html>
+1
-1
language: node_js
node_js:
- 'node'
- lts/*
module.exports = clipboardCopy
function clipboardCopy (text) {
// A <span> contains the text to copy
var span = document.createElement('span')
// Put the text to copy into a <span>
const span = document.createElement('span')
span.textContent = text
span.style.whiteSpace = 'pre' // Preserve consecutive spaces and newlines
// Preserve consecutive spaces and newlines
span.style.whiteSpace = 'pre'
// An <iframe> isolates the <span> from the page's styles
var iframe = document.createElement('iframe')
const iframe = document.createElement('iframe')
iframe.sandbox = 'allow-same-origin'
// Add the <iframe> to the page
document.body.appendChild(iframe)
var win = iframe.contentWindow
// Add the <span> to the <iframe>
let win = iframe.contentWindow
win.document.body.appendChild(span)
var selection = win.getSelection()
let selection = win.getSelection()

@@ -26,3 +31,3 @@ // Firefox fails to get a selection from <iframe> window, so fallback

var range = win.document.createRange()
const range = win.document.createRange()
selection.removeAllRanges()

@@ -32,3 +37,3 @@ range.selectNode(span)

var success = false
let success = false
try {

@@ -35,0 +40,0 @@ success = win.document.execCommand('copy')

{
"name": "clipboard-copy",
"description": "Lightweight copy to clipboard for the web",
"version": "1.3.0",
"version": "1.4.0",
"author": {
"name": "Feross Aboukhadijeh",
"email": "feross@feross.org",
"url": "http://feross.org/"
"url": "https://feross.org"
},

@@ -18,10 +18,10 @@ "bugs": {

"keywords": [
"browser",
"clipboard",
"clipboard copy",
"clipboard.js",
"copy",
"clipboard",
"simple",
"browser",
"copy to clipboard",
"clipboard.js",
"clipboard copy",
"modern browsers"
"modern browsers",
"simple"
],

@@ -28,0 +28,0 @@ "license": "MIT",

@@ -22,2 +22,4 @@ # clipboard-copy [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]

**Supported browsers:** Chrome, Firefox, Edge, Safari, IE11.
Works in the browser with [browserify](http://browserify.org/)!

@@ -56,4 +58,8 @@

## testing
Testing this module is currently a manual process. Open `test.html` in your web browser and follow the short instructions. The web page will always load the latest version of the module, no bundling is necessary.
## license
MIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org).