Comparing version 3.0.0 to 3.0.1
24
index.js
export async function clippie(content) { | ||
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); | ||
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); | ||
} | ||
} | ||
} | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
return true; | ||
} | ||
@@ -16,0 +20,0 @@ |
{ | ||
"name": "clippie", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Teeny-tiny browser clipboard copy", | ||
@@ -5,0 +5,0 @@ "author": "silverwind", |
@@ -11,8 +11,7 @@ # clippie | ||
let success; | ||
try { | ||
success = await clippie(stringOrBlob); | ||
} catch { | ||
success = false; | ||
} | ||
// copy text | ||
const success = await clippie("text to copy"); | ||
// copy image | ||
const success = await clippie(imageBlob); | ||
``` | ||
@@ -25,3 +24,3 @@ | ||
Returns a boolean indicating success. May throw critical errors. | ||
Returns `true` when successful and `false` when not. Will never throw. | ||
@@ -28,0 +27,0 @@ ## Notes |
2521
34
30