Comparing version 1.0.3 to 2.0.0
22
index.js
export async function clippie(content) { | ||
if (content instanceof Blob) { | ||
const item = new ClipboardItem({[content.type]: content}); // eslint-disable-line no-undef | ||
await navigator.clipboard.write([item]); | ||
} else { | ||
try { | ||
await navigator.clipboard.writeText(content); | ||
} catch { | ||
return fallback(content); | ||
try { | ||
if (content instanceof Blob) { | ||
const item = new ClipboardItem({[content.type]: content}); // eslint-disable-line no-undef | ||
await navigator.clipboard.write([item]); | ||
} else { | ||
try { | ||
await navigator.clipboard.writeText(content); | ||
} catch { | ||
return fallback(content); | ||
} | ||
} | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
return true; | ||
} | ||
@@ -14,0 +18,0 @@ |
{ | ||
"name": "clippie", | ||
"version": "1.0.3", | ||
"version": "2.0.0", | ||
"description": "Teeny-tiny browser clipboard copy", | ||
@@ -5,0 +5,0 @@ "author": "silverwind", |
# clippie | ||
[![](https://img.shields.io/npm/v/clippie.svg?style=flat)](https://www.npmjs.org/package/clippie) [![](https://img.shields.io/npm/dm/clippie.svg)](https://www.npmjs.org/package/clippie) [![](https://img.shields.io/bundlephobia/minzip/clippie.svg)](https://bundlephobia.com/package/clippie) | ||
`clippie` copies text and blobs to clipboard in Browsers. It relies on modern APIs that require a secure origin but also includes a fallback so it works on insecure origins. | ||
`clippie` copies text and images to clipboard in Browsers. Text copy works on both secure and insecure origins, image copy requires a secure origin. | ||
@@ -14,4 +14,4 @@ ## Usage | ||
// copy blob, also works with images | ||
const success = await clippie(new Blob("text to copy", "text/plain")); | ||
// copy image | ||
const success = await clippie(imageBlob); | ||
``` | ||
@@ -24,4 +24,4 @@ | ||
Returns `true` when sucessful. Will throw all exceptions except when it falls back to another method. | ||
Returns `true` when sucessful and `false` when not. Will never throw. | ||
© [silverwind](https://github.com/silverwind), distributed under BSD licence |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32
2139