/minform

2.2kb Typescript Schema Validation - A light weight validation package for minimal web forms

Primary LanguageTypeScriptMIT LicenseMIT

Minform

NPM Version npm bundle size

2.2KB Typescript Schema Validation - Zod alternative


Table of contents

Installation

You need to have typescript installed in your project

npm install minform
yarn add minform
pnpm add minform
bun add minform

Basic Usage

import mf from "minform";

type User = {
  name: string;
  age: number;
  email: string;
  password: string;
};

const schema = mf.schema<User>({
  name: mf.string().min(3).max(30, "my custom error").required(),
  age: mf.number().min(18, "my custom error").max(100).required(),
  email: mf.string().email("my custom error").required(),
  password: mf.string().min(8).required("my custom error"),
});

// string[]
const arrayOfErrorMessages = schema.validate({
  name: "John Doe",
  email: "johndoe@gmail.com",
  age: 25,
  password: "12345678",
});

Motivation

There are a lot of powerful validation packages out there but sometimes you don't need all that power, you just need something simple and lightweight for your simple forms.

But the main reason I created this package is to learn Github Actions, Changeset, Jest Testing, publishing packages to NPM and other more.