Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
// RUNTIME VALIDATORS
export function is<T>(input: unknown | T): input is T; // returns boolean
export function assert<T>(input: unknown | T): T; // throws TypeGuardError
export function validate<T>(input: unknown | T): IValidation<T>; // detailed
// 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
// +) isParse, validateParse
// +) stringify, isStringify, validateStringify
// PROTOCOL BUFFER
export function message<T>(): string; // Protocol Buffer message
export function assertDecode<T>(buffer: Buffer): T; // safe decoder
export function assertEncode<T>(input: T): Uint8Array; // safe encoder
// +) decode, isDecode, validateDecode
// +) encode, isEncode, validateEncode
typia
is a transformer library of TypeScript, supporting below features:
All functions in typia
require only one line. You don't need any extra dedication like JSON schema definitions or decorator function calls. Just call typia
function with only one line like typia.assert<T>(input)
.
Also, as typia
performs AOT (Ahead of Time) compilation skill, its performance is much faster than other competitive libaries. For an example, when comparing validate function is()
with other competitive libraries, typia
is maximum 15,000x times faster than class-validator
.
Measured on Intel i5-1135g7, Surface Pro 8
Thanks for your support.
Your donation would encourage typia
development.
npx typia setup
Just type npx typia setup
, that's all.
Also, you can specify package manager or target tsconfig.json
file like below:
npx typia setup --manager npm
npx typia setup --manager pnpm
npx typia setup --manager yarn
npx typia setup --project tsconfig.json
npx typia setup --project tsconfig.test.json
After the setup, you can compile typia
utilization code by using ttsc
(ttypescript
) command. If you want to run your TypeScript file directly through ts-node
, add -C ttypescript
argument like below:
# COMPILE THROUGH TTYPESCRIPT
npx ttsc
# RUN TS-NODE WITH TTYPESCRIPT
npx ts-node -C ttypescript src/index.ts
If you want to install and setup typia
manually, read Guide Documents - Setup.
Also, by Guide Documents - Setup section, you can learn how to use pure TypeScript compiler tsc
through ts-patch
, instead of using the ttypescript
compiler with ttsc
command.
When you want to setup typia
on your frontend project with vite
, just configure vite.config.ts
like below.
For reference, don't forget running Setup Wizard before.
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import typescript from "@rollup/plugin-typescript";
import ttsc from "ttypescript";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
typescript({
typescript: ttsc,
})
]
});
In here README documents, only summarized informations are provided.
For more details, refer to the Guide Documents (wiki).
- Runtime Validators
- Enhanced JSON
- Protocol Buffer
// ALLOW SUPERFLUOUS PROPERTIES
export function is<T>(input: T | unknown): input is T; // returns boolean
export function assert<T>(input: T | unknown): T; // throws `TypeGuardError`
export function validate<T>(input: T | unknown): IValidation<T>; // detailed
// DO NOT ALLOW SUPERFLUOUS PROPERTIES
export function equals<T>(input: T | unknown): input is T;
export function assertEquals<T>(input: T | unknown): T;
export function validateEquals<T>(input: T | unknown): IValidation<T>;
// REUSABLE FACTORY FUNCTIONS
export function createIs<T>(): (input: unknown) => input is T;
export function createAssert<T>(): (input: unknown) => T;
export function createValidate<T>(): (input: unknown) => IValidation<T>;
export function createEquals<T>(): (input: unknown) => input is T;
export function createAssertEquals<T>(): (input: unknown) => T;
export function createValidateEquals<T>(): (input: unknown) => IValidation<T>;
typia
supports three type of validator functions:
is()
: returns false
if not matched with the type T
assert()
: throws a TypeGuardError
when not matchedvalidate()
IValidation.ISuccess<T>
with value
propertyIValidation.IFailure
with errors
propertyAlso, if you want more strict validator functions that even do not allowing superfluous properties not written in the type T
, you can use those functions instead; equals()
, assertEquals()
, validateEquals()
. Otherwise you want to create resuable validator functions, you can utilize factory functions like createIs()
instead.
When you want to add special validation logics, like limiting range of numeric values, you can do it through comment tags. If you want to know about it, visit the Guide Documents (Features > Runtime Validators > Comment Tags).
// JSON SCHEMA GENERATOR
export function application<
Types extends unknown[],
Purpose extends "swagger" | "ajv" = "swagger",
Prefix extends string = Purpose extends "swagger"
? "#/components/schemas"
: "components#/schemas",
>(): IJsonApplication;
// SAFE PARSER FUNCTIONS
export function isParse<T>(input: string): T | null;
export function assertParse<T>(input: string): T;
export function validateParse<T>(input: string): IValidation<T>;
// FASTER STRINGIFY FUNCTIONS
export function stringify<T>(input: T): string; // unsafe
export function isStringify<T>(input: T): string | null; // safe
export function assertStringify<T>(input: T): string;
export function validateStringify<T>(input: T): IValidation<string>;
// FACTORY FUNCTIONS
export function createAssertParse<T>(): (input: string) => T;
export function createAssertStringify<T>(): (input: T) => string;
// +) createIsParse, createValidateParse
// +) createStringify, createIsStringify, createValidateStringify
typia
supports enhanced JSON functions.
application()
: generate JSON schema with only one line
assertParse()
: parse JSON string safely with type validationisStringify()
: maximum 10x faster JSON stringify fuction even type safeMeasured on AMD R7 5800H
// PROTOCOL BUFFER MESSAGE
export function message<T>(): string;
// ENCODE FUNCTIONS
export function encode<T>(input: T): Uint8Array;
export function isEncode<T>(input: T): Uint8Array | null;
export function assertEncode<T>(input: T): Uint8Array;
export function validateEncode<T>(input: T): IValidation<Uint8Array>;
// DECODE FUNCTIONS
export function decode<T>(buffer: Uint8Array): T;
export function isDecode<T>(buffer: Uint8Array): T | null;
export function assertDecode<T>(buffer: Uint8Array): T;
export function validateDecode<T>(buffer: Uint8Array): IValidation<T>;
// FACTORY FUNCTIONS
export function createDecode<T>(): (input: Uint8Array) => T;
export function createEncode<T>(): (input: T) => Uint8Array;
// +) createIsDecode, createAssertDecode, createValidateDecode
// +) createIsEncode, createAssertEncode, createValidateEncode
typia
supports Protocol Buffer.
message()
: generate Protocol Buffer schemaencode()
: encode JavaScript object to Protocol Bufferdecode()
: decode Protocol Buffer to JavaScript objectDo not need to define any *.proto
schema file. Just call above functions with generic argument T
, then typia
will generate the Protocol Buffer schema automatically, by analyzing your type T
.
If you want to add special type like float32
, you can do it through comment tags. If you want to know more about those comment tags, visit Guide Documents (Features > Protocol Buffer > Comment Tags).
Nestia is a set of helper libraries for NestJS
, supporting below features:
@nestia/core
: 15,000x times faster validation decorator using typia
@nestia/sdk
: evolved SDK and Swagger generator for @nestia/core
nestia
: just CLI (command line interface) toolimport { Controller } from "@nestjs/common";
import { TypedBody, TypedRoute } from "@nestia/core";
import type { IBbsArticle } from "@bbs-api/structures/IBbsArticle";
@Controller("bbs/articles")
export class BbsArticlesController {
/**
* Store a new content.
*
* @param inupt Content to store
* @returns Newly archived article
*/
@TypedRoute.Post() // 10x faster and safer JSON.stringify()
public async store(
@TypedBody() input: IBbsArticle.IStore // super-fast validator
): Promise<IBbsArticle>;
// do not need DTO class definition,
// just fine with interface
}
FAQs
Superfast runtime validators with only one line
The npm package typia receives a total of 82,170 weekly downloads. As such, typia popularity was classified as popular.
We found that typia demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.