github samchon/typia v3.7.1

latest releases: v6.12.0, v6.11.4, v6.11.3...
19 months ago

From now on, customization of random data generation is possible:

import typia from "typia";

export interface TagCustom {
    /**
     * Regular feature supported by typia
     *
     * @format uuid
     */
    id: string;

    /**
     * Custom feature composed with "$" + number
     *
     * @dollar
     */
    dollar: string;

    /**
     * Custom feature composed with string + "abcd"
     *
     * @postfix abcd
     */
    postfix: string;

    /**
     * Custom feature meaning x^y
     *
     * @powerOf 10
     */
    log: number;
}

const data: TagCustom = typia.random<TagCustom>({
    customs: {
        string: (tags: typia.IRandomGenerator.ICommentTag[]) => {
            if (tags.find((t) => t.name === "dollar") !== undefined)
                return "$" + RandomGenerator.integer();

            const postfix = tags.find((t) => t.name === "postfix");
            if (postfix !== undefined)
                return RandomGenerator.string() + postfix.value;
        },
        number: (tags: typia.IRandomGenerator.ICommentTag[]) => {
            const powerOf = tags.find((t) => t.name === "powerOf");
            if (powerOf !== undefined)
                return Math.pow(
                    Number(powerOf.value),
                    RandomGenerator.integer(1, 4),
                );
        },
    }
});

What's Changed

Full Changelog: v3.7.0...v3.7.1

Don't miss a new typia release

NewReleases is sending notifications on new releases.