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

More format tags and fix bug of comment format tags. #942

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@
"suppress-warnings": "^1.0.2",
"tstl": "^2.5.13",
"uuid": "^9.0.1",
"typia": "D:\\github\\samchon\\typia\\typia-5.4.0.tgz"
"typia": "D:\\github\\samchon\\typia\\typia-5.4.1.tgz"
}
}
2 changes: 1 addition & 1 deletion errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"typescript": "^5.3.2"
},
"dependencies": {
"typia": "D:\\github\\samchon\\typia\\typia-5.4.0.tgz"
"typia": "D:\\github\\samchon\\typia\\typia-5.4.1.tgz"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typia",
"version": "5.4.0",
"version": "5.4.1",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-json/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-json",
"version": "5.4.0",
"version": "5.4.1",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -61,7 +61,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "5.4.0"
"typia": "5.4.1"
},
"peerDependencies": {
"typescript": ">=4.8.0 <5.5.0"
Expand Down
4 changes: 4 additions & 0 deletions src/IRandomGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export interface IRandomGenerator {
// ADDRESSES
email(): string;
hostname(): string;
idnEmail(): string;
idnHostname(): string;
iri(): string;
iriReference(): string;
ipv4(): string;
ipv6(): string;
uri(): string;
Expand Down
156 changes: 8 additions & 148 deletions src/factories/MetadataCommentTagFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Metadata } from "../schemas/metadata/Metadata";

import { Writable } from "../typings/Writable";

import { FormatCheatSheet } from "../tags/internal/FormatCheatSheet";
import { MetadataFactory } from "./MetadataFactory";
import { MetadataTypeTagFactory } from "./MetadataTypeTagFactory";

Expand Down Expand Up @@ -451,151 +452,10 @@ const parse_integer =
return value;
};

type IMetadataCommentTag =
// NUMBER
| IMetadataCommentTag.IType
| IMetadataCommentTag.IMinimum
| IMetadataCommentTag.IMaximum
| IMetadataCommentTag.IExclusiveMinimum
| IMetadataCommentTag.IExclusiveMaximum
| IMetadataCommentTag.IMultipleOf
| IMetadataCommentTag.IStep
// STRING
| IMetadataCommentTag.IFormat
| IMetadataCommentTag.IPattern
| IMetadataCommentTag.ILength
| IMetadataCommentTag.IMinLength
| IMetadataCommentTag.IMaxLength
// ARRAY
| IMetadataCommentTag.IItems
| IMetadataCommentTag.IMinItems
| IMetadataCommentTag.IMaxItems;

namespace IMetadataCommentTag {
/* -----------------------------------------------------------
NUMBER
----------------------------------------------------------- */
export interface IType {
kind: "type";
value: "int" | "uint" | "int32" | "uint32" | "int64" | "uint64" | "float";
}

export interface IMinimum {
kind: "minimum";
value: number;
}

export interface IMaximum {
kind: "maximum";
value: number;
}

export interface IExclusiveMinimum {
kind: "exclusiveMinimum";
value: number;
}

export interface IExclusiveMaximum {
kind: "exclusiveMaximum";
value: number;
}

export interface IMultipleOf {
kind: "multipleOf";
value: number;
}

export interface IStep {
kind: "step";
value: number;
}

/* -----------------------------------------------------------
STRING
----------------------------------------------------------- */
export interface IFormat {
kind: "format";
value: "uuid" | "email" | "url" | "ipv4" | "ipv6" | "date" | "date-time";
}

export interface IPattern {
kind: "pattern";
value: string;
}

export interface ILength {
kind: "length";
value: number;
}

export interface IMinLength {
kind: "minLength";
value: number;
}

export interface IMaxLength {
kind: "maxLength";
value: number;
}

/* -----------------------------------------------------------
ARRAY
----------------------------------------------------------- */
export interface IItems {
kind: "items";
value: number;
}

export interface IMinItems {
kind: "minItems";
value: number;
}

export interface IMaxItems {
kind: "maxItems";
value: number;
}
}

const FORMATS: Map<string, [IMetadataCommentTag.IFormat["value"], string]> =
new Map([
[
"email",
[
"email",
`/^(([^<>()[\\]\\.,;:\\s@\\"]+(\\.[^<>()[\\]\\.,;:\\s@\\"]+)*)|(\\".+\\"))@(([^<>()[\\]\\.,;:\\s@\\"]+\\.)+[^<>()[\\]\\.,;:\\s@\\"]{2,})$/i.test($input)`,
],
],
[
"uuid",
[
"uuid",
`/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i.test($input)`,
],
],
[
"ipv4",
[
"ipv4",
`/^(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test($input)`,
],
],
[
"ipv6",
[
"ipv6",
`/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/.test($input)`,
],
],
[
"url",
[
"url",
`/^[a-zA-Z0-9]+:\\/\\/(?:www.)?[-a-zA-Z0-9@:%._+~#=]{1,256}.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)$/.test($input)`,
],
],
["date", ["date", `/^(\\d{4})-(\\d{2})-(\\d{2})$/.test($input)`]],
["datetime", ["date-time", `!isNaN(new Date($input).getTime())`]],
["date-time", ["date-time", `!isNaN(new Date($input).getTime())`]],
["dateTime", ["date-time", `!isNaN(new Date($input).getTime())`]],
]);
const FORMATS: Map<string, [string, string]> = new Map([
...Object.entries(FormatCheatSheet).map(
([key, value]) => [key, [key, value]] as any,
),
["datetime", ["date-time", `!isNaN(new Date($input).getTime())`]],
["dateTime", ["date-time", `!isNaN(new Date($input).getTime())`]],
]);
4 changes: 4 additions & 0 deletions src/schemas/json/IJsonSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export namespace IJsonSchema {
| "uuid"
| "email"
| "hostname"
| "idn-email"
| "idn-hostname"
| "iri"
| "iri-reference"
| "ipv4"
| "ipv6"
| "uri"
Expand Down
33 changes: 3 additions & 30 deletions src/tags/Format.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TagBase } from "./TagBase";
import type { TagBase } from "./TagBase";
import type { FormatCheatSheet } from "./internal/FormatCheatSheet";

export type Format<Value extends keyof Format.Validator> = TagBase<{
target: "string";
Expand All @@ -8,33 +9,5 @@ export type Format<Value extends keyof Format.Validator> = TagBase<{
exclusive: ["format", "pattern"];
}>;
export namespace Format {
// reference: https://github.dev/ajv-validator/ajv-formats/blob/master/src/formats.ts
export type Validator = {
// SPECIAL CHARACTERS
byte: RegexCall<`/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm`>;
password: `true`;
regex: `(() => { try { new RegExp($input); return true; } catch { return false; } })()`;
uuid: RegexCall<`/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i`>;

// ADDRESSES
email: RegexCall<`/^[a-z0-9!#$%&'*+/=?^_\`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_\`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i`>;
hostname: RegexCall<`/^(?=.{1,253}\\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\\.?$/i`>;
ipv4: RegexCall<`/^(?:(?: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)$/`>;
ipv6: RegexCall<`/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)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|\\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?)*\\})*$/i`>;
url: RegexCall<`/^(?:https?|ftp):\\/\\/(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z0-9\\u{00a1}-\\u{ffff}]+-)*[a-z0-9\\u{00a1}-\\u{ffff}]+)(?:\\.(?:[a-z0-9\\u{00a1}-\\u{ffff}]+-)*[a-z0-9\\u{00a1}-\\u{ffff}]+)*(?:\\.(?:[a-z\\u{00a1}-\\u{ffff}]{2,})))(?::\\d{2,5})?(?:\\/[^\\s]*)?$/iu`>;

// TIMESTAMPS
"date-time": `!isNaN(new Date($input).getTime())`;
date: RegexCall<`/^(\\d{4})-(\\d{2})-(\\d{2})$/`>;
time: RegexCall<`/^(\\d\\d):(\\d\\d):(\\d\\d(?:\\.\\d+)?)(z|([+-])(\\d\\d)(?::?(\\d\\d))?)?$/i`>;
duration: RegexCall<`/^P(?!$)((\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+S)?)?|(\\d+W)?)$/`>;

// POINTERS
"json-pointer": RegexCall<`/^(?:\\/(?:[^~/]|~0|~1)*)*$/`>;
"relative-json-pointer": RegexCall<`/^(?:0|[1-9][0-9]*)(?:#|(?:\\/(?:[^~/]|~0|~1)*)*)$/`>;
};
type RegexCall<Exp extends string> = `${Exp}.test($input)`;
export type Validator = typeof FormatCheatSheet;
}
71 changes: 71 additions & 0 deletions src/tags/internal/FormatCheatSheet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const RegexCall = <Text extends string>(text: Text) =>
`${text}.test($input)` as const;

/**
* @reference https://github.dev/ajv-validator/ajv-formats/blob/master/src/formats.ts
*/
export const FormatCheatSheet = {
// SPECIAL CHARACTERS
byte: RegexCall(
`/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm`,
),
password: `true`,
regex: `(() => { try { new RegExp($input); return true; } catch { return false; } })()`,
uuid: RegexCall(
`/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i`,
),

// ADDRESSES
email: RegexCall(
`/^[a-z0-9!#$%&'*+/=?^_\`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_\`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i`,
),
hostname: RegexCall(
`/^(?=.{1,253}\\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\\.?$/i`,
),
"idn-email": RegexCall(
`/^(([^<>()[\\]\\.,;:\\s@\\"]+(\\.[^<>()[\\]\\.,;:\\s@\\"]+)*)|(\\".+\\"))@(([^<>()[\\]\\.,;:\\s@\\"]+\\.)+[^<>()[\\]\\.,;:\\s@\\"]{2,})$/i`,
),
"idn-hostname": RegexCall(
`/^([a-z0-9\\u00a1-\\uffff0-9]+(-[a-z0-9\\u00a1-\\uffff0-9]+)*\\.)+[a-z\\u00a1-\\uffff]{2,}$/i`,
),
iri: RegexCall(
`/^[A-Za-z][\\d+-.A-Za-z]*:[^\\u0000-\\u0020"<>\\\\^\`{|}]*$/u`,
),
"iri-reference": RegexCall(
`/^[A-Za-z][\\d+-.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|%[0-9a-f]{2})*)*|\\/(?:(?:[a-z0-9\\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\\/(?:[a-z0-9\\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\\/(?:[a-z0-9\\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\\?(?:[a-z0-9\\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i`,
),
"uri-template": RegexCall(
`/^(?:(?:[^\\x00-\\x20"'<>%\\\\^\`{|}]|%[0-9a-f]{2})|\\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?)*\\})*$/i`,
),
url: RegexCall(
`/^(?:https?|ftp):\\/\\/(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z0-9\\u{00a1}-\\u{ffff}]+-)*[a-z0-9\\u{00a1}-\\u{ffff}]+)(?:\\.(?:[a-z0-9\\u{00a1}-\\u{ffff}]+-)*[a-z0-9\\u{00a1}-\\u{ffff}]+)*(?:\\.(?:[a-z\\u{00a1}-\\u{ffff}]{2,})))(?::\\d{2,5})?(?:\\/[^\\s]*)?$/iu`,
),

// TIMESTAMPS
"date-time": `!isNaN(new Date($input).getTime())`,
date: RegexCall(`/^(\\d{4})-(\\d{2})-(\\d{2})$/`),
time: RegexCall(
`/^(\\d\\d):(\\d\\d):(\\d\\d(?:\\.\\d+)?)(z|([+-])(\\d\\d)(?::?(\\d\\d))?)?$/i`,
),
duration: RegexCall(
`/^P(?!$)((\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+S)?)?|(\\d+W)?)$/`,
),

// POINTERS
"json-pointer": RegexCall(`/^(?:\\/(?:[^~/]|~0|~1)*)*$/`),
"relative-json-pointer": RegexCall(
`/^(?:0|[1-9][0-9]*)(?:#|(?:\\/(?:[^~/]|~0|~1)*)*)$/`,
),
} as const;
4 changes: 4 additions & 0 deletions src/utils/RandomGenerator/RandomGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export const uuid = () =>
// ADDRESSES
export const email = () => `${string(10)}@${string(10)}.${string(3)}`;
export const hostname = () => `${string(10)}.${string(3)}`;
export const idnEmail = () => email();
export const idnHostname = () => hostname();
export const iri = () => url();
export const iriReference = () => url();
export const ipv4 = () => array(() => integer(0, 255), 4).join(".");
export const ipv6 = (): string =>
array(() => integer(0, 65535).toString(16), 8).join(":");
Expand Down
2 changes: 1 addition & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
"suppress-warnings": "^1.0.2",
"tstl": "^2.5.13",
"uuid": "^9.0.1",
"typia": "D:\\github\\samchon\\typia\\typia-5.4.0.tgz"
"typia": "D:\\github\\samchon\\typia\\typia-5.4.1.tgz"
}
}
Loading
Loading