Comparing version 2.1.0 to 3.0.0
24
index.js
export async function clippie(content) { | ||
try { | ||
for (const c of Array.isArray(content) ? content : [content]) { | ||
if (c instanceof Blob) { | ||
const item = new ClipboardItem({[c.type]: c}); | ||
await navigator.clipboard.write([item]); | ||
} else { | ||
try { | ||
await navigator.clipboard.writeText(c); | ||
} catch { | ||
return fallback(c); | ||
} | ||
for (const c of Array.isArray(content) ? content : [content]) { | ||
if (c instanceof Blob) { | ||
const item = new ClipboardItem({[c.type]: c}); | ||
await navigator.clipboard.write([item]); | ||
} else { | ||
try { | ||
await navigator.clipboard.writeText(c); | ||
} catch { | ||
return fallback(c); | ||
} | ||
} | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
return true; | ||
} | ||
@@ -20,0 +16,0 @@ |
{ | ||
"name": "clippie", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "Teeny-tiny browser clipboard copy", | ||
@@ -15,9 +15,9 @@ "author": "silverwind", | ||
"devDependencies": { | ||
"eslint": "8.28.0", | ||
"eslint-config-silverwind": "63.0.0", | ||
"eslint": "8.29.0", | ||
"eslint-config-silverwind": "65.0.0", | ||
"jsdom": "20.0.3", | ||
"updates": "13.2.1", | ||
"versions": "10.2.4", | ||
"vitest": "0.25.3" | ||
"updates": "13.2.4", | ||
"versions": "10.4.1", | ||
"vitest": "0.25.8" | ||
} | ||
} |
@@ -11,7 +11,8 @@ # clippie | ||
// copy text | ||
const success = await clippie("text to copy"); | ||
// copy image | ||
const success = await clippie(imageBlob); | ||
let success; | ||
try { | ||
success = await clippie(stringOrBlob); | ||
} catch { | ||
success = false; | ||
} | ||
``` | ||
@@ -24,4 +25,8 @@ | ||
Returns `true` when successful and `false` when not. Will never throw. | ||
Returns a boolean indicating success. May throw critical errors. | ||
## Notes | ||
To enable image copy in Firefox, enable `dom.events.asyncClipboard.clipboardItem` in `about:config`. Track [Bug 1619947](https://bugzilla.mozilla.org/show_bug.cgi?id=1619947) for updates. | ||
© [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
2421
31
30