typia
v7.5.1
// RUNTIME VALIDATORS
export function is < T > ( input : unknown ) : input is T ; // returns boolean
export function assert < T > ( input : unknown ) : T ; // throws TypeGuardError
export function assertGuard < T > ( input : unknown ) : asserts input is T ;
export function validate < T > ( input : unknown ) : IValidation < T > ; // detailed
// JSON FUNCTIONS
export namespace json {
export function application < T > ( ) : IJsonApplication ; // JSON schema
export function assertParse < T > ( input : string ) : T ; // type safe parser
export function assertStringify < T > ( input : T ) : string ; // safe and faster
}
// LLM FUNCTION CALLING SCHEMA
export namespace llm {
// application schema from a class or interface type
export function application < App , Model > ( ) : ILlmApplication < Model > ;
// structured output
export function parameters < P , Moodel > ( ) : ILlmSchema . IParameters < Model > ;
export function schema < T , Model > ( ) : ILlmSchema < Model > ; // type schema
}
// PROTOCOL BUFFER
export namespace protobuf {
export function message < T > ( ) : string ; // Protocol Buffer message
export function assertDecode < T > ( buffer : Uint8Array ) : T ; // safe decoder
export function assertEncode < T > ( input : T ) : Uint8Array ; // safe encoder
}
// RANDOM GENERATOR
export function random < T > ( g ?: Partial < IRandomGenerator > ) : T ; typia是一个变压器库,支持以下功能:
笔记
class-validator快20,000倍class-transformer快200倍如果您调用typia功能,则将如下所示。
这是typia的关键概念,将打字稿类型转换为运行时函数。通过在编译级别分析目标T型T,将typia.is<T>()函数转换为专用类型检查器。
此功能使开发人员能够确保在应用程序中键入安全性,从而利用打字稿的静态键入,同时还提供运行时验证。您可以简单地使用纯打字条类型本身,而不是定义其他模式。
//----
// examples/checkString.ts
//----
import typia , { tags } from "typia" ;
export const checkString = typia . createIs < string > ( ) ;
//----
// examples/checkUUID.js
//----
import typia from "typia" ;
export const checkString = ( ( ) => {
return ( input ) => "string" === typeof input ;
} ) ( ) ; 感谢您的支持。
您的捐赠鼓励typia发展。
此外, typia正在将一半捐赠给typia核心贡献者的一半。
nonara/ts-patchryoppippi/unplugin-typia您可以通过Playground网站体验典型的工作方式:
在网站上查看文档:
assert()函数is()函数validate()函数stringify()函数parse()函数application()函数parameters()函数schema()函数decode()函数encode()函数dev.to文章