npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ngockhoi96/ctc-vue

v1.0.0

Published

Vue 3 composable for clipboard operations using @ngockhoi96/ctc — useCopyToClipboard as shallowRefs, SSR-safe

Downloads

34

Readme

💚 @ngockhoi96/ctc-vue

Vue 3 composable for the @ngockhoi96/ctc clipboard utilities library. Provides useCopyToClipboard with managed copied and error refs, configurable auto-reset timeout, and TypeScript-first API.

📦 Install

# npm
npm install @ngockhoi96/ctc-vue @ngockhoi96/ctc

# pnpm
pnpm add @ngockhoi96/ctc-vue @ngockhoi96/ctc

# bun
bun add @ngockhoi96/ctc-vue @ngockhoi96/ctc

🔗 Peer dependencies

| Package | Range | |---------|-------| | @ngockhoi96/ctc | >=0.1.0 | | vue | >=3.0.0 <4.0.0 |

Quick start

<script setup lang="ts">
import { useCopyToClipboard } from '@ngockhoi96/ctc-vue'

const { copy, copied, error } = useCopyToClipboard('Hello, world!')
</script>

<template>
  <button @click="copy()">
    {{ copied ? 'Copied!' : 'Copy' }}
  </button>
  <span v-if="error">Error: {{ error.code }}</span>
</template>

Override text at call site

<script setup lang="ts">
const { copy, copied } = useCopyToClipboard()
</script>

<template>
  <button @click="copy(dynamicValue)">Copy</button>
</template>

Disable auto-reset (timeout: 0)

<script setup lang="ts">
const { copy, copied, reset } = useCopyToClipboard('text', { timeout: 0 })
// copied.value stays true until reset() is called explicitly
</script>

Programmatic reset

<script setup lang="ts">
import { onBeforeRouteLeave } from 'vue-router'

const { copy, copied, reset } = useCopyToClipboard('text')

// Reset on route leave
onBeforeRouteLeave(() => reset())
</script>

Custom timeout

<script setup lang="ts">
const { copy, copied } = useCopyToClipboard('text', { timeout: 5000 })
// copied.value resets after 5 seconds
</script>

Error handling

<script setup lang="ts">
import type { BrowserUtilsError } from '@ngockhoi96/ctc-vue'

const { copy, error } = useCopyToClipboard('text', {
  onError: (err: BrowserUtilsError) => {
    console.error('Clipboard error:', err.code, err.message)
  },
})
</script>

API

useCopyToClipboard(initText?, options?)

function useCopyToClipboard(
  initText?: string,
  options?: UseCopyToClipboardOptions,
): UseCopyToClipboardResult

Parameters

| Parameter | Type | Description | |-----------|------|-------------| | initText | string \| undefined | Text to copy. Can be overridden per copy() call. | | options | UseCopyToClipboardOptions \| undefined | Optional configuration. |

UseCopyToClipboardOptions

Extends ClipboardOptions from @ngockhoi96/ctc.

| Property | Type | Default | Description | |----------|------|---------|-------------| | timeout | number \| undefined | 2000 | Milliseconds before copied resets to false. Set to 0 to disable auto-reset. | | onError | OnErrorCallback \| undefined | — | Called when a copy operation fails. Receives a BrowserUtilsError. |

Return value: UseCopyToClipboardResult

| Property | Type | Description | |----------|------|-------------| | copy | (text?: string) => Promise<boolean> | Trigger a copy. Call-site text overrides initText. Returns true on success. | | copied | ShallowRef<boolean> | true immediately after a successful copy. Resets after timeout ms. | | error | ShallowRef<BrowserUtilsError \| null> | Error from the last failed copy, or null. Cleared on each new copy() call. | | reset | () => void | Immediately clears copied.value and error.value. Cancels any pending auto-reset timer. |

Note: copied and error are shallow refs — use .value to access their current value. In Vue templates, .value is unwrapped automatically.

TypeScript types

All types are re-exported from @ngockhoi96/ctc-vue for convenience:

import type {
  BrowserUtilsError,
  ClipboardOptions,
  ErrorCode,
  OnErrorCallback,
  UseCopyToClipboardOptions,
  UseCopyToClipboardResult,
} from '@ngockhoi96/ctc-vue'

ErrorCode

type ErrorCode =
  | 'CLIPBOARD_NOT_SUPPORTED'
  | 'CLIPBOARD_PERMISSION_DENIED'
  | 'CLIPBOARD_WRITE_FAILED'
  | 'CLIPBOARD_READ_FAILED'
  | 'INSECURE_CONTEXT'

Branch on error.value?.code to handle specific failure modes:

<script setup lang="ts">
const { copy, error } = useCopyToClipboard('text')
</script>

<template>
  <span v-if="error?.code === 'CLIPBOARD_NOT_SUPPORTED'">
    Clipboard API not available in this browser.
  </span>
  <span v-if="error?.code === 'INSECURE_CONTEXT'">
    Copy requires HTTPS.
  </span>
</template>

Browser support

Browser support is determined by @ngockhoi96/ctc core. Requires:

  • navigator.clipboard API (Chromium 66+, Firefox 63+, Safari 13.1+)
  • Secure context (HTTPS or localhost)

See @ngockhoi96/ctc browser support for details.

SSR

The composable is SSR-safe. In non-browser environments (Nuxt SSR, Node.js):

  • copyToClipboard from core returns false immediately (guarded by isBrowser())
  • copied.value and error.value remain in their initial state
  • onUnmounted is a no-op on the server — no timer cleanup issues

See also

License

MIT