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

astro-onsubmit

v0.1.0

Published

Astro.js integration for onsubmit.dev — drop-in form submission interceptor

Readme

astro-onsubmit

Drop-in Astro.js integration for onsubmit.dev.
Add a data-onsubmit attribute to any form — submissions are automatically sent to your onsubmit.dev endpoint via fetch. No backend required.

Installation

npm install astro-onsubmit

Quick start

Option A — Astro Integration (recommended)

Register the integration once in astro.config.mjs and it applies to every page:

// astro.config.mjs
import { defineConfig } from 'astro/config';
import onsubmit from 'astro-onsubmit';

export default defineConfig({
  integrations: [onsubmit()],
});

Then add data-onsubmit="your-form-id" to any <form>:

---
// src/pages/contact.astro
---
<form data-onsubmit="YOUR_FORM_ID">
  <input name="name" placeholder="Your name" required />
  <input name="email" type="email" placeholder="Email" required />
  <textarea name="message" placeholder="Message"></textarea>
  <button type="submit">Send</button>
</form>

Your form ID is available in the onsubmit.dev dashboard after creating a form.


Option B — Component (no config change needed)

Import and use the OnSubmitForm component directly on any page:

---
import OnSubmitForm from 'astro-onsubmit/OnSubmitForm.astro';
---

<OnSubmitForm formId="YOUR_FORM_ID" successMessage="Thanks! We'll be in touch.">
  <input name="name" placeholder="Your name" required />
  <input name="email" type="email" placeholder="Email" required />
  <button type="submit" data-onsubmit-loading="Sending…">Send</button>
</OnSubmitForm>

Attributes

| Attribute | Where | Description | |---|---|---| | data-onsubmit | <form> | Required. Your onsubmit.dev form ID. | | data-onsubmit-success | <form> | Text shown in place of the form on success. | | data-onsubmit-error | <form> | Custom error message shown on failure. | | data-onsubmit-loading | <button type="submit"> | Button text while submitting. |

Events

Listen on the form element for custom events:

document.querySelector('form[data-onsubmit]').addEventListener('onsubmit:success', (e) => {
  console.log('Submitted! ID:', e.detail.id);
});

document.querySelector('form[data-onsubmit]').addEventListener('onsubmit:error', (e) => {
  console.error('Error:', e.detail.error);
});

Error messages

Add a <p class="onsubmit-error-message" hidden> inside your form — it will be revealed automatically on API errors:

<form data-onsubmit="YOUR_FORM_ID">
  <input name="email" type="email" required />
  <button type="submit">Subscribe</button>
  <p class="onsubmit-error-message" hidden></p>
</form>

File uploads

File inputs are handled automatically. When the form contains a file field, the data is sent as multipart/form-data. Otherwise, JSON is used.

Integration options

onsubmit({
  // Override the default API base URL (useful for self-hosted deployments)
  endpoint: 'https://your-instance.example.com/f',
})

View Transitions

The integration listens for astro:page-load and re-scans the DOM automatically, so forms inside View Transitions work without any extra configuration.

License

MIT