typia icon indicating copy to clipboard operation
typia copied to clipboard

Add a new function `TSON.random<T>(): T`

Open samchon opened this issue 1 year ago • 1 comments

https://github.com/samchon/nestia/issues/141

@SkyaTura suggested a good idea in nestia, but typescript-json seems more suitable.

Create a transformer function that generates a random data following its generic argument type.

export function random<T>(): T;

Also, TypeScript compiler has started supporting AST features even in the descriptive comments since 4.7 update. Therefore, study the new TypeScript compiler AST and check whether writing script in comment is possible or not like below.

export interface IMember {
    /**
     * E-mail address of member.
     *
     * {@validate Validator.email}
     * {@random RandomGenerator.email}
     */
    email: string;
}

samchon avatar Aug 15 '22 12:08 samchon

This type of annotation would be useful for string masking as well.

Also, maybe, presets/alias to set repetitive combination of helpers, like email. (But I don't really know what to think about this being too "magically" abstracted)

SkyaTura avatar Aug 16 '22 02:08 SkyaTura

I'm sorry for give up this issue. I've failed to find how to generate random data of patterned string

samchon avatar Oct 01 '22 15:10 samchon