JSPM

@minsize/rtl

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

Lightweight, fast and type-safe runtime type validation for TypeScript

Package Exports

  • @minsize/rtl
  • @minsize/rtl/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 (@minsize/rtl) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

RTI

Минималистичная библиотека для runtime-валидации данных в TypeScript с выводом типов.

npm install @minsize/rti
import * as rti from "@minsize/rti"

const userSchema = rti.object({
  id: rti.pipe(rti.number(), rti.integer(), rti.positive()),
  name: rti.pipe(rti.string(), rti.trim(), rti.min(2), rti.max(50)),
  email: rti.pipe(rti.string(), rti.email()),
  createdAt: rti.date(),
})

const result = userSchema({
  id: 1,
  name: "  Alex  ",
  email: "alex@example.com",
  createdAt: "2024-01-01T00:00:00.000Z",
})

if (result.ok) {
  result.value.name
  // "Alex"

  result.value.createdAt instanceof Date
  // true
}

Возможности

  • Примитивы: string, number, bigint, boolean, date, symbol, blob, file, promise, any, unknown
  • Структуры: object, looseObject, strictObject, array, tuple, record, map, set, union
  • Object utilities: pick, omit, partial, required, merge, keyof
  • Модификаторы: optional, null, nullable, nullish, defaultValue, fallback, brand, readonly
  • Ограничения: min, max, check, instance, mimeType
  • Числа: integer, float, finite, safeInteger, positive, negative, multipleOf, nan, infinity
  • Строки: email, url, uuid, cuid1, cuid2, ulid, nanoid, hexColor, base64, creditCard, ip
  • Типы: InferInput, InferOutput, Result, Schema

Документация

Полная GitBook-документация лежит в docs/README.md.

Навигация для GitBook: SUMMARY.md.