# cordova-clipboard-api

> Clipboard copy and paste plugin for Cordova/PhoneGap that supports text, images and urls for iOS, Android.

Latest version **1.0.1** (published 2020-10-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install cordova-clipboard-api
pnpm add cordova-clipboard-api
yarn add cordova-clipboard-api
bun add cordova-clipboard-api
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-10-22 |
| First published | 2020-10-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Michael Wuori |
| Maintainers | wuori |
| Keywords | cordova, plugin, clipboard, copy, paste, phonegap, ionic, ecosystem:cordova |

## Links

- npm: https://www.npmjs.com/package/cordova-clipboard-api
- Repository: https://github.com/wuori/cordova-clipboard-api
- Homepage: https://github.com/wuori/cordova-clipboard-api#readme
- Issues: https://github.com/wuori/cordova-clipboard-api/issues
- npm.io page: https://npm.io/package/cordova-clipboard-api

## Recent versions

- 1.0.1 (latest) — 2020-10-22
- 1.0.0 — 2020-10-22

## README

Cordova Clipboard API
=========

[![npm version](https://badge.fury.io/js/cordova-clipboard-api.svg)](https://badge.fury.io/js/cordova-clipboard-api)

Clipboard management plugin for Cordova/PhoneGap that supports images, text and urls for iOS. Android support is limited to text content only.

## Installation

```
cordova plugin add cordova-clipboard-api
```

The plugin creates the object `cordova.plugins.clipboard` with the methods `copy(options, callback)`, `paste(callback)` and `clear()`.

## Methods

### Copy()

`copy(options, callback)`

The `options` object contains two properties: `type` and `data`.

- *type* - One of "text", "url" or "image"
- *data* - Data to be sent to clipboard

Callback will contain an object:
```
{
	type: "ex: text", // type value submitted to plugin
	data: "ex: Howdy Partner!", // data submitted to plugin
	error: false // false if successful. Exception text if not.
}
```

#### Copy Text (iOS/Android)
```
window.cordova.plugins.clipboard.copy({
	type: "text", // default, so not needed for text
	data: "Howdy Partner!"
}, (res) => {
	console.log(res);
});
```

#### Copy URL (iOS only)
```
window.cordova.plugins.clipboard.copy({
	type: "url",
	data: "https://yesorno.io/"
}, (res) => {
	console.log(res.type);
});
```

#### Copy Image (iOS only)

*NOTE:* Only tested with remote URLs so far.

```
let imageUrl = "https://placedog.net/500";

// get blob of image (example only, use whatever method you like!)
fetch(url)
.then((response) => {
	return response.blob();
}).then((blob) => {
	let reader = new FileReader() ;
	reader.onload = (res) => { 
		window.cordova.plugins.clipboard.copy({
			type: 'image',
			data: res.target.result
		}, (res) => {
			console.log(res);
		});
	};
	reader.readAsDataURL(blob) ;
});
```
---

### Paste()

`paste(callback)`

Callback will contain an object:
```
{
	type: "ex: text", // type of data coming from clipboard
	data: "ex: Howdy Partner!", // data coming from clipboard
}
```

*NOTE:* Pasted images in iOS will always be base64-encoded string.
Example: `data:image/png;base64,iVBORw0KGgoAAAAN...`

#### Paste Data from Clipboard
```
window.cordova.plugins.clipboard.paste((res) => {
	if(res.type == "text"){
		this.text = res.data;
	}
});
```
---

### clear()

`clear()`

#### Clear Data from Clipboard
```
window.cordova.plugins.clipboard.clear();
```

## Notes

### Testing

- This plugin hasn't been tested on a ton of physical devices yet. Please file an issue should you find a bug!

### iOS

- The minimum supported version of iOS is v7.0.

### Android

- Android version only supports text content.
- The minimum supported API Level is 11. Make sure that `minSdkVersion` is larger or equal to 11 in `AndroidManifest.xml`.

## Acknowledgements

This plugin began as a fork of [CordovaClipboard](https://github.com/ihadeed/cordova-clipboard) which was inspired by [ClipboardManagerPlugin](https://github.com/jacob/ClipboardManagerPlugin) (Android) and [ClipboardPlugin](https://github.com/phonegap/phonegap-plugins/tree/master/iPhone/ClipboardPlugin) (iOS).

This plugin adds support for urls and images (iOS only) as well as provides a more complete callback object with error handling.

## License

The MIT License (MIT)

Copyright (c) 2020 Michael Wuori

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

---
_Source: https://npm.io/package/cordova-clipboard-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
