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文章