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

small-type-forms

v1.0.0

Published

TypeScript forms & validation library

Readme

small-forms-ts

Small Forms TS est une librairie de forms & validation inspirée du package PHP small/forms.
Elle apporte un système de formulaires typés, de validation, de transformation (modifiers),
ainsi qu'un support avancé pour DTOs via décorateurs et adaptateurs.

Ce package est conçu pour :

  • Node
  • SvelteKit
  • Front-end TypeScript
  • DTOs & mapping
  • Interopérabilité small/type-dependency-injection

Installation

npm install small-forms-ts reflect-metadata

Ajoutez dans votre tsconfig.json :

{
  "experimentalDecorators": true,
  "emitDecoratorMetadata": true
}

Puis dans votre bootstrap :

import "reflect-metadata";

Quick Start

import {
  FormBuilder,
  StringType,
  NumberType,
  ValidateRequired,
  ValidateEmail,
  TrimModifier
} from "small-forms-ts";

const form = FormBuilder.create()
  .addField("email", new StringType(), [
    new ValidateRequired(),
    new ValidateEmail()
  ], [
    new TrimModifier()
  ])
  .addField("age", new NumberType())
  .getForm();

form.fill({ email: "  [email protected] ", age: "33" });

form.validate();

console.log(form.toObject());

FormBuilder

FormBuilder.create()
  .addField("name", new StringType())
  .addField("age", new NumberType())
  .getForm();

Types

  • StringType
  • NumberType
  • BooleanType
  • DateType

Rules (Validators)

Tous les validateurs implémentent :

interface Rule {
  validate(value: unknown, data?: Record<string, unknown>): string | null;
}

Listes des ValidateXXX :

ValidateAtLeastOneOf
ValidateBoolean
ValidateCallback
ValidateChoice
ValidateCountLessOrEqualThan
ValidateCountGreaterThan
ValidateCountLessThan
ValidateDateTime
ValidateDecimal
ValidateDivisibleBy
ValidateEmail
ValidateString
ValidateStringArray
ValidateUnique
ValidateEmpty
ValidateEqual
ValidateFloat
ValidateFloatArray
ValidateGreater
ValidateGreaterOrEqual
ValidateInt
ValidateIntArray
ValidateIsFalse
ValidateIsNull
ValidateIsTrue
ValidateJson
ValidateLess
ValidateLessOrEqual
ValidateMatchRegex
ValidateMixedArray
ValidateNegativeNumber
ValidateNotEmpty
ValidateNotEqual
ValidateNotMatchRegex
ValidateNotNull
ValidateNumberCharsBetween
ValidateNumberCharLessThan
ValidatePositiveNumber
ValidateRange
ValidateRequired
ValidateSequencialy
ValidateInteger


Modifiers

Tous implémentent :

interface Modifier {
  apply(value: unknown): unknown;
}

Modifiers inclus :

ExplodeModifier
FalseIfEmptyModifier
FormBooleanToPhpModifier
ImplodeModifier
LTrimModifier
NullIfEmptyModifier
RoundModifier
RTrimModifier
StringToDateTimeImmutableModifier
StringToDateTimeModifier
SubStrModifier
ToLowerModifier
ToUpperModifier
TrimModifier
UcFirstModifier
UcWordsModifier


Décorateurs

class UserDTO {
  @FormField(new StringType(), { rules: [new ValidateRequired()] })
  name!: string;

  @FormField(new NumberType())
  age!: number;
}

Adapters

ClassAdapter

const form = ClassAdapter.from(UserDTO);
form.fill(dto);
form.validate();

ObjectAdapter

const form = ObjectAdapter.fromObject({ name: "seb", age: 33 });

Intégration SvelteKit

export const actions = {
  default: async ({ request }) => {
    const data = Object.fromEntries(await request.formData());
    const form = ObjectAdapter.fromObject(data);

    try {
      form.validate();
      return { success: true };
    } catch (e) {
      return fail(400, { errors: e.errors });
    }
  }
};

Intégration API Node

app.post("/login", (req, res) => {
  const form = ObjectAdapter.fromObject(req.body);

  try {
    form.validate();
    res.json(form.toObject());
  } catch (e) {
    res.status(400).json(e.errors);
  }
});

Licence

MIT — Sébastien Kus
https://small-project.dev