Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "refactor: improve tree-shaking in ESM target" #1128

Merged
merged 1 commit into from
Jun 27, 2024

Conversation

samchon
Copy link
Owner

@samchon samchon commented Jun 27, 2024

Reverts #1124 - @ryoppippi

It is due to RandomGenerator.mjs file be generated like below:

import RandExp from '../../node_modules/.pnpm/randexp@0.5.3/node_modules/randexp/lib/randexp.mjs';

const ALPHABETS = "abcdefghijklmnopqrstuvwxyz";
/* -----------------------------------------------------------
  REGULAR
----------------------------------------------------------- */
const boolean = () => Math.random() < 0.5;
const integer = (min, max) => {
    min ??= 0;
    max ??= 100;
    return Math.floor(Math.random() * (max - min + 1)) + min;
};
const bigint = (min, max) => BigInt(integer(Number(min ?? BigInt(0)), Number(max ?? BigInt(100))));
const number = (min, max) => {
    min ??= 0;
    max ??= 100;
    return Math.random() * (max - min) + min;
};
const string = (length) => new Array(length ?? integer(5, 10))
    .fill(0)
    .map(() => ALPHABETS[integer(0, ALPHABETS.length - 1)])
    .join("");
const array = (closure, count) => new Array(count ?? length()).fill(0).map((_e, index) => closure(index));
const pick = (array) => array[integer(0, array.length - 1)];
const length = () => integer(0, 3);
const pattern = (regex) => {
    const r = new RandExp(regex);
    for (let i = 0; i < 10; ++i) {
        const str = r.gen();
        if (regex.test(str))
            return str;
    }
    return r.gen();
};
/* -----------------------------------------------------------
  SECIAL FORMATS
----------------------------------------------------------- */
// SPECIAL CHARACTERS
const byte = () => "vt7ekz4lIoNTTS9sDQYdWKharxIFAR54+z/umIxSgUM=";
const password = () => string(integer(4, 16));
const regex = () => "/^(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)$/";
const uuid = () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
    const r = (Math.random() * 16) | 0;
    const v = c === "x" ? r : (r & 0x3) | 0x8;
    return v.toString(16);
});
// ADDRESSES
const email = () => `${string(10)}@${string(10)}.${string(3)}`;
const hostname = () => `${string(10)}.${string(3)}`;
const idnEmail = () => email();
const idnHostname = () => hostname();
const iri = () => url();
const iriReference = () => url();
const ipv4 = () => array(() => integer(0, 255), 4).join(".");
const ipv6 = () => array(() => integer(0, 65535).toString(16), 8).join(":");
const uri = () => url();
const uriReference = () => url();
const uriTemplate = () => url();
const url = () => `https://${string(10)}.${string(3)}`;
// TIMESTAMPS
const datetime = (min, max) => new Date(number(min ?? Date.now() - 30 * DAY, max ?? Date.now() + 7 * DAY)).toISOString();
const date = (min, max) => new Date(number(min ?? 0, max ?? Date.now() * 2))
    .toISOString()
    .substring(0, 10);
const time = () => new Date(number(0, DAY)).toISOString().substring(11);
const duration = () => {
    const period = durate([
        ["Y", integer(0, 100)],
        ["M", integer(0, 12)],
        ["D", integer(0, 31)],
    ]);
    const time = durate([
        ["H", integer(0, 24)],
        ["M", integer(0, 60)],
        ["S", integer(0, 60)],
    ]);
    if (period.length + time.length === 0)
        return "PT0S";
    return `P${period}${time.length ? "T" : ""}${time}`;
};
// POINTERS
const jsonPointer = () => `/components/schemas/${string(10)}`;
const relativeJsonPointer = () => `${integer(0, 10)}#`;
const DAY = 86400000;
const durate = (elements) => elements
    .filter(([_unit, value]) => value !== 0)
    .map(([unit, value]) => `${value}${unit}`)
    .join("");

export { array, bigint, boolean, byte, date, datetime, duration, email, hostname, idnEmail, idnHostname, integer, ipv4, ipv6, iri, iriReference, jsonPointer, length, number, password, pattern, pick, regex, relativeJsonPointer, string, time, uri, uriReference, uriTemplate, url, uuid };
//# sourceMappingURL=RandomGenerator.mjs.map

@samchon samchon added the bug Something isn't working label Jun 27, 2024
@samchon samchon self-assigned this Jun 27, 2024
@samchon samchon merged commit e5add3e into master Jun 27, 2024
6 checks passed
@samchon samchon deleted the revert-1124-feature/improve-tree-shaking-build branch June 27, 2024 05:04
@ryoppippi
Copy link
Contributor

Oh, really.
I'll investigate it. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants