Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svelte-copy

Package Overview
Dependencies
Maintainers
0
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-copy

A svelte action to copy text to clipboard. It uses the `navigator.clipboard` api, with a fallback to the legacy method.

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.6K
increased by3.03%
Maintainers
0
Weekly downloads
 
Created
Source

Svelte Copy

A svelte action to copy text to clipboard. It uses the navigator.clipboard api, with a fallback to the legacy method.

Installing

npm install svelte-copy -D

This library only works with Svelte 5, checkout svelte-copy@1 for Svelte 3/4 support.

Usage

The simplest use is to just pass the text you want to copy:

<script>
    import { copy } from 'svelte-copy';
</script>

<button use:copy={'Hello World'}>
    Click me!
</button>

You can expand that with an options object:

<script>
    import { copy } from 'svelte-copy';
</script>

<button
    use:copy={{
        text,
        events: ['click'],
        onCopy({ text, event }) {
            alert(`Text copied: "${text}". Triggered by "${event}"`);
        },
        onError({ error, event }) {
            alert(error.message)
        }
    }}
>
    Copy
</button>

Read the full docs here.

Migrating from v1 to v2

  • The on:svelte-copy event is now a onCopy param to the action options.
  • The on:svelte-copy:error event is now a onError param to the action options.
  • The events option now only accepts string[], rather than string | string[]
  • Svelte 5 is now required

Support

FAQs

Package last updated on 21 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc