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

mfga

v2.1.5

Published

Thin tools to assist in basic form handling

Readme

MFG(a)

Making Forms Great (again) is a collection of standard enhancements for forms, made as thin as possible, to aid in the most common conversion and processing tasks related to form state and submission. This module does not rely on any other modules at all and can be used natively or with a frontend framework. Examples below are given both as native and for React, but it should be trivial to apply the MFG(a) attributes and methods to any form with any framework.

Install: npm i mfga

Use: import the methods you need from

import {
    handleSubmit, 
    watchFormState, 
    handleFiles
} from 'mfga'

Normally you only need handleSubmit and watchFormState, and handleFiles if you are going to upload files.


Handle Submit

If you want to use the MFG(a) solutions in general, this wrapper function and form setup takes care of it.

handleSubmit (event)

Native

<form onsubmit="handleSubmit(event)" onchange="watchFormState(event)" action="/send/to/this-url" method="post">
    <input type="text" name="zip" />
    <input type="submit" value="Send" />
</form>

Reacty

<form onSubmit={handleSubmit} onChange={watchFormState} action="/send/to/this-url" method="post">
    <input type="text" name="zip" />
    <input type="submit" value="Send" />
</form>

Between the time of submit and response the form will have the class 'mfga-processing', which you can refer to for a css waiting animation.

Example CSS

.mfga-processing::before {
    content:'';
    position: fixed;
    top: 0;
    left: 0;
    width: 15%;
    height: 2px;
    display: block;
    background: white;
    box-shadow: 0 0 6px 2px rgba(100, 100, 100, 0.8);
    animation: line 1.4s linear infinite;
}

@keyframes line {
    0% {
        transform: translateX(-100%) scale(1);
    }
    40% {
        transform: translateX(280%) scale(5, 1.3);
    }
    100% {
        transform: translateX(660%) scale(1);
    }
}

Handle Form State

watchFormState (event)

  • Keeps track of your form state.
  • Toggles the disabled prop on your submit button so that you cannot send an unmodified form, if you have a button or input with the type property set to type="submit".

Reacty

<form onChange={watchFormState}>
    <input type="text" name="zip" />
    <input type="submit" disabled value="Send" />
</form>

Note that you need to manually set disabled as default (above)

What about initial state?

Just apply it directly to the fields in your form:

Reacty

<form onChange={watchFormState} onSubmit="handleSubmit">
    <input type="text" name="zip" value={zip}/>
    <input type="submit" disabled value="Send" />
</form>

Upload files

Just set the form as multipart and use the handleFiles method and the JSON object posted will have a files array:

<form enctype="multipart/form-data" onsubmit="handleSubmit(event)" onchange="watchFormState(event)" action="/send/to/this-url" method="post">
    <input name="slogan" value="No slogan">
    <input type="file" onchange="handleFiles(event)" name="files" multiple> 
    <input type="submit" value="Upload" disabled>
</form>

Objectify Form

A helper function, that you may use if you wish to, well, just use this or parts of MFG(a) and not the whole thing.. Converts a form to an object, suitable for sending JSON in a POST body. Normally you wouldn't call it directly using MFG(a) but if you want to write your own submit handler you can use it to convert the form data.

import {
    handleSubmit, 
    objectifyForm
} from 'mfga'

async function submitForm(e) {
    e.preventDefault()
    await fetch(url,{
        method: 'post',
        body: JSON.stringify(objectifyForm(e.target))
    })
}
<form onSubmit={submitForm}>
    <input type="text" name="zip"/>
    <input type="submit" value="Send" />
</form>