@mariozechner/clipboard
Advanced tools
+11
-11
| { | ||
| "name": "@mariozechner/clipboard", | ||
| "version": "0.3.2", | ||
| "version": "0.3.3", | ||
| "main": "index.js", | ||
@@ -45,13 +45,13 @@ "types": "index.d.ts", | ||
| "optionalDependencies": { | ||
| "@mariozechner/clipboard-win32-x64-msvc": "0.3.2", | ||
| "@mariozechner/clipboard-darwin-x64": "0.3.2", | ||
| "@mariozechner/clipboard-linux-x64-gnu": "0.3.2", | ||
| "@mariozechner/clipboard-darwin-arm64": "0.3.2", | ||
| "@mariozechner/clipboard-linux-arm64-gnu": "0.3.2", | ||
| "@mariozechner/clipboard-linux-arm64-musl": "0.3.2", | ||
| "@mariozechner/clipboard-win32-arm64-msvc": "0.3.2", | ||
| "@mariozechner/clipboard-darwin-universal": "0.3.2", | ||
| "@mariozechner/clipboard-linux-riscv64-gnu": "0.3.2", | ||
| "@mariozechner/clipboard-linux-x64-musl": "0.3.2" | ||
| "@mariozechner/clipboard-win32-x64-msvc": "0.3.3", | ||
| "@mariozechner/clipboard-darwin-x64": "0.3.3", | ||
| "@mariozechner/clipboard-linux-x64-gnu": "0.3.3", | ||
| "@mariozechner/clipboard-darwin-arm64": "0.3.3", | ||
| "@mariozechner/clipboard-linux-arm64-gnu": "0.3.3", | ||
| "@mariozechner/clipboard-linux-arm64-musl": "0.3.3", | ||
| "@mariozechner/clipboard-win32-arm64-msvc": "0.3.3", | ||
| "@mariozechner/clipboard-darwin-universal": "0.3.3", | ||
| "@mariozechner/clipboard-linux-riscv64-gnu": "0.3.3", | ||
| "@mariozechner/clipboard-linux-x64-musl": "0.3.3" | ||
| } | ||
| } |
+57
-52
@@ -17,101 +17,106 @@ #![deny(clippy::all)] | ||
| fn napi_error(error: impl ToString) -> Error { | ||
| Error::from_reason(error.to_string()) | ||
| } | ||
| #[napi] | ||
| pub fn available_formats() -> Vec<String> { | ||
| let ctx = ClipboardContext::new().unwrap(); | ||
| let types = ctx.available_formats().unwrap(); | ||
| types | ||
| pub fn available_formats() -> Result<Vec<String>> { | ||
| let ctx = ClipboardContext::new().map_err(napi_error)?; | ||
| ctx.available_formats().map_err(napi_error) | ||
| } | ||
| #[napi] | ||
| pub async fn get_text() -> String { | ||
| let ctx = ClipboardContext::new().unwrap(); | ||
| ctx.get_text().unwrap() | ||
| pub async fn get_text() -> Result<String> { | ||
| let ctx = ClipboardContext::new().map_err(napi_error)?; | ||
| ctx.get_text().map_err(napi_error) | ||
| } | ||
| #[napi] | ||
| pub async fn set_text(text: String) { | ||
| let ctx = ClipboardContext::new().unwrap(); | ||
| ctx.set_text(text).unwrap() | ||
| pub async fn set_text(text: String) -> Result<()> { | ||
| let ctx = ClipboardContext::new().map_err(napi_error)?; | ||
| ctx.set_text(text).map_err(napi_error) | ||
| } | ||
| #[napi] | ||
| pub fn has_text() -> bool { | ||
| let ctx = ClipboardContext::new().unwrap(); | ||
| ctx.has(ContentFormat::Text) | ||
| pub fn has_text() -> Result<bool> { | ||
| let ctx = ClipboardContext::new().map_err(napi_error)?; | ||
| Ok(ctx.has(ContentFormat::Text)) | ||
| } | ||
| #[napi] | ||
| pub async fn get_image_binary() -> Vec<u8> { | ||
| let ctx = ClipboardContext::new().unwrap(); | ||
| let image = ctx.get_image().unwrap(); | ||
| let image_bytes = image.to_png().unwrap().get_bytes().to_vec(); | ||
| image_bytes | ||
| pub async fn get_image_binary() -> Result<Vec<u8>> { | ||
| let ctx = ClipboardContext::new().map_err(napi_error)?; | ||
| let image = ctx.get_image().map_err(napi_error)?; | ||
| let image_bytes = image.to_png().map_err(napi_error)?.get_bytes().to_vec(); | ||
| Ok(image_bytes) | ||
| } | ||
| #[napi] | ||
| pub async fn get_image_base64() -> String { | ||
| let image_bytes = get_image_binary().await; | ||
| pub async fn get_image_base64() -> Result<String> { | ||
| let image_bytes = get_image_binary().await?; | ||
| let base64_str = general_purpose::STANDARD_NO_PAD.encode(&image_bytes); | ||
| base64_str | ||
| Ok(base64_str) | ||
| } | ||
| #[napi] | ||
| pub async fn set_image_binary(image_bytes: Vec<u8>) { | ||
| let ctx = ClipboardContext::new().unwrap(); | ||
| let img = RustImageData::from_bytes(&image_bytes).unwrap(); | ||
| ctx.set_image(img).unwrap() | ||
| pub async fn set_image_binary(image_bytes: Vec<u8>) -> Result<()> { | ||
| let ctx = ClipboardContext::new().map_err(napi_error)?; | ||
| let img = RustImageData::from_bytes(&image_bytes).map_err(napi_error)?; | ||
| ctx.set_image(img).map_err(napi_error) | ||
| } | ||
| #[napi] | ||
| pub async fn set_image_base64(base64_str: String) { | ||
| let decoded: Vec<u8> = general_purpose::STANDARD_NO_PAD.decode(base64_str).unwrap(); | ||
| set_image_binary(decoded).await; | ||
| pub async fn set_image_base64(base64_str: String) -> Result<()> { | ||
| let decoded: Vec<u8> = general_purpose::STANDARD_NO_PAD | ||
| .decode(base64_str) | ||
| .map_err(napi_error)?; | ||
| set_image_binary(decoded).await | ||
| } | ||
| #[napi] | ||
| pub fn has_image() -> bool { | ||
| let ctx = ClipboardContext::new().unwrap(); | ||
| ctx.has(ContentFormat::Image) | ||
| pub fn has_image() -> Result<bool> { | ||
| let ctx = ClipboardContext::new().map_err(napi_error)?; | ||
| Ok(ctx.has(ContentFormat::Image)) | ||
| } | ||
| #[napi] | ||
| pub async fn get_html() -> String { | ||
| let ctx = ClipboardContext::new().unwrap(); | ||
| ctx.get_html().unwrap() | ||
| pub async fn get_html() -> Result<String> { | ||
| let ctx = ClipboardContext::new().map_err(napi_error)?; | ||
| ctx.get_html().map_err(napi_error) | ||
| } | ||
| #[napi] | ||
| pub async fn set_html(html: String) { | ||
| let ctx = ClipboardContext::new().unwrap(); | ||
| ctx.set_html(html).unwrap() | ||
| pub async fn set_html(html: String) -> Result<()> { | ||
| let ctx = ClipboardContext::new().map_err(napi_error)?; | ||
| ctx.set_html(html).map_err(napi_error) | ||
| } | ||
| #[napi] | ||
| fn has_html() -> bool { | ||
| let ctx = ClipboardContext::new().unwrap(); | ||
| ctx.has(ContentFormat::Html) | ||
| fn has_html() -> Result<bool> { | ||
| let ctx = ClipboardContext::new().map_err(napi_error)?; | ||
| Ok(ctx.has(ContentFormat::Html)) | ||
| } | ||
| #[napi] | ||
| pub async fn get_rtf() -> String { | ||
| let ctx = ClipboardContext::new().unwrap(); | ||
| ctx.get_rich_text().unwrap() | ||
| pub async fn get_rtf() -> Result<String> { | ||
| let ctx = ClipboardContext::new().map_err(napi_error)?; | ||
| ctx.get_rich_text().map_err(napi_error) | ||
| } | ||
| #[napi] | ||
| pub async fn set_rtf(rtf: String) { | ||
| let ctx = ClipboardContext::new().unwrap(); | ||
| ctx.set_rich_text(rtf).unwrap() | ||
| pub async fn set_rtf(rtf: String) -> Result<()> { | ||
| let ctx = ClipboardContext::new().map_err(napi_error)?; | ||
| ctx.set_rich_text(rtf).map_err(napi_error) | ||
| } | ||
| #[napi] | ||
| pub fn has_rtf() -> bool { | ||
| let ctx = ClipboardContext::new().unwrap(); | ||
| ctx.has(ContentFormat::Rtf) | ||
| pub fn has_rtf() -> Result<bool> { | ||
| let ctx = ClipboardContext::new().map_err(napi_error)?; | ||
| Ok(ctx.has(ContentFormat::Rtf)) | ||
| } | ||
| #[napi] | ||
| pub async fn clear() { | ||
| let ctx = ClipboardContext::new().unwrap(); | ||
| ctx.clear().unwrap() | ||
| pub async fn clear() -> Result<()> { | ||
| let ctx = ClipboardContext::new().map_err(napi_error)?; | ||
| ctx.clear().map_err(napi_error) | ||
| } | ||
@@ -118,0 +123,0 @@ |
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
20176
2.97%