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
Минималистичная библиотека для валидации данных в TypeScript с выводом типов на этапе разработки.
Установка
npm install @minsize/rtiБыстрый пример
import * as rti from "@minsize/rti"
const userSchema = rti.object({
id: rti.pipe(rti.number(), 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(),
bio: rti.defaultValue(rti.string(), ""),
tags: rti.array(rti.string()),
})
const result = userSchema({
id: 1,
name: " Alex ",
email: "alex@example.com",
createdAt: "2024-01-01T00:00:00.000Z",
tags: ["ts", "validation"],
})
if (result.ok) {
console.log(result.value.name) // "Alex"
console.log(result.value.createdAt instanceof Date) // true
} else {
console.error(result.error)
}Что умеет RTI
- Примитивы:
string,number,boolean,date,any,unknown - Структуры:
object,array,tuple,record,union - Модификаторы:
optional,null,nullable,nullish,defaultValue,fallback - Композиция:
pipe,transform - Ограничения:
min,max,check,instance - Числовые проверки:
integer,float,finite,safeInteger,positive,negativeи другие - Строковые проверки:
email,regex,includes,startsWith,endsWith,trimи другие - Вывод типов через
InferInputиInferOutput
Документация
Полная документация для GitBook лежит в docs/README.md.
Если хочешь открыть её как книгу, используй SUMMARY.md.