github samchon/typia v3.2.1

latest releases: v6.11.3, v6.11.2, v6.11.1...
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: v3.1.1...v3.2.1

Don't miss a new typia release

NewReleases is sending notifications on new releases.