Cookie Consent by Free Privacy Policy Generator ๐Ÿ“Œ [TS] I made Ultimate Random Generator which can make Everything

๐Ÿ  Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeitrรคge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden รœberblick รผber die wichtigsten Aspekte der IT-Sicherheit in einer sich stรคndig verรคndernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch รผbersetzen, erst Englisch auswรคhlen dann wieder Deutsch!

Google Android Playstore Download Button fรผr Team IT Security



๐Ÿ“š [TS] I made Ultimate Random Generator which can make Everything


๐Ÿ’ก Newskategorie: Programmierung
๐Ÿ”— Quelle: dev.to

Outline

I made ultimate random generator which can make everything.

Just call typia.random<T>() function, then it will generate matched random data.

From now on, don't be plagued by random data creation, especially when constructing mockup data. We just need to call the typia.random<T>() function with only one line. It will do everything for you.

import typia from "typia";

//----
// RANDOM DATA GENERATION
//----
const member: IMembere = typia.random<IMembere>();
console.log(member);

//----
// SCHEMA DEFINITION
//----
interface IMember {
    /**
     * @format uuid
     */
    id: string;

    /**
     * @minLength 3
     * @maxLength 20
     */
    account: string;

    /**
     * @format email
     */
    email: string | null;

    sex: "male" | "female";

    loginHistories: ILoginHistory[];
}
interface ILoginHistory {
    /**
     * @format ipv4
     */
    ip: string;

    success: boolean;

    /**
     * @format date-time
     */
    created_at: string;    
}
{
  "id": "7ea48b93-d201-4a16-a649-546b41c77459",
  "account": "uusucswmjiflzur",
  "email": "[email protected]",
  "sex": "male",
  "loginHistories": [
    {
      "ip": "101.51.96.72",
      "success": false,
      "created_at": "2027-05-30T07:35:02.626Z"
    }
  ]
}

Principles

AOT (Ahead of Time) compilation, that's how the typia.random<T>() function can generate all random data in just one line.

When you write above typia.random<IMember>() function and compiles the code, typia will analyze the IMember type. After analyzing, typia will write random data generation code suitable for the IMember type, in the compilation level.

Below is the actual JavaScript code written by typia, in the compilation level. This is the AOT compilation.

const member = ((generator) => {
    const $generator = typia.random.generator;
    const $pick = typia.random.pick;
    const $ro0 = (_recursive = false, _depth = 0) => ({
        id: (generator?.customs ?? $generator.customs)?.string?.([
            {
                name: "format",
                value: "uuid"
            }
        ]) ?? (generator?.uuid ?? $generator.uuid)(),
        account: (generator?.customs ?? $generator.customs)?.string?.([
            {
                name: "minLength",
                value: "3"
            },
            {
                name: "maxLength",
                value: "20"
            }
        ]) ?? (generator?.string ?? $generator.string)((generator?.integer ?? $generator.integer)(3, 20)),
        email: $pick([
            () => null,
            () => (generator?.customs ?? $generator.customs)?.string?.([
                {
                    name: "format",
                    value: "email"
                }
            ]) ?? (generator?.email ?? $generator.email)()
        ])(),
        sex: $pick([
            () => "male",
            () => "female"
        ])(),
        loginHistories: (generator?.array ?? $generator.array)(() => $ro1(_recursive, _recursive ? 1 + _depth : _depth))
    });
    const $ro1 = (_recursive = false, _depth = 0) => ({
        ip: (generator?.customs ?? $generator.customs)?.string?.([
            {
                name: "format",
                value: "ipv4"
            }
        ]) ?? (generator?.ipv4 ?? $generator.ipv4)(),
        success: (generator?.boolean ?? $generator.boolean)(),
        created_at: (generator?.customs ?? $generator.customs)?.string?.([
            {
                name: "format",
                value: "date-time"
            }
        ]) ?? (generator?.datetime ?? $generator.datetime)()
    });
    return $ro0();
})();

Supported Types

typia supports every TypeScript type.

So, no matter how complex your type T is, the typia.random<T>() function can generate random data for it.

Below types are extreme cases, a nd no problem at all.

Also, typia is ensuring its safety through over 7,500 test functions. Thus, if you need random generator, just use typia.random() with confidence. It is the most powerful random generator than ever.

import typia from "typia";

export type IBucket = IDirectory | IShortcut | IFile;
export interface IDirectory {
    type: "directory";
    location: string;
    name: string;
    children: IBucket[];
}

// NO MATTER EVEN HOW COMPLICATE TYPE COMES
const directory: IDirectory = typia.random<IDirectory>();

Comment Tags

You can specialize random data generation by using comment tags.

Below table shows list of supported comment tags in typia.random<T>() function, and you can utilize them like below example structure TagExample.

If you want more comment tags, you can define it by yourself -> Customization

Tag Name Target Type
`@type {"int"\ "uint"}`
@minimum {number} number
@maximum {number} number
@exclusiveMinimum {number} number
@exclusiveMaximum {number} number
@multipleOf {number} number
@step {number} number
@length {number} string
@minLength {number} string
@maxLength {number} string
`@format {"email"\ "uuid"\
{% raw %}@pattern {string} string
@items {number} array
@minItems {number} array
@maxItems {number} array
export interface TagExample {
    /* -----------------------------------------------------------
        ARRAYS
    ----------------------------------------------------------- */
    /**
     * You can limit array length like below.
     * 
     * @minItems 3
     * @maxItems 10
     * 
     * Also, you can use `@items` tag to fix length.
     * 
     * @items 5
     * 
     * 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 arrays. Also using additional tags 
     * for each item (string) would still work.
     * 
     * @minItems 5
     * @maxItems 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 exclusive tags instead
     * 
     * @exclusiveMinimum 4
     * @exclusiveMaximum 11
     */
    range: number;

    /**
     * Step tag requires minimum or exclusiveMinimum tag.
     * 
     * 3, 13, 23, 33, ...
     * 
     * @step 10
     * @exclusiveMinimum 3
     */
    step: number;

    /**
     * Value must be multiple of the given number.
     * 
     * -5, 0, 5, 10, 15, ...
     * 
     * @multipleOf 5
     */
    multipleOf: number;

    /* -----------------------------------------------------------
        STRINGS
    ----------------------------------------------------------- */
    /**
     * You can limit string length like below.
     * 
     * @minLength 3
     * @maxLength 10
     * 
     * Also, you can use `@length` tag to fix length.
     * 
     * @length 7
     */
    length: string;

    /**
     * Mobile number composed by only numbers.
     * 
     * @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;

    /**
     * `YYYY-MM-DD`
     *
     * @format date
     */
    date: string;

    /**
     * Same with `Date.toISOString()`
     *
     * @format date-time
     */
    datetime: string;
}

Customization

As you can see from above Supported Comment Tags corner, typia.random<T>() can utilize comment tags for speicifying the random data generation.

By the way, if someone wants additional comment tgas that is not supported by typia, then how should do?

The answer is just define your own custom comment tags like below:

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),
                );
        },
    }
});
...



๐Ÿ“Œ [TS] I made Ultimate Random Generator which can make Everything


๐Ÿ“ˆ 69.55 Punkte

๐Ÿ“Œ I made universal Random Generator, which can make everything, by just only one line


๐Ÿ“ˆ 60.79 Punkte

๐Ÿ“Œ CVE-2013-4102 | Cryptocat up to 2.0.21 strophe.js Math.random Random random values (BID-61095 / OSVDB-95006)


๐Ÿ“ˆ 36.86 Punkte

๐Ÿ“Œ Enigmail bis 1.9.8 Random Generator Math.Random() schwache Verschlรผsselung


๐Ÿ“ˆ 35.51 Punkte

๐Ÿ“Œ FreeBSD 4.0/5.0 Random Generator /dev/random weak encryption


๐Ÿ“ˆ 35.51 Punkte

๐Ÿ“Œ Enigmail up to 1.9.8 Random Generator Math.Random() weak encryption


๐Ÿ“ˆ 35.51 Punkte

๐Ÿ“Œ Cryptocat up to 2.0.21 Random Generator strophe.js Math.random missing encryption


๐Ÿ“ˆ 35.51 Punkte

๐Ÿ“Œ CVE-2016-5085 | Johnson & Johnson Animas OneTouch Ping Random Number Generator random values (BID-93351)


๐Ÿ“ˆ 35.51 Punkte

๐Ÿ“Œ Canada's 'Random' Immigration Lottery Uses Microsoft Excel, Which Isn't Actually Random


๐Ÿ“ˆ 33.43 Punkte

๐Ÿ“Œ I made a Random Quote Generator.


๐Ÿ“ˆ 31.31 Punkte

๐Ÿ“Œ Which terminal emulator can do quick on-screen searches which can be copied to the cursor?


๐Ÿ“ˆ 26.77 Punkte

๐Ÿ“Œ Unix: How random is random?


๐Ÿ“ˆ 24.57 Punkte

๐Ÿ“Œ Enter 6 random characters to see how random you're capable of being.


๐Ÿ“ˆ 24.57 Punkte

๐Ÿ“Œ Enter 6 random characters to see how random you're capable of being.


๐Ÿ“ˆ 24.57 Punkte

๐Ÿ“Œ Weird Bug Makes Samsung Phones Text Random Photos To Random People


๐Ÿ“ˆ 24.57 Punkte

๐Ÿ“Œ StashCat up to 1.7.5 Message CryptoJS.lib.WordArray.random() math.random() weak encryption


๐Ÿ“ˆ 24.57 Punkte

๐Ÿ“Œ StashCat bis 1.7.5 Message CryptoJS.lib.WordArray.random() math.random() schwache Verschlรผsselung


๐Ÿ“ˆ 24.57 Punkte

๐Ÿ“Œ CVE-2022-31034 | Argo CD up to 2.1.15/2.2.9/2.3.4/2.4.0 SSO Login random random values (GHSA-2m7h-86qq-fp4v)


๐Ÿ“ˆ 24.57 Punkte

๐Ÿ“Œ How Truly Random are Random Numbers?


๐Ÿ“ˆ 24.57 Punkte

๐Ÿ“Œ What commonly installed program on Ubuntu accesses seemingly random files at seemingly random times?


๐Ÿ“ˆ 24.57 Punkte

๐Ÿ“Œ BurpSuite Random User-Agents - Burp Suite Extension For Generate A Random User-Agents


๐Ÿ“ˆ 24.57 Punkte

๐Ÿ“Œ random shutdown after random time


๐Ÿ“ˆ 24.57 Punkte

๐Ÿ“Œ How to Generate Random Numbers in JavaScript with Math.random()


๐Ÿ“ˆ 24.57 Punkte

๐Ÿ“Œ Random way of making a console snake by a random ๐Ÿ‘๏ธ๐Ÿ˜ƒ


๐Ÿ“ˆ 24.57 Punkte

๐Ÿ“Œ Vuln: GnuPG and Libgcrypt CVE-2016-6313 Local Predictable Random Number Generator Weakness


๐Ÿ“ˆ 23.22 Punkte

๐Ÿ“Œ Vuln: NTP 'ntp-keygen.c' Predictable Random Number Generator Weakness


๐Ÿ“ˆ 23.22 Punkte

๐Ÿ“Œ Vuln: GnuPG and Libgcrypt CVE-2016-6313 Local Predictable Random Number Generator Weakness


๐Ÿ“ˆ 23.22 Punkte











matomo