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

formfatecore

v0.12.1

Published

React Hook Form context for form generating libraries

Downloads

931

Readme

Form Validator Core

This library provides a schema-based form validation system using zod. It allows you to define form fields, their types, validation rules, and conditional logic in a structured JSON format.

Installation

To use the library, install formfatecore :

npm i formfatecore

Usage

Importing the Schema

Import the jsonFormSchema from the library:

import { FormDefinition, useFormFate } from "formfatecore";


... 


const form = useFormFate(formDefinitionObject);
const { handleSubmit, control, setValue, watch } = form;

JSON Schema Structure

The JSON schema for a form should follow this structure:

Root Object

  • name (optional): A string representing the name of the form.
  • properties: An object where each key is the field name, and the value is the field definition (see below for field types).
  • buttons (optional): An array of button definitions.

Field Types

The properties object supports the following field types:

  1. Text Field

    {
        "type": "text",
        "title": "Your Name",
        "description": "Enter your full name",
        "required": true,
        "minLength": 3,
        "maxLength": 50
    }
  2. Password Field

    {
        "type": "password",
        "title": "Password",
        "description": "Enter a secure password",
        "required": true,
        "minLength": 8
    }
  3. Email Field

    {
        "type": "email",
        "title": "Email Address",
        "description": "Enter your email",
        "required": true
    }
  4. Date Field

    {
        "type": "date",
        "title": "Date of Birth",
        "description": "Select your birth date"
    }
  5. Time Field

    {
        "type": "time",
        "title": "Preferred Time",
        "description": "Select a time"
    }
  6. URL Field

    {
        "type": "url",
        "title": "Website",
        "description": "Enter your website URL"
    }
  7. Select Field

    {
        "type": "select",
        "title": "Country",
        "description": "Select your country",
        "options": [
            { "label": "USA", "value": "us" },
            { "label": "Canada", "value": "ca" }
        ],
        "required": true
    }
  8. Radio Field

    {
        "type": "radio",
        "title": "Gender",
        "description": "Select your gender",
        "options": [
            { "label": "Male", "value": "male" },
            { "label": "Female", "value": "female" }
        ]
    }
  9. Number Field

    {
        "type": "number",
        "title": "Age",
        "description": "Enter your age",
        "required": true
    }
  10. Boolean Field

    {
        "type": "boolean",
        "title": "Subscribe",
        "description": "Subscribe to our newsletter"
    }
  11. Checkbox Field

    {
        "type": "checkbox",
        "title": "Accept Terms",
        "description": "I agree to the terms and conditions",
        "required": true
    }
  12. Custom Field

    {
        "type": "custom",
        "title": "Custom Field",
        "customProperty": "value"
    }

Conditional Logic

Fields can include a conditional object to define dependencies on other fields:

{
    "conditional": {
        "field": "subscribe",
        "state": true,
        "equal": "yes"
    }
}

Buttons

Buttons can be defined as follows:

{
    "buttons": [
        {
            "type": "submit",
            "label": "Submit",
            "variant": "primary"
        },
        {
            "type": "reset",
            "label": "Reset"
        }
    ]
}

Validation

To validate a JSON schema, use the jsonFormSchema:

const formData = {
    name: "Example Form",
    properties: {
        username: {
            type: "text",
            title: "Username",
            description: "Enter your username",
            required: true
        }
    },
    buttons: [
        { type: "submit", label: "Submit" }
    ]
};

try {
    jsonFormSchema.parse(formData);
    console.log("Form is valid!");
} catch (error) {
    console.error("Validation failed:", error.errors);
}

License

This library is open-source and available under the MIT license.