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

ackerjs-forms

v1.0.0

Published

Client-side form handling with built-in SMTP email capabilities for AckerJS

Downloads

5

Readme

AckerJS Forms

Client-side form handling with built-in SMTP email capabilities

NPM Version License TypeScript

✨ Features

  • 🚀 Zero Backend Setup - Works immediately after installation
  • 📧 Built-in SMTP Client - Send emails directly from the browser
  • Automatic Validation - Auto-detect validation rules from HTML attributes
  • 🎨 Template Engine - Customizable email templates with variable substitution
  • 🔒 Security First - Built-in sanitization and XSS protection
  • 💪 TypeScript Support - Fully typed API
  • 📦 Tree-shakable - Import only what you need
  • 🎯 Framework Agnostic - Works with vanilla JS, React, Vue, or any framework

📦 Installation

npm install ackerjs-forms

🚀 Quick Start

Basic Usage

<form id="contact-form">
  <input type="text" name="name" required minlength="3" />
  <input type="email" name="email" required />
  <textarea name="message" required minlength="10"></textarea>
  <button type="submit">Send</button>
</form>
import { AckerForm } from 'ackerjs-forms';

const form = new AckerForm('#contact-form', {
  smtp: {
    host: 'smtp.gmail.com',
    port: 587,
    secure: false,
    auth: {
      user: '[email protected]',
      pass: 'your-app-password'
    }
  },
  email: {
    to: '[email protected]',
    subject: 'New Contact Form Submission',
    userConfirmation: true
  },
  onSuccess: (data) => {
    console.log('Form submitted successfully!', data);
  },
  onError: (error) => {
    console.error('Submission failed:', error);
  }
});

📚 Core Concepts

1. Auto-Detection of Validation Rules

AckerJS Forms automatically detects validation rules from HTML5 attributes:

<input type="text" name="username" required minlength="3" maxlength="20" />
<input type="email" name="email" required />
<input type="url" name="website" pattern="https?://.+" />
<input type="number" name="age" min="18" max="100" />

These attributes are automatically converted to validation rules!

2. Custom Validation Rules

Add custom validation logic:

form.addRule('phone', {
  validator: (value) => /^\+?[1-9]\d{1,14}$/.test(value),
  message: 'Please enter a valid phone number'
});

form.addRule('password', {
  validator: (value) => {
    return value.length >= 8 && /[A-Z]/.test(value) && /[0-9]/.test(value);
  },
  message: 'Password must be at least 8 characters with uppercase and number'
});

3. SMTP Configuration

Configure SMTP for sending emails:

const form = new AckerForm('#myform', {
  smtp: {
    host: 'smtp.gmail.com',      // SMTP server
    port: 587,                    // SMTP port (587 for TLS, 465 for SSL)
    secure: false,                // true for 465, false for other ports
    auth: {
      user: '[email protected]',
      pass: 'your-app-password'   // Use app-specific passwords!
    }
  }
});

Popular SMTP Providers

Gmail:

{
  host: 'smtp.gmail.com',
  port: 587,
  secure: false,
  auth: { user: '[email protected]', pass: 'app-password' }
}

Outlook/Office365:

{
  host: 'smtp-mail.outlook.com',
  port: 587,
  secure: false,
  auth: { user: '[email protected]', pass: 'password' }
}

SendGrid:

{
  host: 'smtp.sendgrid.net',
  port: 587,
  secure: false,
  auth: { user: 'apikey', pass: 'your-sendgrid-api-key' }
}

4. Email Templates

Using Built-in Templates

const form = new AckerForm('#myform', {
  email: {
    to: '[email protected]',
    subject: 'New Submission',
    template: 'default/welcome',        // Use built-in template
    userConfirmation: true,             // Send confirmation to user
    userTemplate: 'default/developer-alert'
  }
});

Custom Templates

Create your own email templates with variable substitution:

<!-- my-template.html -->
<html>
  <body>
    <h1>Hello {{name}}!</h1>
    <p>Thank you for your message: {{message}}</p>
    <p>We'll contact you at {{email}}</p>
  </body>
</html>
const form = new AckerForm('#myform', {
  email: {
    template: '/path/to/my-template.html'
  }
});

Template Syntax

Variables:

{{fieldName}}          <!-- Replace with form data -->
{{user.email}}         <!-- Nested properties -->

Conditionals:

{{#if fieldName}}
  <p>{{fieldName}}</p>
{{/if}}

Loops:

{{#each items}}
  <li>{{this}}</li>
{{/each}}

5. Lifecycle Events

Hook into form submission lifecycle:

const form = new AckerForm('#myform', {
  onSubmit: (data) => {
    console.log('Form submitted with:', data);
    // Return false to cancel submission
  },
  
  onValidate: (result) => {
    console.log('Validation result:', result);
    // result.valid: boolean
    // result.errors: { fieldName: 'error message' }
  },
  
  onSuccess: (response) => {
    console.log('Emails sent successfully:', response);
    // response.userEmail: string
    // response.developerEmail: string
  },
  
  onError: (error) => {
    console.error('Submission failed:', error);
  }
});

6. Security Features

AckerJS Forms includes built-in security:

import { Sanitizer } from 'ackerjs-forms';

// Escape HTML to prevent XSS
const safe = Sanitizer.escapeHtml(userInput);

// Strip all HTML tags
const text = Sanitizer.stripHtml(htmlContent);

// Strip dangerous scripts and attributes
const clean = Sanitizer.stripScripts(htmlContent);

// Validate and sanitize emails
const isValid = Sanitizer.isValidEmail(email);
const sanitized = Sanitizer.sanitizeEmail(email);

// Sanitize entire form data
const cleanData = Sanitizer.sanitizeFormData(formData);

🔧 Advanced Usage

Manual Validation

import { Validator } from 'ackerjs-forms';

const validator = new Validator();

validator.addRule('email', {
  required: true,
  email: true
});

validator.addRule('age', {
  required: true,
  min: 18,
  max: 100
});

const result = validator.validateForm({
  email: '[email protected]',
  age: 25
});

if (result.valid) {
  console.log('Valid!');
} else {
  console.log('Errors:', result.errors);
}

Custom Template Rendering

import { TemplateRenderer } from 'ackerjs-forms';

const renderer = new TemplateRenderer();

const html = await renderer.render('/path/to/template.html', {
  name: 'John',
  email: '[email protected]',
  items: ['Item 1', 'Item 2', 'Item 3']
});

Using the SMTP Client Directly

import { SMTPClient, MIMEBuilder } from 'ackerjs-forms';

const smtp = new SMTPClient({
  host: 'smtp.gmail.com',
  port: 587,
  secure: false,
  auth: {
    user: '[email protected]',
    pass: 'your-app-password'
  }
});

const message = MIMEBuilder.buildMessage({
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Test Email',
  text: 'Plain text content',
  html: '<h1>HTML content</h1>'
});

await smtp.sendMail(message);

📖 API Reference

AckerForm

Main form handler class.

new AckerForm(selector: string, options: AckerFormOptions)

Options:

  • smtp - SMTP configuration
  • email - Email settings (to, subject, templates)
  • validation - Validation options
  • ui - UI customization
  • onSubmit - Submit handler
  • onValidate - Validation handler
  • onSuccess - Success handler
  • onError - Error handler

Methods:

  • addRule(fieldName, rule) - Add custom validation rule
  • validate() - Manually validate form
  • submit() - Manually submit form
  • reset() - Reset form
  • destroy() - Cleanup and remove event listeners

Validator

Form validation engine.

new Validator()

Methods:

  • addRule(fieldName, rule) - Add validation rule
  • validateField(fieldName, value) - Validate single field
  • validateForm(data) - Validate entire form
  • getErrors() - Get all validation errors

TemplateRenderer

Email template renderer with variable substitution.

new TemplateRenderer()

Methods:

  • render(templatePath, data) - Render template with data
  • loadTemplate(url) - Load template from URL

SMTPClient

SMTP client for sending emails.

new SMTPClient(config: SMTPConfig)

Methods:

  • sendMail(message) - Send email message

Sanitizer

Security utilities for sanitizing input.

Static Methods:

  • Sanitizer.escapeHtml(text) - Escape HTML special characters
  • Sanitizer.stripHtml(html) - Remove all HTML tags
  • Sanitizer.stripScripts(html) - Remove scripts and dangerous attributes
  • Sanitizer.sanitizeEmail(email) - Sanitize email address
  • Sanitizer.isValidEmail(email) - Validate email format
  • Sanitizer.sanitizeFormData(data) - Sanitize all form data

🔐 Security Best Practices

  1. Never expose SMTP credentials in client-side code - Use environment variables or a backend proxy
  2. Always validate and sanitize user input - Built-in but you can add custom rules
  3. Use app-specific passwords - Don't use your actual email password
  4. Enable rate limiting - Prevent abuse of your SMTP server
  5. Validate email domains - Use isEmailFromDomain() helper
  6. Check for disposable emails - Use isDisposableEmail() helper

🤝 Integration with AckerJS

AckerJS Forms works seamlessly with the AckerJS framework:

import { dom } from 'ackerjs';
import { AckerForm } from 'ackerjs-forms';

// Use AckerJS DOM utilities
dom.on('#myform', 'submit', (e) => {
  e.preventDefault();
  form.submit();
});

// Use AckerJS HTTP utilities for backend integration
import { http } from 'ackerjs';

const form = new AckerForm('#myform', {
  onSuccess: async (data) => {
    // Send data to your backend
    await http.post('/api/submissions', data);
  }
});

📝 Examples

Check out the /examples directory for complete working examples:

  • Basic contact form
  • Multi-step form with validation
  • File upload handling
  • Custom email templates
  • Integration with React
  • Integration with Vue
  • Backend proxy setup

🐛 Troubleshooting

Emails not sending

  1. Check SMTP credentials are correct
  2. Verify SMTP port and secure settings
  3. Check console for error messages
  4. Test SMTP connection outside the browser first

Validation not working

  1. Ensure HTML attributes are spelled correctly
  2. Check for JavaScript errors in console
  3. Verify field names match validation rules

Template not loading

  1. Check template file path is correct
  2. Verify file is accessible via HTTP
  3. Check browser console for CORS errors

📄 License

MIT © Acker Technologies

🔗 Links