typia

Super-fast/easy runtime validations and serializations through transformation

MIT License

Downloads
429.9K
Stars
4.4K
Committers
87

Bot releases are visible (Hide)

typia - v3.2.5

Published by samchon about 2 years ago

What's Changed

Full Changelog: https://github.com/samchon/typescript-json/compare/v3.2.4...v3.2.5

typia - v3.2.4

Published by samchon about 2 years ago

typia - v3.2.3

Published by samchon about 2 years ago

Special thans for @paulrostorp

What's Changed

Full Changelog: https://github.com/samchon/typescript-json/compare/v3.2.2...v3.2.3

typia - v3.2.2

Published by samchon about 2 years ago

What's Changed

Full Changelog: https://github.com/samchon/typescript-json/compare/v3.2.1...v3.2.2

New tags:

  • @exclusiveMinimum
  • @exclusiveMaximum
  • @multipleOf
  • @step
typia - v3.2.1

Published by samchon about 2 years ago

Thanks for many contributors who've participated in benchmark.

Since v3.2 update, typescript-json has started supporting comment tags.

Below table shows list of supported comment tags. You can utilize those tags by writing in comments like below example structure TagExample. Look at them and utilize those comment tags to make your TypeScript program to be safer and more convenient.

Also, don't worry about taking a mistake on using those comment tags. In that case, compile error would be occured. By the compile level error detection, typescript-json is much stronger than any other runtime validator libraries using decorator functions, which can't catch any mistake on the compilation level.

Tag Kind Target Type
@type {"int"|"uint"} number
@range (number, number] number
@minimum {number} number
@maximum {number} number
@length {number} | [number, number) string
@minLength {number} string
@maxLength {number} string
@format {"email"|"uuid"|"url"|"ipv4"|"ipv6"} string
@pattern {string} string
export interface TagExample {
    /* -----------------------------------------------------------
        ARRAYS
    ----------------------------------------------------------- */
    /**
     * You can limit array length like below.
     * 
     * @minItems 3
     * @maxItems 10
     * 
     * Also, you can use `@items` tag instead.
     * 
     * @items (5, 10] --> 5 < length <= 10
     * @items [7      --> 7 <= length
     * @items 12)     --> length < 12
     * 
     * Furthermore, you can use additional tags for each item.
     * 
     * @type uint
     * @format uuid
     */
    array: Array<string|number>;

    /**
     * If two-dimensional array comes, length limit would work for 
     * both 1st and 2nd level arraies. Also using additional tags 
     * for each item (string) would still work.
     * 
     * @items (5, 10)
     * @format url
     */
    matrix: string[][];

    /* -----------------------------------------------------------
        NUMBERS
    ----------------------------------------------------------- */
    /**
     * Type of number.
     * 
     * It must be one of integer or unsigned integer.
     * 
     * @type int
     * @type uint
     */
    type: number;

    /**
     * You can limit range of numeric value like below.
     * 
     * @minimum 5
     * @maximum 10
     * 
     * Also, you can use `@range` tag instead.
     * 
     * @range (5, 10] --> 5 < x <= 10
     * @range [7      --> 7 <= x
     * @range 12)     --> x < 12
     */
    range: number;

    /* -----------------------------------------------------------
        STRINGS
    ----------------------------------------------------------- */
    /**
     * You can limit string length like below.
     * 
     * @minLength 3
     * @maxLength 10
     * 
     * Also, you can use `@length` tag instead.
     * 
     * @length 10      --> length = 10
     * @length [3, 7]  --> 3 <= length && length <= 7
     * @length (5, 10) --> 5 < length && length < 10
     * @length [4      --> 4 < length
     * @length 7)      --> length < 7
     */
    length: string;

    /**
     * Mobile number composed by only numbers.
     * 
     * Note that, `typescript-json` does not support flag of regex,
     * because JSON schema definition does not suppor it either.
     * Therefore, write regex pattern without `/` characters and flag.
     * 
     * @pattern ^0[0-9]{7,16} 
     *     -> RegExp(/[0-9]{7,16}/).test("01012345678")
     */
    mobile: string;

    /**
     * E-mail address.
     * 
     * @format email
     */
    email: string;

    /**
     * UUID value.
     * 
     * @format uuid
     */
    uuid: string;

    /**
     * URL address.
     * 
     * @format url
     */
    url: string;

    /**
     * IPv4 address.
     * 
     * @format ipv4
     */
    ipv4: string;

    /**
     * IPv6 address.
     * 
     * @format ipv6
     */
    ipv6: string;
}

What's Changed

New Contributors

Full Changelog: https://github.com/samchon/typescript-json/compare/v3.1.1...v3.2.1

typia - v3.1.1

Published by samchon over 2 years ago

What's Changed

Full Changelog: https://github.com/samchon/typescript-json/compare/v3.0.12...v3.1.1

A new function validate() has come.

The validate() function archives all type errors into an IValidation.errors array, which being returned by the validate() function.

Special thanks for @edobrb who've suggested this validate() function.

export function validate<T>(input: T): IValidation;

export interface IValidation {
    success: boolean;
    errors: IValidation.IError[];
}
export namespace IValidation {
    export interface IError {
        path: string;
        expected: string;
        value: any;
    }
}
typia - v3.0.12

Published by samchon over 2 years ago

typia - v3.0.10

Published by samchon over 2 years ago

What's Changed

Full Changelog: https://github.com/samchon/typescript-json/compare/v3.0.9...v3.0.10

typia - v3.0.9

Published by samchon over 2 years ago

What's Changed

Full Changelog: https://github.com/samchon/typescript-json/compare/v3.0.8...v3.0.9

typia - v3.0.8

Published by samchon over 2 years ago

typia - v3.0.7

Published by samchon over 2 years ago

typia - v3.0.6

Published by samchon over 2 years ago

typia - v3.0.5

Published by samchon over 2 years ago

What's Changed

Full Changelog: https://github.com/samchon/typescript-json/compare/v3.0.4...v3.0.5

typia - v3.0.4

Published by samchon over 2 years ago

What's Changed

Full Changelog: https://github.com/samchon/typescript-json/compare/v3.0.3...v3.0.4

typia - v3.0.3

Published by samchon over 2 years ago

typia - v3.0.2

Published by samchon over 2 years ago

Summary

import TSON from "typescript-json";

//----
// MAIN FUNCTIONS
//----
TSON.assertType<T>(input); // runtime type checker throwing exception
TSON.is<T>(input); // runtime type checker returning boolean
TSON.stringify<T>(input); // 5x faster JSON.stringify()

//----
// APPENDIX FUNCTIONS
//----
TSON.application<[T, U, V], "swagger">(); // JSON schema application generator
TSON.create<T>(input); // 2x faster object creator (only one-time construction)

JSON String Conversion Benchmark

From now on, typescript-json is not a wrapper library of fast-json-stringify. It converts to JSON string by its optimal algorithm. By the new algorithm, typescript-json generates JSON string much faster and safer. Also, its optimizer plan construction time is over 10,000 times faster than the previous fast-json-stringify.

Also, typescript-json supports runtime type checker functions. The new runtime type checker functions are much stronger and safer than ever. Only typescript-json can validate complicate union typed structures. Other simliar libraries like ajv, io-ts or typescript-is, all of them cannot understand the complicate union type.

Runtime Type Checker Benchmark

What's Changed

Full Changelog: https://github.com/samchon/typescript-json/compare/v2.1.6...v3.0.2

typia - v2.1.6

Published by samchon over 2 years ago

What's Changed

Features

  • ESLint and Prettier
  • Support tuple type
  • Support constant value type
  • Support enumeration type
  • Fix error when template literal type on generic type

Full Changelog: https://github.com/samchon/typescript-json/compare/v2.1.5...v2.1.6

typia - v2.1.5

Published by samchon over 2 years ago

Updates for the 3rd party library nestia, for the swagger.json generation.

What's Changed

Full Changelog: https://github.com/samchon/typescript-json/compare/v2.1.1...v2.1.5

typia - v2.1.1

Published by samchon over 2 years ago

What's Changed

Full Changelog: https://github.com/samchon/typescript-json/compare/v2.1.0...v2.1.1

Package Rankings
Top 1.44% on Npmjs.org
Badges
Extracted from project README
GitHub license npm version Downloads Build Status Guide Documents Sponsers