import { Meta } from '@storybook/addon-docs/blocks'

<Meta title='@dxtmisha/en/functional-basic/Functions/getClipboardData - Get data from clipboard'/>

# `getClipboardData`

Asynchronously extracts text from the clipboard.

This function primarily attempts to retrieve text data from the provided `ClipboardEvent` (e.g., when handling a `paste` event). If the event is omitted or contains no data, it falls back to reading directly from the system clipboard using `navigator.clipboard.readText()`.

> Note: Using `navigator.clipboard.readText()` requires a secure context (HTTPS) and may require the user to explicitly grant clipboard reading permissions in some browsers.

**Parameters:**
- `event?: ClipboardEvent` — The (optional) clipboard event that fires during cut, copy, or paste actions.

**Returns:**
`Promise<string>` — A promise that resolves to the string content of the clipboard, or an empty string if retrieval fails.

```typescript
import { getClipboardData } from '@dxtmisha/functional-basic'

// Direct usage
document.querySelector('#paste-btn')?.addEventListener('click', async () => {
  const text = await getClipboardData()
  console.log('Clipboard text:', text)
})

// Usage inside a 'paste' event handler
document.addEventListener('paste', async (event) => {
  const text = await getClipboardData(event)
  console.log('Pasted text:', text)
})
```
