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

@aldoalfaro/magnet

v1.0.4

Published

A lightweight JavaScript library for lead capture modals. No dependencies, pure vanilla JS.

Readme

🧲 Magnet

A lightweight, customizable JavaScript library for creating lead capture modals. No runtime dependencies, pure vanilla JS.

Features

  • 🎯 Smart Triggers - Time-based, scroll-based, or exit intent
  • 🎨 Fully Customizable - Colors, text, images, and layouts
  • 📱 Responsive - Works perfectly on all devices
  • Form Validation - Built-in email validation and error handling
  • Lightweight - No dependencies, pure vanilla JavaScript
  • 🔄 Multiple Instances - Run multiple modals on the same page

Installation

NPM

npm install @aldoalfaro/magnet

CDN

<script src="https://cdn.jsdelivr.net/npm/@aldoalfaro/magnet@latest/dist/magnet.min.js"></script>

Quick Start

<script src="https://cdn.jsdelivr.net/npm/@aldoalfaro/magnet@latest/dist/magnet.min.js"></script>
<script>
  new Magnet({
    trigger: {
      type: 'time',
      value: 3
    },
    submit: {
      url: 'https://your-webhook-url.com'
    }
  });
</script>

Examples

Time-based Trigger

Opens after 3 seconds with default styling.

new Magnet({
  trigger: {
    type: 'time',
    value: 3
  },
  submit: {
    url: 'https://hooks.website.com/...'
  }
});

Scroll Trigger (No Backdrop)

Appears at 50% scroll in bottom-right corner without backdrop overlay.

new Magnet({
  trigger: {
    type: 'scroll',
    value: 50
  },
  submit: {
    url: 'https://hooks.website.com/...'
  },
  design: {
    position: 'bottom-right',
    backdrop: false,
    ctaColor: '#FF5722'
  },
  content: {
    title: '🎁 Special Offer!',
    introText: 'Get 20% off today.'
  }
});

Exit Intent with Image

Triggers when user moves mouse to top of viewport.

new Magnet({
  trigger: {
    type: 'exit'
  },
  submit: {
    url: 'https://hooks.website.com/...'
  },
  design: {
    imageUrl: 'https://images.unsplash.com/photo-example.jpg',
    layout: 'left',
    ctaColor: '#9C27B0'
  },
  content: {
    title: 'Download Our eBook',
    introText: 'Learn advanced techniques.'
  }
});

Custom Hidden Fields

Add tracking parameters or custom data.

new Magnet({
  trigger: { type: 'time', value: 3 },
  submit: { url: 'https://your-webhook.com' },
  customFields: {
    utm_source: 'website',
    utm_campaign: 'summer-2024'
  }
});

Configuration

Full Configuration Example

new Magnet({
  // Trigger configuration
  trigger: {
    type: 'time',           // 'time', 'scroll', 'exit'
    value: 3                // seconds for time, percentage for scroll
  },
  
  // Submission configuration
  submit: {
    url: '',                // Required: webhook/API endpoint
    format: 'formdata'      // 'formdata' or 'json'
  },
  
  // Custom hidden fields
  customFields: {
    source: 'homepage',
    campaign: 'promo'
  },
  
  // Design configuration
  design: {
    position: 'centered',   // See positions below
    backdrop: true,         // Show backdrop overlay
    imageUrl: '',           // Optional image URL
    layout: 'top',          // 'top', 'left', 'right'
    backgroundColor: '#ffffff',
    textColor: '#333333',
    ctaColor: '#007bff'
  },
  
  // Content configuration
  content: {
    title: 'Get Your Free Guide',
    introText: 'Enter your details to download',
    buttonText: 'Download Now',
    thankYouTitle: 'Thank You!',
    thankYouText: 'Check your email for the download link',
    errorMessage: 'Please fill in all fields correctly.'
  }
});

Configuration Reference

| Parameter | Possible Values | Default | Description | |-----------|----------------|---------|-------------| | Trigger | | trigger.type | 'time', 'scroll', 'exit' | 'time' | When to trigger the modal | | trigger.value | Number | 3 | Seconds for time trigger, percentage for scroll trigger | | Submit | | submit.url | String (URL) | '' | Webhook or API endpoint to submit form data | | submit.format | 'formdata', 'json' | 'formdata' | Format for submission | | Custom Fields | | customFields | Object | {} | Key-value pairs for hidden form fields | | Design | | design.position | 'centered', 'bottom-right', 'top-center', 'top-left', 'bottom-left', 'bottom-center' | 'centered' | Modal position on screen | | design.backdrop | true, false | true | Show dark overlay behind modal | | design.imageUrl | String (URL) | '' | Optional image to display in modal | | design.layout | 'top', 'left', 'right' | 'top' | Image position relative to content | | design.backgroundColor | Hex color | '#ffffff' | Modal background color | | design.textColor | Hex color | '#333333' | Text color | | design.ctaColor | Hex color | '#007bff' | Submit button color | | Content | | content.title | String | '' | Optional. Main heading text. | | content.introText | String | 'Enter your details below' | Subheading or description text | | content.buttonText | String | 'Submit' | Submit button text | | content.thankYouTitle | String | 'Thank You!' | Title shown after successful submission | | content.thankYouText | String | 'We will get back to you soon.' | Message shown after successful submission | | content.errorMessage | String | 'Please fill in all fields correctly.' | Error message for validation failures | | content.nameLabel | String | 'Name' | Label for name field | | content.emailLabel | String | 'Email' | Label for email field |

Methods

open()

Manually open the modal. Can be called multiple times.

const magnet = new Magnet({ /* config */ });
magnet.open();  // Opens the modal

close()

Programmatically close the modal.

magnet.close();

Development

# Install build tools
npm install

# Build minified version
npm run build

Made with ❤️ by Aldo Alfaro