JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 224
  • Score
    100M100P100Q29046F
  • License MIT

Minimal validation library in TypeScript

Package Exports

  • @the-minimal/validator
  • @the-minimal/validator/build/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@the-minimal/validator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Validator image

@the-minimal/validator

Minimalist TypeScript data validation library with great focus on size and performance.

Highlights

  • Fully type safe
  • 500 bytes bundle
  • Minimal overhead
  • Validation only
  • No dependencies
  • No compilation

Concept

Compared to most other data validation libraries @the-minimal/validator doesn't support data transformations or coercions.

It has one focus and that is data validation.

The reasoning is that in most cases we control both the sender and receiver so validations such as age: number().or(coerce.number()) are simply not necessary since we can make sure we send only one type (number) to the receiver.

In other words we rely on the third party to normalize data before it gets send.

Once the data is validated it can then be manually mapped into a different shape if needed.

However this is generally frowned upon because if we immediately map input data into a different shape then the sended could have just send the data in the desired shape instead.

Example

import { object, and, string, email, minLength } from "@the-minimal/validator"; // 350 bytes

// Creates login schema with email and password
const login = object({
  email: and([string, email]),
  password: and([string, minLength(8)]),
});

// Throws error for `email`
login({ email: '', password: '' });

// Asserts data as { email: string; password: string }
login({ email: 'jane@example.com', password: '12345678' });