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 🙏

© 2025 – Pkg Stats / Ryan Hefner

svelte-captcha-enhance

v1.2.3

Published

A lightweight SvelteKit utility that adds CAPTCHA protection to your forms with progressive enhancement. Supports reCAPTCHA v3, hCaptcha, and Cloudflare Turnstile.

Downloads

1,896

Readme

svelte-captcha-enhance

A lightweight SvelteKit utility that adds CAPTCHA protection to your forms with progressive enhancement. Supports reCAPTCHA v3, hCaptcha, and Cloudflare Turnstile.

Features

  • 🔒 Multiple CAPTCHA providers: reCAPTCHA v3, hCaptcha, and Cloudflare Turnstile
  • 📦 Easy integration: Extends SvelteKit's enhance function with CAPTCHA support
  • 🎯 TypeScript support: Fully typed for better developer experience
  • 🪶 Lightweight: Minimal bundle size impact

Installation

npm install svelte-captcha-enhance

Quick Start

reCAPTCHA v3

<script>
  import { env } from '$env/dynamic/public';
  import enhance from 'svelte-captcha-enhance';
</script>

<svelte:head>
  <script src="https://www.google.com/recaptcha/api.js?render={env.PUBLIC_RECAPTCHA_SITEKEY}"></script>
</svelte:head>

<form
  method="post"
  use:enhance={{
    type: 'recaptcha',
    sitekey: env.PUBLIC_RECAPTCHA_SITEKEY,
    action: 'submit',
    submit: ({ formData }) => ({ result }) => {
      console.log('Form submitted:', result);
    }
  }}
>
  <input type="text" name="name" placeholder="Your name" required />
  <button type="submit">Submit</button>
</form>

hCaptcha

<script>
  import { env } from '$env/dynamic/public';
  import enhance from 'svelte-captcha-enhance';
</script>

<svelte:head>
  <script src="https://js.hcaptcha.com/1/api.js" async defer></script>
</svelte:head>

<div class="h-captcha" data-sitekey={env.PUBLIC_HCAPTCHA_SITEKEY}></div>

<form
  method="post"
  use:enhance={{
    type: 'hcaptcha',
    submit: ({ formData }) => ({ result }) => {
      console.log('Form submitted:', result);
    }
  }}
>
  <input type="text" name="name" placeholder="Your name" required />
  <button type="submit">Submit</button>
</form>

Cloudflare Turnstile

<script>
  import { env } from '$env/dynamic/public';
  import enhance from 'svelte-captcha-enhance';
</script>

<svelte:head>
  <script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
</svelte:head>

<form
  method="post"
  use:enhance={{
    type: 'turnstile',
    sitekey: env.PUBLIC_TURNSTILE_SITEKEY,
    submit: ({ formData }) => ({ result }) => {
      console.log('Form submitted:', result);
    }
  }}
>
  <input type="text" name="name" placeholder="Your name" required />
  <button type="submit">Submit</button>
</form>

API Reference

Configuration Options

Common Options

| Option | Type | Description | |--------|------|-------------| | submit | SubmitFunction | Optional callback function (same as SvelteKit's enhance) |

reCAPTCHA Options

| Option | Type | Required | Description | |--------|------|----------|-------------| | type | 'recaptcha' | ✅ | CAPTCHA provider type | | sitekey | string | ✅ | Your reCAPTCHA site key | | action | string | ❌ | Action name for reCAPTCHA v3 (default: 'submit') |

hCaptcha Options

| Option | Type | Required | Description | |--------|------|----------|-------------| | type | 'hcaptcha' | ✅ | CAPTCHA provider type | | widget | string | ❌ | Widget ID (uses first widget if unspecified) |

Turnstile Options

| Option | Type | Required | Description | |--------|------|----------|-------------| | type | 'turnstile' | ✅ | CAPTCHA provider type | | sitekey | string | ✅ | Your Turnstile site key | | container | string \| HTMLElement | ❌ | Container element (uses form if unspecified) | | theme | 'light' \| 'dark' \| 'auto' | ❌ | Theme (default: 'auto') | | size | 'normal' \| 'invisible' \| 'compact' | ❌ | Size (default: 'normal') | | language | string \| 'auto' | ❌ | Language (default: 'auto') |

Bypass Mode

For development or testing purposes:

<form
  method="post"
  use:enhance={{
    type: 'bypass',
    submit: ({ formData }) => ({ result }) => {
      console.log('Form submitted without CAPTCHA');
    }
  }}
>
  <!-- form content -->
</form>

Server-Side Validation

This library handles the client-side CAPTCHA integration only. You'll need to implement server-side validation yourself using your CAPTCHA provider's verification API. The CAPTCHA responses will be available in your form data as:

  • g-recaptcha-response (reCAPTCHA)
  • h-captcha-response (hCaptcha)
  • cf-turnstile-response (Turnstile)

Examples

Check out the examples directory for complete working examples of each CAPTCHA provider.