From e987f57b254fbb6a9d39bf92622c0153413fd327 Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Sun, 4 Aug 2024 01:41:26 +0900 Subject: [PATCH] Documentation of v6.7 update. --- website/package-lock.json | 26 +- website/package.json | 4 +- website/pages/docs/__templates/tab-aot.txt | 4 +- website/pages/docs/_meta.json | 2 +- website/pages/docs/json/parse.mdx | 287 ++-- website/pages/docs/json/schema.mdx | 97 +- website/pages/docs/json/stringify.mdx | 577 ++++---- website/pages/docs/misc.mdx | 1393 ++++++++++-------- website/pages/docs/protobuf/decode.mdx | 72 +- website/pages/docs/protobuf/encode.mdx | 72 +- website/pages/docs/protobuf/message.mdx | 88 +- website/pages/docs/pure.mdx | 427 +++--- website/pages/docs/random.mdx | 18 +- website/pages/docs/setup.mdx | 25 +- website/pages/docs/validators/assert.mdx | 858 ++++++----- website/pages/docs/validators/functional.mdx | 392 +++-- website/pages/docs/validators/is.mdx | 123 +- website/pages/docs/validators/tags.mdx | 52 +- website/pages/docs/validators/validate.mdx | 818 +++++----- website/src/compilers/COMPILER_OPTIONS.ts | 4 +- 20 files changed, 2821 insertions(+), 2518 deletions(-) diff --git a/website/package-lock.json b/website/package-lock.json index 26d7a95809..de494ced3a 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -11,12 +11,12 @@ "dependencies": { "@emotion/react": "^11.10.6", "@emotion/styled": "^11.10.6", - "@monaco-editor/react": "^4.5.1", + "@monaco-editor/react": "^4.6.0", "@mui/icons-material": "^5.15.4", "@mui/material": "^5.12.0", "@rollup/browser": "^4.13.0", "lz-string": "^1.5.0", - "monaco-editor": "^0.48.0", + "monaco-editor": "^0.50.0", "next": "^14.2.3", "nextra": "^2.13.4", "nextra-theme-docs": "^2.13.4", @@ -24,10 +24,10 @@ "prettier": "^3.2.5", "react": "^18.2.0", "react-dom": "^18.2.0", - "tgrid": "^1.0.2", + "tgrid": "^1.0.3", "tstl": "^3.0.0", "typescript": "^5.5.4", - "typia": "^6.6.1" + "typia": "^6.7.0" }, "devDependencies": { "@trivago/prettier-plugin-sort-imports": "^4.3.0", @@ -6550,9 +6550,9 @@ } }, "node_modules/monaco-editor": { - "version": "0.48.0", - "resolved": "https://registry.npmjs.org/monaco-editor/-/monaco-editor-0.48.0.tgz", - "integrity": "sha512-goSDElNqFfw7iDHMg8WDATkfcyeLTNpBHQpO8incK6p5qZt5G/1j41X0xdGzpIkGojGXM+QiRQyLjnfDVvrpwA==" + "version": "0.50.0", + "resolved": "https://registry.npmjs.org/monaco-editor/-/monaco-editor-0.50.0.tgz", + "integrity": "sha512-8CclLCmrRRh+sul7C08BmPBP3P8wVWfBHomsTcndxg5NRCEPfu/mc2AGU8k37ajjDVXcXFc12ORAMUkmk+lkFA==" }, "node_modules/mri": { "version": "1.2.0", @@ -8413,9 +8413,9 @@ } }, "node_modules/tgrid": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/tgrid/-/tgrid-1.0.2.tgz", - "integrity": "sha512-L5JK48K2NNyDAZtn8rtJX9f4gCauKwaFmtjAo/8s91McmytpeHuFcUSNP3v7SK+wEydaCZPxxp5Nz9dE59c32A==", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tgrid/-/tgrid-1.0.3.tgz", + "integrity": "sha512-WtknZ6JdXi/vuE1KZpTS3DkF1sU+aQWOOViv7fZvimAhF+pKG63lKVe+nr1GG7ENU0S86/87o3YDqdvvxjeVlQ==", "dependencies": { "@types/node": "^20.11.30", "@types/websocket": "^1.0.10", @@ -8872,9 +8872,9 @@ } }, "node_modules/typia": { - "version": "6.6.1", - "resolved": "https://registry.npmjs.org/typia/-/typia-6.6.1.tgz", - "integrity": "sha512-fK8dBwBtgV0jFqJiaVNzzWqLPwh3TNAP2mshQO00SjAVGpYxMUJA5PqqR9VYVNfXGhlWCpmaCuyviX8wJ0Sq9Q==", + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/typia/-/typia-6.7.0.tgz", + "integrity": "sha512-lXipD7asf2TSYPAT8ZkTzcV5E7ophz2Q+TxD+8nQLb/v+Mzj4UxOAr7Twf7ODc4HXe80dfLPuf3amkqbLIvuSA==", "dependencies": { "@samchon/openapi": "^0.4.3", "commander": "^10.0.0", diff --git a/website/package.json b/website/package.json index e9418c1f0e..c877bfb502 100644 --- a/website/package.json +++ b/website/package.json @@ -22,12 +22,12 @@ "dependencies": { "@emotion/react": "^11.10.6", "@emotion/styled": "^11.10.6", - "@monaco-editor/react": "^4.5.1", + "@monaco-editor/react": "^4.6.0", "@mui/icons-material": "^5.15.4", "@mui/material": "^5.12.0", "@rollup/browser": "^4.13.0", "lz-string": "^1.5.0", - "monaco-editor": "^0.48.0", + "monaco-editor": "^0.50.0", "next": "^14.2.3", "nextra": "^2.13.4", "nextra-theme-docs": "^2.13.4", diff --git a/website/pages/docs/__templates/tab-aot.txt b/website/pages/docs/__templates/tab-aot.txt index 294c913d10..659e6642ef 100644 --- a/website/pages/docs/__templates/tab-aot.txt +++ b/website/pages/docs/__templates/tab-aot.txt @@ -1,10 +1,10 @@ -```typescript copy filename="examples/src/.ts" showLineNumbers {} +```typescript copy filename="examples/src/.ts" showLineNumbers ``` -```javascript filename="examples/bin/.js" showLineNumbers {} +```javascript filename="examples/bin/.js" showLineNumbers ``` \ No newline at end of file diff --git a/website/pages/docs/_meta.json b/website/pages/docs/_meta.json index 13fd655b33..de1d7564db 100644 --- a/website/pages/docs/_meta.json +++ b/website/pages/docs/_meta.json @@ -25,7 +25,7 @@ }, "benchmark": { "title": "⇲ Benchmark Result", - "href": "https://github.com/samchon/typia/tree/master/benchmark/results/11th%20Gen%20Intel(R)%20Core(TM)%20i5-1135G7%20%40%202.40GHz", + "href": "https://github.com/samchon/typia/tree/master/benchmark/results/AMD%20Ryzen%209%207940HS%20w%20Radeon%20780M%20Graphics", "newWindow": true }, "articles": { diff --git a/website/pages/docs/json/parse.mdx b/website/pages/docs/json/parse.mdx index 268d21eefe..0710461bd7 100644 --- a/website/pages/docs/json/parse.mdx +++ b/website/pages/docs/json/parse.mdx @@ -221,17 +221,10 @@ interface IMember { ```javascript filename="examples/bin/assertParse.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); +import typia from "typia"; const json = JSON.stringify( ((generator) => { - const $generator = typia_1.default.random.generator; + const $generator = typia.random.generator; const $ro0 = (_recursive = false, _depth = 0) => ({ id: (generator?.customs ?? $generator.customs)?.string?.([ @@ -271,107 +264,143 @@ const json = JSON.stringify( return $ro0(); })(), ); -const parsed = ((input) => { - const assert = (input) => { - const __is = (input) => { - return ( - "object" === typeof input && - null !== input && - "string" === typeof input.id && - /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input.id, - ) && - "string" === typeof input.email && - /^[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.test( - input.email, - ) && - "number" === typeof input.age && - Math.floor(input.age) === input.age && +const parsed = (() => { + const $guard = typia.json.assertParse.guard; + const $io0 = (input) => + "string" === typeof input.id && + /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input.id, + ) && + "string" === typeof input.email && + /^[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.test( + input.email, + ) && + "number" === typeof input.age && + Math.floor(input.age) === input.age && + 0 <= input.age && + input.age <= 4294967295 && + 19 < input.age && + input.age <= 100; + const $ao0 = (input, _path, _exceptionable = true) => + (("string" === typeof input.id && + (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input.id, + ) || + $guard( + _exceptionable, + { + path: _path + ".id", + expected: 'string & Format<"uuid">', + value: input.id, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".id", + expected: '(string & Format<"uuid">)', + value: input.id, + }, + _errorFactory, + )) && + (("string" === typeof input.email && + (/^[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.test( + input.email, + ) || + $guard( + _exceptionable, + { + path: _path + ".email", + expected: 'string & Format<"email">', + value: input.email, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".email", + expected: '(string & Format<"email">)', + value: input.email, + }, + _errorFactory, + )) && + (("number" === typeof input.age && + ((Math.floor(input.age) === input.age && 0 <= input.age && - input.age <= 4294967295 && - 19 < input.age && - input.age <= 100 - ); - }; - if (false === __is(input)) - ((input, _path, _exceptionable = true) => { - const $guard = typia_1.default.json.assertParse.guard; - const $ao0 = (input, _path, _exceptionable = true) => - (("string" === typeof input.id && - (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input.id, - ) || - $guard(_exceptionable, { - path: _path + ".id", - expected: 'string & Format<"uuid">', - value: input.id, - }))) || - $guard(_exceptionable, { - path: _path + ".id", - expected: '(string & Format<"uuid">)', - value: input.id, - })) && - (("string" === typeof input.email && - (/^[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.test( - input.email, - ) || - $guard(_exceptionable, { - path: _path + ".email", - expected: 'string & Format<"email">', - value: input.email, - }))) || - $guard(_exceptionable, { - path: _path + ".email", - expected: '(string & Format<"email">)', - value: input.email, - })) && - (("number" === typeof input.age && - ((Math.floor(input.age) === input.age && - 0 <= input.age && - input.age <= 4294967295) || - $guard(_exceptionable, { - path: _path + ".age", - expected: 'number & Type<"uint32">', - value: input.age, - })) && - (19 < input.age || - $guard(_exceptionable, { - path: _path + ".age", - expected: "number & ExclusiveMinimum<19>", - value: input.age, - })) && - (input.age <= 100 || - $guard(_exceptionable, { - path: _path + ".age", - expected: "number & Maximum<100>", - value: input.age, - }))) || - $guard(_exceptionable, { - path: _path + ".age", - expected: - '(number & Type<"uint32"> & ExclusiveMinimum<19> & Maximum<100>)', - value: input.age, - })); - return ( - ((("object" === typeof input && null !== input) || - $guard(true, { + input.age <= 4294967295) || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: 'number & Type<"uint32">', + value: input.age, + }, + _errorFactory, + )) && + (19 < input.age || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: "number & ExclusiveMinimum<19>", + value: input.age, + }, + _errorFactory, + )) && + (input.age <= 100 || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: "number & Maximum<100>", + value: input.age, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: + '(number & Type<"uint32"> & ExclusiveMinimum<19> & Maximum<100>)', + value: input.age, + }, + _errorFactory, + )); + const __is = (input) => + "object" === typeof input && null !== input && $io0(input); + let _errorFactory; + const __assert = (input, errorFactory) => { + if (false === __is(input)) { + _errorFactory = errorFactory; + ((input, _path, _exceptionable = true) => + ((("object" === typeof input && null !== input) || + $guard( + true, + { path: _path + "", expected: "IMember", value: input, - })) && - $ao0(input, _path + "", true)) || - $guard(true, { + }, + _errorFactory, + )) && + $ao0(input, _path + "", true)) || + $guard( + true, + { path: _path + "", expected: "IMember", value: input, - }) - ); - })(input, "$input", true); + }, + _errorFactory, + ))(input, "$input", true); + } return input; }; - input = JSON.parse(input); - return assert(input); -})(json); + return (input, errorFactory) => __assert(JSON.parse(input), errorFactory); +})()(json); console.log(json === JSON.stringify(parsed)); // true ``` @@ -594,40 +623,30 @@ interface IMember { ```javascript filename="examples/bin/createIsParse.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.parseMember = void 0; -const typia_1 = __importDefault(require("typia")); -const parseMember = (input) => { - const is = (input) => { - return ( - "object" === typeof input && - null !== input && - "string" === typeof input.id && - /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input.id, - ) && - "string" === typeof input.email && - /^[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.test( - input.email, - ) && - "number" === typeof input.age && - Math.floor(input.age) === input.age && - 0 <= input.age && - input.age <= 4294967295 && - 19 < input.age && - input.age <= 100 - ); +import typia from "typia"; +export const parseMember = (() => { + const $io0 = (input) => + "string" === typeof input.id && + /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input.id, + ) && + "string" === typeof input.email && + /^[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.test( + input.email, + ) && + "number" === typeof input.age && + Math.floor(input.age) === input.age && + 0 <= input.age && + input.age <= 4294967295 && + 19 < input.age && + input.age <= 100; + const __is = (input) => + "object" === typeof input && null !== input && $io0(input); + return (input) => { + input = JSON.parse(input); + return __is(input) ? input : null; }; - input = JSON.parse(input); - return is(input) ? input : null; -}; -exports.parseMember = parseMember; +})(); ``` diff --git a/website/pages/docs/json/schema.mdx b/website/pages/docs/json/schema.mdx index 6d83af453b..b19ed2a8a0 100644 --- a/website/pages/docs/json/schema.mdx +++ b/website/pages/docs/json/schema.mdx @@ -83,26 +83,12 @@ interface IMember { ```javascript filename="examples/bin/application.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.MemberSchema = void 0; -const typia_1 = __importDefault(require("typia")); -exports.MemberSchema = { +import typia from "typia"; +export const MemberSchema = { version: "3.0", - schemas: [ - { - $ref: "#/components/schemas/IMember", - }, - ], components: { schemas: { IMember: { - $id: "#/components/schemas/IMember", type: "object", properties: { id: { @@ -119,18 +105,24 @@ exports.MemberSchema = { }, age: { type: "integer", - minimum: 19, exclusiveMinimum: true, + minimum: 19, maximum: 100, title: "Age of the member", description: "Age of the member.\n\nFor reference, only adult can be a member.", }, }, + nullable: false, required: ["id", "email", "age"], }, }, }, + schemas: [ + { + $ref: "#/components/schemas/IMember", + }, + ], }; ``` @@ -230,22 +222,9 @@ interface Special { ```javascript filename="examples/bin/application-comment-tags.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.SpecialTagSchema = void 0; -const typia_1 = __importDefault(require("typia")); -exports.SpecialTagSchema = { +import typia from "typia"; +export const SpecialTagSchema = { version: "3.1", - schemas: [ - { - $ref: "#/components/schemas/Special", - }, - ], components: { schemas: { Special: { @@ -259,10 +238,9 @@ exports.SpecialTagSchema = { }, number: { type: "number", - minimum: 19, exclusiveMinimum: true, + minimum: 19, maximum: 100, - default: 30, title: "You can limit the range of number", description: "You can limit the range of number.", }, @@ -270,13 +248,13 @@ exports.SpecialTagSchema = { oneOf: [ { type: "string", - maxLength: 24, minLength: 3, + maxLength: 24, }, { type: "string", - maxLength: 100, minLength: 40, + maxLength: 100, }, ], title: "You can limit the length of string", @@ -292,12 +270,12 @@ exports.SpecialTagSchema = { format: { oneOf: [ { - type: "null" + type: "null", }, { type: "string", format: "date-time", - } + }, ], title: "You can limit the format of string", description: "You can limit the format of string.", @@ -318,6 +296,11 @@ exports.SpecialTagSchema = { }, }, }, + schemas: [ + { + $ref: "#/components/schemas/Special", + }, + ], }; ``` @@ -357,14 +340,10 @@ typia.json.application<[IAccount]>(); ``` -```javascript copy filename="examples/bin/json-schema-custom.js" showLineNumbers {15, 19} +```javascript copy filename="examples/bin/json-schema-custom.js" showLineNumbers {11, 15} +import typia from "typia"; ({ version: "3.1", - schemas: [ - { - $ref: "#/components/schemas/IAccount", - }, - ], components: { schemas: { IAccount: { @@ -383,7 +362,13 @@ typia.json.application<[IAccount]>(); }, }, }, + schemas: [ + { + $ref: "#/components/schemas/IAccount", + }, + ], }); + ``` @@ -410,7 +395,7 @@ interface Nested { uint64: bigint & tags.Type<"uint64">; } -typia.json.application<[Something], "ajv">(); +typia.json.application<[Something]>(); ``` @@ -439,30 +424,17 @@ import typia from "typia"; interface Native { date: Date; } -typia.json.application<[Native], "ajv">(); +typia.json.application<[Native]>(); ``` ```typescript filename="json.application.native.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); +import typia from "typia"; ({ version: "3.1", - schemas: [ - { - $ref: "#/components/schemas/Native", - }, - ], components: { schemas: { Native: { - $id: "#/components/schemas/Native", type: "object", properties: { date: { @@ -474,6 +446,11 @@ const typia_1 = __importDefault(require("typia")); }, }, }, + schemas: [ + { + $ref: "#/components/schemas/Native", + }, + ], }); ``` diff --git a/website/pages/docs/json/stringify.mdx b/website/pages/docs/json/stringify.mdx index 8bf6887d49..2a68f7b152 100644 --- a/website/pages/docs/json/stringify.mdx +++ b/website/pages/docs/json/stringify.mdx @@ -81,34 +81,27 @@ const json: string | null = typia.json.isStringify(department); console.log(json); // not null, but string interface IDepartment { - id: string & tags.Format<"uuid">; - name: string & tags.MinLength<3>; - limit: number & tags.Type<"int32">; - clerks: IClerk[]; + id: string & tags.Format<"uuid">; + name: string & tags.MinLength<3>; + limit: number & tags.Type<"int32">; + clerks: IClerk[]; } interface IClerk { - name: string; - age: number - & tags.Type<"uint32"> - & tags.ExclusiveMinimum<19> - & tags.Maximum<100>; - authority: number; - joined_at: string & tags.Format<"date">; + name: string; + age: number + & tags.Type<"uint32"> + & tags.ExclusiveMinimum<19> + & tags.Maximum<100>; + authority: number; + joined_at: string & tags.Format<"date">; } ``` ```javascript filename="examples/bin/isStringify.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); +import typia from "typia"; const department = ((generator) => { - const $generator = typia_1.default.random.generator; + const $generator = typia.random.generator; const $ro0 = (_recursive = false, _depth = 0) => ({ id: (generator?.customs ?? $generator.customs)?.string?.([ @@ -177,56 +170,45 @@ const department = ((generator) => { }); return $ro0(); })(); -const json = ((input) => { - const is = (input) => { - const $io0 = (input) => - "string" === typeof input.id && - /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input.id, - ) && - "string" === typeof input.name && - 3 <= input.name.length && - "number" === typeof input.limit && - Math.floor(input.limit) === input.limit && - -2147483648 <= input.limit && - input.limit <= 2147483647 && - Array.isArray(input.clerks) && - input.clerks.every( - (elem) => "object" === typeof elem && null !== elem && $io1(elem), - ); - const $io1 = (input) => - "string" === typeof input.name && - "number" === typeof input.age && - Math.floor(input.age) === input.age && - 0 <= input.age && - input.age <= 4294967295 && - 19 < input.age && - input.age <= 100 && - "number" === typeof input.authority && - !Number.isNaN(input.authority) && - "string" === typeof input.joined_at && - /^(\d{4})-(\d{2})-(\d{2})$/.test(input.joined_at); - return "object" === typeof input && null !== input && $io0(input); - }; - const stringify = (input) => { - const $io1 = (input) => - "string" === typeof input.name && - "number" === typeof input.age && - Math.floor(input.age) === input.age && - 0 <= input.age && - input.age <= 4294967295 && - 19 < input.age && - input.age <= 100 && - "number" === typeof input.authority && - "string" === typeof input.joined_at && - /^(\d{4})-(\d{2})-(\d{2})$/.test(input.joined_at); - const $string = typia_1.default.json.isStringify.string; - const $so0 = (input) => - `{"id":${$string(input.id)},"name":${$string(input.name)},"limit":${input.limit},"clerks":${`[${input.clerks.map((elem) => `{"name":${$string(elem.name)},"age":${elem.age},"authority":${elem.authority},"joined_at":${$string(elem.joined_at)}}`).join(",")}]`}}`; - return $so0(input); - }; - return is(input) ? stringify(input) : null; -})(department); +const json = (() => { + const $string = typia.json.isStringify.string; + const $number = typia.json.isStringify.number; + const $io0 = (input) => + "string" === typeof input.id && + /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input.id, + ) && + "string" === typeof input.name && + 3 <= input.name.length && + "number" === typeof input.limit && + Math.floor(input.limit) === input.limit && + -2147483648 <= input.limit && + input.limit <= 2147483647 && + Array.isArray(input.clerks) && + input.clerks.every( + (elem) => "object" === typeof elem && null !== elem && $io1(elem), + ); + const $io1 = (input) => + "string" === typeof input.name && + "number" === typeof input.age && + Math.floor(input.age) === input.age && + 0 <= input.age && + input.age <= 4294967295 && + 19 < input.age && + input.age <= 100 && + "number" === typeof input.authority && + !Number.isNaN(input.authority) && + "string" === typeof input.joined_at && + /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.test(input.joined_at); + const $so0 = (input) => + `{"id":${$string(input.id)},"name":${$string(input.name)},"limit":${$number(input.limit)},"clerks":${`[${input.clerks.map((elem) => $so1(elem)).join(",")}]`}}`; + const $so1 = (input) => + `{"name":${$string(input.name)},"age":${$number(input.age)},"authority":${$number(input.authority)},"joined_at":${$string(input.joined_at)}}`; + const __is = (input) => + "object" === typeof input && null !== input && $io0(input); + const __stringify = (input) => $so0(input); + return (input) => (__is(input) ? __stringify(input) : null); +})()(department); console.log(json); // not null, but string ``` @@ -321,211 +303,274 @@ interface IClerk { ```javascript filename="examples/bin/createAssertStringify.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.assertDepartment = void 0; -const typia_1 = __importDefault(require("typia")); -const assertDepartment = (input) => { - const assert = (input) => { - const __is = (input) => { - const $io0 = (input) => - "string" === typeof input.id && - /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input.id, - ) && - "string" === typeof input.name && - 3 <= input.name.length && - "number" === typeof input.limit && - Math.floor(input.limit) === input.limit && +import typia from "typia"; +export const assertDepartment = (() => { + const $guard = typia.json.createAssertStringify.guard; + const $string = typia.json.createAssertStringify.string; + const $io0 = (input) => + "string" === typeof input.id && + /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input.id, + ) && + "string" === typeof input.name && + 3 <= input.name.length && + "number" === typeof input.limit && + Math.floor(input.limit) === input.limit && + -2147483648 <= input.limit && + input.limit <= 2147483647 && + Array.isArray(input.clerks) && + input.clerks.every( + (elem) => "object" === typeof elem && null !== elem && $io1(elem), + ); + const $io1 = (input) => + "string" === typeof input.name && + "number" === typeof input.age && + Math.floor(input.age) === input.age && + 0 <= input.age && + input.age <= 4294967295 && + 19 < input.age && + input.age <= 100 && + "number" === typeof input.authority && + !Number.isNaN(input.authority) && + "string" === typeof input.joined_at && + /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.test(input.joined_at); + const $ao0 = (input, _path, _exceptionable = true) => + (("string" === typeof input.id && + (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input.id, + ) || + $guard( + _exceptionable, + { + path: _path + ".id", + expected: 'string & Format<"uuid">', + value: input.id, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".id", + expected: '(string & Format<"uuid">)', + value: input.id, + }, + _errorFactory, + )) && + (("string" === typeof input.name && + (3 <= input.name.length || + $guard( + _exceptionable, + { + path: _path + ".name", + expected: "string & MinLength<3>", + value: input.name, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".name", + expected: "(string & MinLength<3>)", + value: input.name, + }, + _errorFactory, + )) && + (("number" === typeof input.limit && + ((Math.floor(input.limit) === input.limit && -2147483648 <= input.limit && - input.limit <= 2147483647 && - Array.isArray(input.clerks) && - input.clerks.every( - (elem) => "object" === typeof elem && null !== elem && $io1(elem), - ); - const $io1 = (input) => - "string" === typeof input.name && - "number" === typeof input.age && - Math.floor(input.age) === input.age && - 0 <= input.age && - input.age <= 4294967295 && - 19 < input.age && - input.age <= 100 && - "number" === typeof input.authority && - !Number.isNaN(input.authority) && - "string" === typeof input.joined_at && - /^(\d{4})-(\d{2})-(\d{2})$/.test(input.joined_at); - return "object" === typeof input && null !== input && $io0(input); - }; - if (false === __is(input)) - ((input, _path, _exceptionable = true) => { - const $guard = typia_1.default.json.createAssertStringify.guard; - const $ao0 = (input, _path, _exceptionable = true) => - (("string" === typeof input.id && - (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input.id, - ) || - $guard(_exceptionable, { - path: _path + ".id", - expected: 'string & Format<"uuid">', - value: input.id, - }))) || - $guard(_exceptionable, { - path: _path + ".id", - expected: '(string & Format<"uuid">)', - value: input.id, - })) && - (("string" === typeof input.name && - (3 <= input.name.length || - $guard(_exceptionable, { - path: _path + ".name", - expected: "string & MinLength<3>", - value: input.name, - }))) || - $guard(_exceptionable, { - path: _path + ".name", - expected: "(string & MinLength<3>)", - value: input.name, - })) && - (("number" === typeof input.limit && - ((Math.floor(input.limit) === input.limit && - -2147483648 <= input.limit && - input.limit <= 2147483647) || - $guard(_exceptionable, { - path: _path + ".limit", - expected: 'number & Type<"int32">', - value: input.limit, - }))) || - $guard(_exceptionable, { - path: _path + ".limit", - expected: '(number & Type<"int32">)', - value: input.limit, - })) && - (((Array.isArray(input.clerks) || - $guard(_exceptionable, { - path: _path + ".clerks", - expected: "Array", - value: input.clerks, - })) && - input.clerks.every( - (elem, _index1) => - ((("object" === typeof elem && null !== elem) || - $guard(_exceptionable, { - path: _path + ".clerks[" + _index1 + "]", - expected: "IClerk", - value: elem, - })) && - $ao1( - elem, - _path + ".clerks[" + _index1 + "]", - true && _exceptionable, - )) || - $guard(_exceptionable, { - path: _path + ".clerks[" + _index1 + "]", - expected: "IClerk", - value: elem, - }), + input.limit <= 2147483647) || + $guard( + _exceptionable, + { + path: _path + ".limit", + expected: 'number & Type<"int32">', + value: input.limit, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".limit", + expected: '(number & Type<"int32">)', + value: input.limit, + }, + _errorFactory, + )) && + (((Array.isArray(input.clerks) || + $guard( + _exceptionable, + { + path: _path + ".clerks", + expected: "Array", + value: input.clerks, + }, + _errorFactory, + )) && + input.clerks.every( + (elem, _index2) => + ((("object" === typeof elem && null !== elem) || + $guard( + _exceptionable, + { + path: _path + ".clerks[" + _index2 + "]", + expected: "IClerk", + value: elem, + }, + _errorFactory, + )) && + $ao1( + elem, + _path + ".clerks[" + _index2 + "]", + true && _exceptionable, )) || - $guard(_exceptionable, { - path: _path + ".clerks", - expected: "Array", - value: input.clerks, - })); - const $ao1 = (input, _path, _exceptionable = true) => - ("string" === typeof input.name || - $guard(_exceptionable, { - path: _path + ".name", - expected: "string", - value: input.name, - })) && - (("number" === typeof input.age && - ((Math.floor(input.age) === input.age && - 0 <= input.age && - input.age <= 4294967295) || - $guard(_exceptionable, { - path: _path + ".age", - expected: 'number & Type<"uint32">', - value: input.age, - })) && - (19 < input.age || - $guard(_exceptionable, { - path: _path + ".age", - expected: "number & ExclusiveMinimum<19>", - value: input.age, - })) && - (input.age <= 100 || - $guard(_exceptionable, { - path: _path + ".age", - expected: "number & Maximum<100>", - value: input.age, - }))) || - $guard(_exceptionable, { - path: _path + ".age", - expected: - '(number & Type<"uint32"> & ExclusiveMinimum<19> & Maximum<100>)', - value: input.age, - })) && - (("number" === typeof input.authority && - !Number.isNaN(input.authority)) || - $guard(_exceptionable, { - path: _path + ".authority", - expected: "number", - value: input.authority, - })) && - (("string" === typeof input.joined_at && - (/^(\d{4})-(\d{2})-(\d{2})$/.test(input.joined_at) || - $guard(_exceptionable, { - path: _path + ".joined_at", - expected: 'string & Format<"date">', - value: input.joined_at, - }))) || - $guard(_exceptionable, { - path: _path + ".joined_at", - expected: '(string & Format<"date">)', - value: input.joined_at, - })); - return ( - ((("object" === typeof input && null !== input) || - $guard(true, { + $guard( + _exceptionable, + { + path: _path + ".clerks[" + _index2 + "]", + expected: "IClerk", + value: elem, + }, + _errorFactory, + ), + )) || + $guard( + _exceptionable, + { + path: _path + ".clerks", + expected: "Array", + value: input.clerks, + }, + _errorFactory, + )); + const $ao1 = (input, _path, _exceptionable = true) => + ("string" === typeof input.name || + $guard( + _exceptionable, + { + path: _path + ".name", + expected: "string", + value: input.name, + }, + _errorFactory, + )) && + (("number" === typeof input.age && + ((Math.floor(input.age) === input.age && + 0 <= input.age && + input.age <= 4294967295) || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: 'number & Type<"uint32">', + value: input.age, + }, + _errorFactory, + )) && + (19 < input.age || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: "number & ExclusiveMinimum<19>", + value: input.age, + }, + _errorFactory, + )) && + (input.age <= 100 || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: "number & Maximum<100>", + value: input.age, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: + '(number & Type<"uint32"> & ExclusiveMinimum<19> & Maximum<100>)', + value: input.age, + }, + _errorFactory, + )) && + (("number" === typeof input.authority && !Number.isNaN(input.authority)) || + $guard( + _exceptionable, + { + path: _path + ".authority", + expected: "number", + value: input.authority, + }, + _errorFactory, + )) && + (("string" === typeof input.joined_at && + (/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.test( + input.joined_at, + ) || + $guard( + _exceptionable, + { + path: _path + ".joined_at", + expected: 'string & Format<"date">', + value: input.joined_at, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".joined_at", + expected: '(string & Format<"date">)', + value: input.joined_at, + }, + _errorFactory, + )); + const $so0 = (input) => + `{"id":${$string(input.id)},"name":${$string(input.name)},"limit":${input.limit},"clerks":${`[${input.clerks.map((elem) => $so1(elem)).join(",")}]`}}`; + const $so1 = (input) => + `{"name":${$string(input.name)},"age":${input.age},"authority":${input.authority},"joined_at":${$string(input.joined_at)}}`; + const __is = (input) => + "object" === typeof input && null !== input && $io0(input); + let _errorFactory; + const __assert = (input, errorFactory) => { + if (false === __is(input)) { + _errorFactory = errorFactory; + ((input, _path, _exceptionable = true) => + ((("object" === typeof input && null !== input) || + $guard( + true, + { path: _path + "", expected: "IDepartment", value: input, - })) && - $ao0(input, _path + "", true)) || - $guard(true, { + }, + _errorFactory, + )) && + $ao0(input, _path + "", true)) || + $guard( + true, + { path: _path + "", expected: "IDepartment", value: input, - }) - ); - })(input, "$input", true); + }, + _errorFactory, + ))(input, "$input", true); + } return input; }; - const stringify = (input) => { - const $io1 = (input) => - "string" === typeof input.name && - "number" === typeof input.age && - Math.floor(input.age) === input.age && - 0 <= input.age && - input.age <= 4294967295 && - 19 < input.age && - input.age <= 100 && - "number" === typeof input.authority && - "string" === typeof input.joined_at && - /^(\d{4})-(\d{2})-(\d{2})$/.test(input.joined_at); - const $string = typia_1.default.json.createAssertStringify.string; - const $so0 = (input) => - `{"id":${$string(input.id)},"name":${$string(input.name)},"limit":${input.limit},"clerks":${`[${input.clerks.map((elem) => `{"name":${$string(elem.name)},"age":${elem.age},"authority":${elem.authority},"joined_at":${$string(elem.joined_at)}}`).join(",")}]`}}`; - return $so0(input); + const __stringify = (input) => $so0(input); + return (input, errorFactory) => { + __assert(input, errorFactory); + return __stringify(input); }; - return stringify(assert(input)); -}; -exports.assertDepartment = assertDepartment; +})(); ``` @@ -541,7 +586,7 @@ For reference, `class-transformer` is the most famous library used in `NestJS` w - `fast-json-stringify` requires [JSON schema definition](https://github.com/samchon/typia/blob/master/test/schemas/json/swagger/ObjectHierarchical.json). - `class-validator` requires [DTO class with decorator function calls](https://github.com/samchon/typia/blob/master/benchmark/structures/class-validator/ClassValidatorObjectHierarchical.ts). -![Stringify Function Benchmark](https://github.com/samchon/typia/raw/master/benchmark/results/11th%20Gen%20Intel(R)%20Core(TM)%20i5-1135G7%20%40%202.40GHz/images/stringify.svg) +![Stringify Function Benchmark](https://github.com/samchon/typia/raw/master/benchmark/results/AMD%20Ryzen%209%207940HS%20w%20Radeon%20780M%20Graphics/images/stringify.svg) > Measured on [AMD Ryzen 9 7940HS, Rog Flow x13](https://github.com/samchon/typia/tree/master/benchmark/results/AMD%20Ryzen%209%207940HS%20w%20Radeon%20780M%20Graphics#stringify) @@ -561,6 +606,6 @@ Most operations in NodeJS server are asynchronously executed in background threa I'll show you the benchmark result that, how JSON serizliation speed affects on the server performance. -![Server Benchmark](https://raw.githubusercontent.com/samchon/typia/master/benchmark/results/11th%20Gen%20Intel(R)%20Core(TM)%20i5-1135G7%20%40%202.40GHz/images/server.svg) +![Server Benchmark](https://raw.githubusercontent.com/samchon/typia/master/benchmark/results/AMD%20Ryzen%209%207940HS%20w%20Radeon%20780M%20Graphics/images/server.svg) > Measured on [AMD Ryzen 9 7940HS, Rog Flow x13](https://github.com/samchon/typia/tree/master/benchmark/results/AMD%20Ryzen%209%207940HS%20w%20Radeon%20780M%20Graphics#server) \ No newline at end of file diff --git a/website/pages/docs/misc.mdx b/website/pages/docs/misc.mdx index f96f123fb1..f78dd0860d 100644 --- a/website/pages/docs/misc.mdx +++ b/website/pages/docs/misc.mdx @@ -196,7 +196,7 @@ When you want to copy an instance, just call `typia.misc.clone()` function. It w ```typescript copy filename="examples/src/assertClone.ts" showLineNumbers {4} import typia from "typia"; -const department: IDepartment = typia.misc.random(); +const department: IDepartment = typia.random(); const cloned: IDepartment = typia.misc.assertClone(department); console.log(cloned); @@ -238,209 +238,332 @@ interface IClerk { ``` -```javascript filename="examples/bin/assertClone.js" showLineNumbers {146-164} -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); -const department = typia_1.default.misc.random(); -const cloned = ((input) => { - const assert = (input) => { - const __is = (input) => { - const $io0 = (input) => - "string" === typeof input.id && - /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input.id, - ) && - "string" === typeof input.name && - 3 <= input.name.length && - "number" === typeof input.limit && - Math.floor(input.limit) === input.limit && +```javascript filename="examples/bin/assertClone.js" showLineNumbers {67-325} +import typia from "typia"; +const department = ((generator) => { + const $generator = typia.random.generator; + const $ro0 = (_recursive = false, _depth = 0) => ({ + id: + (generator?.customs ?? $generator.customs)?.string?.([ + { + name: 'Format<"uuid">', + kind: "format", + value: "uuid", + }, + ]) ?? (generator?.uuid ?? $generator.uuid)(), + name: + (generator?.customs ?? $generator.customs)?.string?.([ + { + name: "MinLength<3>", + kind: "minLength", + value: 3, + }, + ]) ?? + (generator?.string ?? $generator.string)( + (generator?.integer ?? $generator.integer)(3, 25), + ), + limit: + (generator?.customs ?? $generator.customs)?.number?.([ + { + name: 'Type<"int32">', + kind: "type", + value: "int32", + }, + ]) ?? (generator?.integer ?? $generator.integer)(0, 100), + clerks: (generator?.array ?? $generator.array)(() => + $ro1(_recursive, _recursive ? 1 + _depth : _depth), + ), + }); + const $ro1 = (_recursive = false, _depth = 0) => ({ + name: + (generator?.customs ?? $generator.customs)?.string?.([]) ?? + (generator?.string ?? $generator.string)(), + age: + (generator?.customs ?? $generator.customs)?.number?.([ + { + name: "ExclusiveMinimum<19>", + kind: "exclusiveMinimum", + value: 19, + }, + { + name: "Maximum<100>", + kind: "maximum", + value: 100, + }, + ]) ?? (generator?.number ?? $generator.number)(19, 100), + authority: + (generator?.customs ?? $generator.customs)?.number?.([]) ?? + (generator?.number ?? $generator.number)(0, 100), + joined_at: + (generator?.customs ?? $generator.customs)?.string?.([ + { + name: 'Format<"date">', + kind: "format", + value: "date", + }, + ]) ?? (generator?.date ?? $generator.date)(), + }); + return $ro0(); +})(); +const cloned = (() => { + const $guard = typia.misc.assertClone.guard; + const $cp0 = (input) => + input.map((elem) => + "object" === typeof elem && null !== elem ? $co1(elem) : elem, + ); + const $io0 = (input) => + "string" === typeof input.id && + /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input.id, + ) && + "string" === typeof input.name && + 3 <= input.name.length && + "number" === typeof input.limit && + Math.floor(input.limit) === input.limit && + -2147483648 <= input.limit && + input.limit <= 2147483647 && + Array.isArray(input.clerks) && + input.clerks.every( + (elem) => "object" === typeof elem && null !== elem && $io1(elem), + ); + const $io1 = (input) => + "string" === typeof input.name && + "number" === typeof input.age && + 19 < input.age && + input.age <= 100 && + "number" === typeof input.authority && + "string" === typeof input.joined_at && + /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.test(input.joined_at); + const $ao0 = (input, _path, _exceptionable = true) => + (("string" === typeof input.id && + (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input.id, + ) || + $guard( + _exceptionable, + { + path: _path + ".id", + expected: 'string & Format<"uuid">', + value: input.id, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".id", + expected: '(string & Format<"uuid">)', + value: input.id, + }, + _errorFactory, + )) && + (("string" === typeof input.name && + (3 <= input.name.length || + $guard( + _exceptionable, + { + path: _path + ".name", + expected: "string & MinLength<3>", + value: input.name, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".name", + expected: "(string & MinLength<3>)", + value: input.name, + }, + _errorFactory, + )) && + (("number" === typeof input.limit && + ((Math.floor(input.limit) === input.limit && -2147483648 <= input.limit && - input.limit <= 2147483647 && - Array.isArray(input.clerks) && - input.clerks.every( - (elem) => "object" === typeof elem && null !== elem && $io1(elem), - ); - const $io1 = (input) => - "string" === typeof input.name && - "number" === typeof input.age && - 19 < input.age && - input.age <= 100 && - "number" === typeof input.authority && - "string" === typeof input.joined_at && - /^(\d{4})-(\d{2})-(\d{2})$/.test(input.joined_at); - return "object" === typeof input && null !== input && $io0(input); - }; - if (false === __is(input)) - ((input, _path, _exceptionable = true) => { - const $guard = typia_1.default.misc.assertClone.guard; - const $ao0 = (input, _path, _exceptionable = true) => - (("string" === typeof input.id && - (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input.id, - ) || - $guard(_exceptionable, { - path: _path + ".id", - expected: 'string & Format<"uuid">', - value: input.id, - }))) || - $guard(_exceptionable, { - path: _path + ".id", - expected: '(string & Format<"uuid">)', - value: input.id, - })) && - (("string" === typeof input.name && - (3 <= input.name.length || - $guard(_exceptionable, { - path: _path + ".name", - expected: "string & MinLength<3>", - value: input.name, - }))) || - $guard(_exceptionable, { - path: _path + ".name", - expected: "(string & MinLength<3>)", - value: input.name, - })) && - (("number" === typeof input.limit && - ((Math.floor(input.limit) === input.limit && - -2147483648 <= input.limit && - input.limit <= 2147483647) || - $guard(_exceptionable, { - path: _path + ".limit", - expected: 'number & Type<"int32">', - value: input.limit, - }))) || - $guard(_exceptionable, { - path: _path + ".limit", - expected: '(number & Type<"int32">)', - value: input.limit, - })) && - (((Array.isArray(input.clerks) || - $guard(_exceptionable, { - path: _path + ".clerks", - expected: "Array", - value: input.clerks, - })) && - input.clerks.every( - (elem, _index1) => - ((("object" === typeof elem && null !== elem) || - $guard(_exceptionable, { - path: _path + ".clerks[" + _index1 + "]", - expected: "IClerk", - value: elem, - })) && - $ao1( - elem, - _path + ".clerks[" + _index1 + "]", - true && _exceptionable, - )) || - $guard(_exceptionable, { - path: _path + ".clerks[" + _index1 + "]", - expected: "IClerk", - value: elem, - }), + input.limit <= 2147483647) || + $guard( + _exceptionable, + { + path: _path + ".limit", + expected: 'number & Type<"int32">', + value: input.limit, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".limit", + expected: '(number & Type<"int32">)', + value: input.limit, + }, + _errorFactory, + )) && + (((Array.isArray(input.clerks) || + $guard( + _exceptionable, + { + path: _path + ".clerks", + expected: "Array", + value: input.clerks, + }, + _errorFactory, + )) && + input.clerks.every( + (elem, _index2) => + ((("object" === typeof elem && null !== elem) || + $guard( + _exceptionable, + { + path: _path + ".clerks[" + _index2 + "]", + expected: "IClerk", + value: elem, + }, + _errorFactory, + )) && + $ao1( + elem, + _path + ".clerks[" + _index2 + "]", + true && _exceptionable, )) || - $guard(_exceptionable, { - path: _path + ".clerks", - expected: "Array", - value: input.clerks, - })); - const $ao1 = (input, _path, _exceptionable = true) => - ("string" === typeof input.name || - $guard(_exceptionable, { - path: _path + ".name", - expected: "string", - value: input.name, - })) && - (("number" === typeof input.age && - (19 < input.age || - $guard(_exceptionable, { - path: _path + ".age", - expected: "number & ExclusiveMinimum<19>", - value: input.age, - })) && - (input.age <= 100 || - $guard(_exceptionable, { - path: _path + ".age", - expected: "number & Maximum<100>", - value: input.age, - }))) || - $guard(_exceptionable, { - path: _path + ".age", - expected: "(number & ExclusiveMinimum<19> & Maximum<100>)", - value: input.age, - })) && - ("number" === typeof input.authority || - $guard(_exceptionable, { - path: _path + ".authority", - expected: "number", - value: input.authority, - })) && - (("string" === typeof input.joined_at && - (/^(\d{4})-(\d{2})-(\d{2})$/.test(input.joined_at) || - $guard(_exceptionable, { - path: _path + ".joined_at", - expected: 'string & Format<"date">', - value: input.joined_at, - }))) || - $guard(_exceptionable, { - path: _path + ".joined_at", - expected: '(string & Format<"date">)', - value: input.joined_at, - })); - return ( - ((("object" === typeof input && null !== input) || - $guard(true, { + $guard( + _exceptionable, + { + path: _path + ".clerks[" + _index2 + "]", + expected: "IClerk", + value: elem, + }, + _errorFactory, + ), + )) || + $guard( + _exceptionable, + { + path: _path + ".clerks", + expected: "Array", + value: input.clerks, + }, + _errorFactory, + )); + const $ao1 = (input, _path, _exceptionable = true) => + ("string" === typeof input.name || + $guard( + _exceptionable, + { + path: _path + ".name", + expected: "string", + value: input.name, + }, + _errorFactory, + )) && + (("number" === typeof input.age && + (19 < input.age || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: "number & ExclusiveMinimum<19>", + value: input.age, + }, + _errorFactory, + )) && + (input.age <= 100 || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: "number & Maximum<100>", + value: input.age, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: "(number & ExclusiveMinimum<19> & Maximum<100>)", + value: input.age, + }, + _errorFactory, + )) && + ("number" === typeof input.authority || + $guard( + _exceptionable, + { + path: _path + ".authority", + expected: "number", + value: input.authority, + }, + _errorFactory, + )) && + (("string" === typeof input.joined_at && + (/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.test( + input.joined_at, + ) || + $guard( + _exceptionable, + { + path: _path + ".joined_at", + expected: 'string & Format<"date">', + value: input.joined_at, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".joined_at", + expected: '(string & Format<"date">)', + value: input.joined_at, + }, + _errorFactory, + )); + const $co0 = (input) => ({ + id: input.id, + name: input.name, + limit: input.limit, + clerks: Array.isArray(input.clerks) ? $cp0(input.clerks) : input.clerks, + }); + const $co1 = (input) => ({ + name: input.name, + age: input.age, + authority: input.authority, + joined_at: input.joined_at, + }); + const __is = (input) => + "object" === typeof input && null !== input && $io0(input); + let _errorFactory; + const __assert = (input, errorFactory) => { + if (false === __is(input)) { + _errorFactory = errorFactory; + ((input, _path, _exceptionable = true) => + ((("object" === typeof input && null !== input) || + $guard( + true, + { path: _path + "", expected: "IDepartment", value: input, - })) && - $ao0(input, _path + "", true)) || - $guard(true, { + }, + _errorFactory, + )) && + $ao0(input, _path + "", true)) || + $guard( + true, + { path: _path + "", expected: "IDepartment", value: input, - }) - ); - })(input, "$input", true); + }, + _errorFactory, + ))(input, "$input", true); + } return input; }; - const clone = (input) => { - const $io1 = (input) => - "string" === typeof input.name && - "number" === typeof input.age && - 19 < input.age && - input.age <= 100 && - "number" === typeof input.authority && - "string" === typeof input.joined_at && - /^(\d{4})-(\d{2})-(\d{2})$/.test(input.joined_at); - const $cp0 = (input) => - input.map((elem) => - "object" === typeof elem && null !== elem ? $co1(elem) : elem, - ); - const $co0 = (input) => ({ - id: input.id, - name: input.name, - limit: input.limit, - clerks: Array.isArray(input.clerks) ? $cp0(input.clerks) : input.clerks, - }); - const $co1 = (input) => ({ - name: input.name, - age: input.age, - authority: input.authority, - joined_at: input.joined_at, - }); - return "object" === typeof input && null !== input ? $co0(input) : input; - }; - assert(input); - const output = clone(input); - return output; -})(department); + const __clone = (input) => + "object" === typeof input && null !== input ? $co0(input) : input; + return (input, errorFactory) => __clone(__assert(input, errorFactory)); +})()(department); console.log(cloned); ``` @@ -513,263 +636,382 @@ When you want to remove every extra properties that are not defined in the type ```typescript copy filename="examples/src/assertPrune.ts" showLineNumbers {4} import typia from "typia"; -const department: IDepartment = typia.misc.random(); +const department: IDepartment = typia.random(); const pruned: IDepartment = typia.misc.assertPrune(department); console.log(pruned); interface IDepartment { - /** - * @format uuid - */ - id: string; - - /** - * @minLength 3 - */ - name: string; - - /** - * @type int - */ - limit: number; - - clerks: IClerk[]; + /** + * @format uuid + */ + id: string; + + /** + * @minLength 3 + */ + name: string; + + /** + * @type int + */ + limit: number; + + clerks: IClerk[]; } interface IClerk { - name: string; + name: string; - /** - * @exclusiveMinimum 19 - * @maximum 100 - */ - age: number; + /** + * @exclusiveMinimum 19 + * @maximum 100 + */ + age: number; - authority: number; + authority: number; - /** - * @format date - */ - joined_at: string; + /** + * @format date + */ + joined_at: string; } ``` -```javascript filename="examples/bin/assertPrune.js" showLineNumbers {147-173} -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); -const department = typia_1.default.misc.random(); -const pruned = ((input) => { - const assert = (input) => { - const __is = (input) => { - const $io0 = (input) => - "string" === typeof input.id && - /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input.id, - ) && - "string" === typeof input.name && - 3 <= input.name.length && - "number" === typeof input.limit && - Math.floor(input.limit) === input.limit && +```javascript filename="examples/bin/assertPrune.js" showLineNumbers {67-334} +import typia from "typia"; +const department = ((generator) => { + const $generator = typia.random.generator; + const $ro0 = (_recursive = false, _depth = 0) => ({ + id: + (generator?.customs ?? $generator.customs)?.string?.([ + { + name: 'Format<"uuid">', + kind: "format", + value: "uuid", + }, + ]) ?? (generator?.uuid ?? $generator.uuid)(), + name: + (generator?.customs ?? $generator.customs)?.string?.([ + { + name: "MinLength<3>", + kind: "minLength", + value: 3, + }, + ]) ?? + (generator?.string ?? $generator.string)( + (generator?.integer ?? $generator.integer)(3, 25), + ), + limit: + (generator?.customs ?? $generator.customs)?.number?.([ + { + name: 'Type<"int32">', + kind: "type", + value: "int32", + }, + ]) ?? (generator?.integer ?? $generator.integer)(0, 100), + clerks: (generator?.array ?? $generator.array)(() => + $ro1(_recursive, _recursive ? 1 + _depth : _depth), + ), + }); + const $ro1 = (_recursive = false, _depth = 0) => ({ + name: + (generator?.customs ?? $generator.customs)?.string?.([]) ?? + (generator?.string ?? $generator.string)(), + age: + (generator?.customs ?? $generator.customs)?.number?.([ + { + name: "ExclusiveMinimum<19>", + kind: "exclusiveMinimum", + value: 19, + }, + { + name: "Maximum<100>", + kind: "maximum", + value: 100, + }, + ]) ?? (generator?.number ?? $generator.number)(19, 100), + authority: + (generator?.customs ?? $generator.customs)?.number?.([]) ?? + (generator?.number ?? $generator.number)(0, 100), + joined_at: + (generator?.customs ?? $generator.customs)?.string?.([ + { + name: 'Format<"date">', + kind: "format", + value: "date", + }, + ]) ?? (generator?.date ?? $generator.date)(), + }); + return $ro0(); +})(); +const pruned = (() => { + const $guard = typia.misc.assertPrune.guard; + const $pp0 = (input) => + input.forEach((elem) => { + if ("object" === typeof elem && null !== elem) $po1(elem); + }); + const $io0 = (input) => + "string" === typeof input.id && + /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input.id, + ) && + "string" === typeof input.name && + 3 <= input.name.length && + "number" === typeof input.limit && + Math.floor(input.limit) === input.limit && + -2147483648 <= input.limit && + input.limit <= 2147483647 && + Array.isArray(input.clerks) && + input.clerks.every( + (elem) => "object" === typeof elem && null !== elem && $io1(elem), + ); + const $io1 = (input) => + "string" === typeof input.name && + "number" === typeof input.age && + 19 < input.age && + input.age <= 100 && + "number" === typeof input.authority && + "string" === typeof input.joined_at && + /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.test(input.joined_at); + const $ao0 = (input, _path, _exceptionable = true) => + (("string" === typeof input.id && + (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input.id, + ) || + $guard( + _exceptionable, + { + path: _path + ".id", + expected: 'string & Format<"uuid">', + value: input.id, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".id", + expected: '(string & Format<"uuid">)', + value: input.id, + }, + _errorFactory, + )) && + (("string" === typeof input.name && + (3 <= input.name.length || + $guard( + _exceptionable, + { + path: _path + ".name", + expected: "string & MinLength<3>", + value: input.name, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".name", + expected: "(string & MinLength<3>)", + value: input.name, + }, + _errorFactory, + )) && + (("number" === typeof input.limit && + ((Math.floor(input.limit) === input.limit && -2147483648 <= input.limit && - input.limit <= 2147483647 && - Array.isArray(input.clerks) && - input.clerks.every( - (elem) => "object" === typeof elem && null !== elem && $io1(elem), - ); - const $io1 = (input) => - "string" === typeof input.name && - "number" === typeof input.age && - 19 < input.age && - input.age <= 100 && - "number" === typeof input.authority && - "string" === typeof input.joined_at && - /^(\d{4})-(\d{2})-(\d{2})$/.test(input.joined_at); - return "object" === typeof input && null !== input && $io0(input); - }; - if (false === __is(input)) - ((input, _path, _exceptionable = true) => { - const $guard = typia_1.default.misc.assertPrune.guard; - const $ao0 = (input, _path, _exceptionable = true) => - (("string" === typeof input.id && - (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input.id, - ) || - $guard(_exceptionable, { - path: _path + ".id", - expected: 'string & Format<"uuid">', - value: input.id, - }))) || - $guard(_exceptionable, { - path: _path + ".id", - expected: '(string & Format<"uuid">)', - value: input.id, - })) && - (("string" === typeof input.name && - (3 <= input.name.length || - $guard(_exceptionable, { - path: _path + ".name", - expected: "string & MinLength<3>", - value: input.name, - }))) || - $guard(_exceptionable, { - path: _path + ".name", - expected: "(string & MinLength<3>)", - value: input.name, - })) && - (("number" === typeof input.limit && - ((Math.floor(input.limit) === input.limit && - -2147483648 <= input.limit && - input.limit <= 2147483647) || - $guard(_exceptionable, { - path: _path + ".limit", - expected: 'number & Type<"int32">', - value: input.limit, - }))) || - $guard(_exceptionable, { - path: _path + ".limit", - expected: '(number & Type<"int32">)', - value: input.limit, - })) && - (((Array.isArray(input.clerks) || - $guard(_exceptionable, { - path: _path + ".clerks", - expected: "Array", - value: input.clerks, - })) && - input.clerks.every( - (elem, _index1) => - ((("object" === typeof elem && null !== elem) || - $guard(_exceptionable, { - path: _path + ".clerks[" + _index1 + "]", - expected: "IClerk", - value: elem, - })) && - $ao1( - elem, - _path + ".clerks[" + _index1 + "]", - true && _exceptionable, - )) || - $guard(_exceptionable, { - path: _path + ".clerks[" + _index1 + "]", - expected: "IClerk", - value: elem, - }), + input.limit <= 2147483647) || + $guard( + _exceptionable, + { + path: _path + ".limit", + expected: 'number & Type<"int32">', + value: input.limit, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".limit", + expected: '(number & Type<"int32">)', + value: input.limit, + }, + _errorFactory, + )) && + (((Array.isArray(input.clerks) || + $guard( + _exceptionable, + { + path: _path + ".clerks", + expected: "Array", + value: input.clerks, + }, + _errorFactory, + )) && + input.clerks.every( + (elem, _index2) => + ((("object" === typeof elem && null !== elem) || + $guard( + _exceptionable, + { + path: _path + ".clerks[" + _index2 + "]", + expected: "IClerk", + value: elem, + }, + _errorFactory, + )) && + $ao1( + elem, + _path + ".clerks[" + _index2 + "]", + true && _exceptionable, )) || - $guard(_exceptionable, { - path: _path + ".clerks", - expected: "Array", - value: input.clerks, - })); - const $ao1 = (input, _path, _exceptionable = true) => - ("string" === typeof input.name || - $guard(_exceptionable, { - path: _path + ".name", - expected: "string", - value: input.name, - })) && - (("number" === typeof input.age && - (19 < input.age || - $guard(_exceptionable, { - path: _path + ".age", - expected: "number & ExclusiveMinimum<19>", - value: input.age, - })) && - (input.age <= 100 || - $guard(_exceptionable, { - path: _path + ".age", - expected: "number & Maximum<100>", - value: input.age, - }))) || - $guard(_exceptionable, { - path: _path + ".age", - expected: "(number & ExclusiveMinimum<19> & Maximum<100>)", - value: input.age, - })) && - ("number" === typeof input.authority || - $guard(_exceptionable, { - path: _path + ".authority", - expected: "number", - value: input.authority, - })) && - (("string" === typeof input.joined_at && - (/^(\d{4})-(\d{2})-(\d{2})$/.test(input.joined_at) || - $guard(_exceptionable, { - path: _path + ".joined_at", - expected: 'string & Format<"date">', - value: input.joined_at, - }))) || - $guard(_exceptionable, { - path: _path + ".joined_at", - expected: '(string & Format<"date">)', - value: input.joined_at, - })); - return ( - ((("object" === typeof input && null !== input) || - $guard(true, { + $guard( + _exceptionable, + { + path: _path + ".clerks[" + _index2 + "]", + expected: "IClerk", + value: elem, + }, + _errorFactory, + ), + )) || + $guard( + _exceptionable, + { + path: _path + ".clerks", + expected: "Array", + value: input.clerks, + }, + _errorFactory, + )); + const $ao1 = (input, _path, _exceptionable = true) => + ("string" === typeof input.name || + $guard( + _exceptionable, + { + path: _path + ".name", + expected: "string", + value: input.name, + }, + _errorFactory, + )) && + (("number" === typeof input.age && + (19 < input.age || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: "number & ExclusiveMinimum<19>", + value: input.age, + }, + _errorFactory, + )) && + (input.age <= 100 || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: "number & Maximum<100>", + value: input.age, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: "(number & ExclusiveMinimum<19> & Maximum<100>)", + value: input.age, + }, + _errorFactory, + )) && + ("number" === typeof input.authority || + $guard( + _exceptionable, + { + path: _path + ".authority", + expected: "number", + value: input.authority, + }, + _errorFactory, + )) && + (("string" === typeof input.joined_at && + (/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.test( + input.joined_at, + ) || + $guard( + _exceptionable, + { + path: _path + ".joined_at", + expected: 'string & Format<"date">', + value: input.joined_at, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".joined_at", + expected: '(string & Format<"date">)', + value: input.joined_at, + }, + _errorFactory, + )); + const $po0 = (input) => { + if (Array.isArray(input.clerks)) $pp0(input.clerks); + for (const key of Object.keys(input)) { + if ("id" === key || "name" === key || "limit" === key || "clerks" === key) + continue; + delete input[key]; + } + }; + const $po1 = (input) => { + for (const key of Object.keys(input)) { + if ( + "name" === key || + "age" === key || + "authority" === key || + "joined_at" === key + ) + continue; + delete input[key]; + } + }; + const __is = (input) => + "object" === typeof input && null !== input && $io0(input); + let _errorFactory; + const __assert = (input, errorFactory) => { + if (false === __is(input)) { + _errorFactory = errorFactory; + ((input, _path, _exceptionable = true) => + ((("object" === typeof input && null !== input) || + $guard( + true, + { path: _path + "", expected: "IDepartment", value: input, - })) && - $ao0(input, _path + "", true)) || - $guard(true, { + }, + _errorFactory, + )) && + $ao0(input, _path + "", true)) || + $guard( + true, + { path: _path + "", expected: "IDepartment", value: input, - }) - ); - })(input, "$input", true); + }, + _errorFactory, + ))(input, "$input", true); + } return input; }; - const prune = (input) => { - const $io1 = (input) => - "string" === typeof input.name && - "number" === typeof input.age && - 19 < input.age && - input.age <= 100 && - "number" === typeof input.authority && - "string" === typeof input.joined_at && - /^(\d{4})-(\d{2})-(\d{2})$/.test(input.joined_at); - const $pp0 = (input) => - input.forEach((elem) => { - if ("object" === typeof elem && null !== elem) $po1(elem); - }); - const $po0 = (input) => { - if (Array.isArray(input.clerks)) $pp0(input.clerks); - for (const key of Object.keys(input)) { - if ( - "id" === key || - "name" === key || - "limit" === key || - "clerks" === key - ) - continue; - delete input[key]; - } - }; - const $po1 = (input) => { - for (const key of Object.keys(input)) { - if ( - "name" === key || - "age" === key || - "authority" === key || - "joined_at" === key - ) - continue; - delete input[key]; - } - }; + const __prune = (input) => { if ("object" === typeof input && null !== input) $po0(input); }; - assert(input); - prune(input); - return input; -})(department); + return (input, errorFactory) => __prune(__assert(input, errorFactory)); +})()(department); console.log(pruned); ``` @@ -798,14 +1040,7 @@ typia.misc.literals<"A" | "B" | "C" | 1 | 2n>(); ```javascript filename="examples/bin/literals.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); +import typia from "typia"; ["A", "B", "C", 1, BigInt(2)]; ``` @@ -1021,23 +1256,17 @@ typia.notations.createCamel(); ``` -```javascript filename="examples/bin/camel.js" showLineNumbers {} -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); -(input) => { +```javascript filename="examples/bin/camel.js" showLineNumbers +import typia from "typia"; +(() => { const $co0 = (input) => ({ isMyNameSamchon: input.is_my_name_samchon, helloTheNewWorld: input.HelloTheNewWorld, toHTML: input.ToHTML, }); - return "object" === typeof input && null !== input ? $co0(input) : input; -}; + return (input) => + "object" === typeof input && null !== input ? $co0(input) : input; +})(); ``` @@ -1250,23 +1479,17 @@ typia.notations.createPascal(); ``` -```javascript filename="examples/bin/pascal.js" showLineNumbers {} -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); -(input) => { +```javascript filename="examples/bin/pascal.js" showLineNumbers +import typia from "typia"; +(() => { const $co0 = (input) => ({ IsMyNameSamchon: input.is_my_name_samchon, HelloTheNewWorld: input.helloTheNewWorld, ToHTML: input.toHTML, }); - return "object" === typeof input && null !== input ? $co0(input) : input; -}; + return (input) => + "object" === typeof input && null !== input ? $co0(input) : input; +})(); ``` @@ -1517,23 +1740,17 @@ typia.notations.createSnake(); ``` -```javascript filename="examples/bin/snake.js" showLineNumbers {} -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); -(input) => { +```javascript filename="examples/bin/snake.js" showLineNumbers +import typia from "typia"; +(() => { const $co0 = (input) => ({ is_my_name_samchon: input.isMyNameSamchon, hello_the_new_world: input.HelloTheNewWorld, to_html: input.ToHTML, }); - return "object" === typeof input && null !== input ? $co0(input) : input; -}; + return (input) => + "object" === typeof input && null !== input ? $co0(input) : input; +})(); ``` @@ -1773,34 +1990,29 @@ typia.http.createQuery(); ``` -```javascript filename="examples/bin/query.js" showLineNumbers {} -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); -(input) => { - const $params = typia_1.default.http.createQuery.params; - const $number = typia_1.default.http.createQuery.number; - const $boolean = typia_1.default.http.createQuery.boolean; - const $string = typia_1.default.http.createQuery.string; - const $array = typia_1.default.http.createQuery.array; - input = $params(input); - const output = { - limit: $number(input.get("limit")) ?? undefined, - enforce: $boolean(input.get("enforce")), - values: $array( - input.getAll("values").map((elem) => $string(elem)), - undefined, - ), - atomic: $string(input.get("atomic")), - indexes: input.getAll("indexes").map((elem) => $number(elem)), +```javascript filename="examples/bin/query.js" showLineNumbers +import typia from "typia"; +(() => { + const $params = typia.http.createQuery.params; + const $number = typia.http.createQuery.number; + const $boolean = typia.http.createQuery.boolean; + const $string = typia.http.createQuery.string; + const $array = typia.http.createQuery.array; + return (input) => { + input = $params(input); + const output = { + limit: $number(input.get("limit")) ?? undefined, + enforce: $boolean(input.get("enforce")), + values: $array( + input.getAll("values").map((elem) => $string(elem)), + undefined, + ), + atomic: $string(input.get("atomic")), + indexes: input.getAll("indexes").map((elem) => $number(elem)), + }; + return output; }; - return output; -}; +})(); ``` @@ -2050,35 +2262,31 @@ typia.http.createHeaders(); ``` -```javascript filename="examples/bin/headers.js" showLineNumbers {} -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); -(input) => { - const $number = typia_1.default.http.createHeaders.number; - const $boolean = typia_1.default.http.createHeaders.boolean; - const $string = typia_1.default.http.createHeaders.string; - const output = { - "x-Category": input["x-category"], - "x-MEMO": input["x-memo"], - "x-nAmE": input["x-name"], - "x-ValUes": Array.isArray(input["x-values"]) - ? input["x-values"].map($number) - : input["x-values"]?.split(", ")?.map($number) ?? [], - "x-FlAgS": Array.isArray(input["x-flags"]) - ? input["x-flags"].map($boolean) - : input["x-flags"]?.split(", ")?.map($boolean) ?? [], - "X-Descriptions": Array.isArray(input["x-descriptions"]) - ? input["x-descriptions"].map($string) - : input["x-descriptions"]?.split(", ")?.map($string) ?? [], +```javascript filename="examples/bin/headers.js" showLineNumbers +import typia from "typia"; +(() => { + const $number = typia.http.createHeaders.number; + const $boolean = typia.http.createHeaders.boolean; + const $string = typia.http.createHeaders.string; + return (input) => { + const output = { + "x-Category": input["x-category"], + "x-MEMO": input["x-memo"], + "x-nAmE": input["x-name"], + "x-ValUes": Array.isArray(input["x-values"]) + ? input["x-values"].map($number) + : input["x-values"]?.split(", ")?.map($number) ?? [], + "x-FlAgS": Array.isArray(input["x-flags"]) + ? input["x-flags"].map($boolean) + : input["x-flags"]?.split(", ")?.map($boolean) ?? [], + "X-Descriptions": Array.isArray(input["x-descriptions"]) + ? input["x-descriptions"].map($string) + : input["x-descriptions"]?.split(", ")?.map($string) ?? [], + }; + return output; }; - return output; -}; +})(); + ``` @@ -2126,84 +2334,91 @@ typia.http.createParameter>(); ``` -```javascript filename="examples/bin/parameter.js" showLineNumbers {} -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); +```javascript filename="examples/bin/parameter.js" showLineNumbers +import typia from "typia"; (input) => { - const $string = typia_1.default.http.createParameter.string; - const assert = (input) => { - const __is = (input) => { - return ( - "string" === typeof input && - /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input, - ) + const $string = typia.http.createParameter.string; + const assert = (() => { + const $guard = typia.http.createParameter.guard; + const __is = (input) => + "string" === typeof input && + /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input, ); - }; - if (false === __is(input)) - ((input, _path, _exceptionable = true) => { - const $guard = typia_1.default.http.createParameter.guard; - return ( + let _errorFactory; + return (input, errorFactory) => { + if (false === __is(input)) { + _errorFactory = errorFactory; + ((input, _path, _exceptionable = true) => ("string" === typeof input && (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( input, ) || - $guard(true, { - path: _path + "", - expected: 'string & Format<"uuid">', - value: input, - }))) || - $guard(true, { - path: _path + "", - expected: '(string & Format<"uuid">)', - value: input, - }) - ); - })(input, "$input", true); - return input; - }; + $guard( + true, + { + path: _path + "", + expected: 'string & Format<"uuid">', + value: input, + }, + _errorFactory, + ))) || + $guard( + true, + { + path: _path + "", + expected: '(string & Format<"uuid">)', + value: input, + }, + _errorFactory, + ))(input, "$input", true); + } + return input; + }; + })(); const value = $string(input); return assert(value); }; (input) => { - const $number = typia_1.default.http.createParameter.number; - const assert = (input) => { - const __is = (input) => { - return ( - "number" === typeof input && - Math.floor(input) === input && - 0 <= input && - input <= 4294967295 - ); - }; - if (false === __is(input)) - ((input, _path, _exceptionable = true) => { - const $guard = typia_1.default.http.createParameter.guard; - return ( + const $number = typia.http.createParameter.number; + const assert = (() => { + const $guard = typia.http.createParameter.guard; + const __is = (input) => + "number" === typeof input && + Math.floor(input) === input && + 0 <= input && + input <= 4294967295; + let _errorFactory; + return (input, errorFactory) => { + if (false === __is(input)) { + _errorFactory = errorFactory; + ((input, _path, _exceptionable = true) => ("number" === typeof input && ((Math.floor(input) === input && 0 <= input && input <= 4294967295) || - $guard(true, { - path: _path + "", - expected: 'number & Type<"uint32">', - value: input, - }))) || - $guard(true, { - path: _path + "", - expected: '(number & Type<"uint32">)', - value: input, - }) - ); - })(input, "$input", true); - return input; - }; + $guard( + true, + { + path: _path + "", + expected: 'number & Type<"uint32">', + value: input, + }, + _errorFactory, + ))) || + $guard( + true, + { + path: _path + "", + expected: '(number & Type<"uint32">)', + value: input, + }, + _errorFactory, + ))(input, "$input", true); + } + return input; + }; + })(); const value = $number(input); return assert(value); }; diff --git a/website/pages/docs/protobuf/decode.mdx b/website/pages/docs/protobuf/decode.mdx index abbc94a28b..8b0ad3d4a0 100644 --- a/website/pages/docs/protobuf/decode.mdx +++ b/website/pages/docs/protobuf/decode.mdx @@ -240,17 +240,10 @@ typia.protobuf.decode(encoded); ```javascript copy filename="protobuf.decode.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); +import typia from "typia"; const data = ((generator) => { - const $generator = typia_1.default.random.generator; - const $pick = typia_1.default.random.pick; + const $generator = typia.random.generator; + const $pick = typia.random.pick; const $ro0 = (_recursive = false, _depth = 0) => ({ id: (generator?.customs ?? $generator.customs)?.number?.([ @@ -353,11 +346,11 @@ const data = ((generator) => { }); return $ro0(); })(); -const encoded = ((input) => { - const $throws = typia_1.default.protobuf.encode.throws; - const $Sizer = typia_1.default.protobuf.encode.Sizer; - const $Writer = typia_1.default.protobuf.encode.Writer; - const encoder = (writer) => { +const encoded = (() => { + const $throws = typia.protobuf.encode.throws; + const $Sizer = typia.protobuf.encode.Sizer; + const $Writer = typia.protobuf.encode.Writer; + const encoder = (writer, input) => { const $peo0 = (input) => { // property "id"; writer.uint32(8); @@ -480,7 +473,9 @@ const encoded = ((input) => { input.ip, )) && "string" === typeof input.time && - !isNaN(new Date(input.time).getTime()); + /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(T|\s)([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i.test( + input.time, + ); const $iu0 = (input) => (() => { if ("cat" === input.type) return $io1(input); @@ -491,12 +486,14 @@ const encoded = ((input) => { $peo0(input); return writer; }; - const sizer = encoder(new $Sizer()); - const writer = encoder(new $Writer(sizer)); - return writer.buffer(); -})(data); -((input) => { - const $Reader = typia_1.default.protobuf.decode.Reader; + return (input) => { + const sizer = encoder(new $Sizer(), input); + const writer = encoder(new $Writer(sizer), input); + return writer.buffer(); + }; +})()(data); +(() => { + const $Reader = typia.protobuf.decode.Reader; const $pdo0 = (reader, length = -1) => { length = length < 0 ? reader.size() : reader.index() + length; const output = { @@ -666,9 +663,11 @@ const encoded = ((input) => { } return output; }; - const reader = new $Reader(input); - return $pdo0(reader); -})(encoded); + return (input) => { + const reader = new $Reader(input); + return $pdo0(reader); + }; +})()(encoded); ``` @@ -803,17 +802,9 @@ interface ICustomerLogin { ```javascript copy filename="protobuf.createDecode.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.encode = void 0; -const typia_1 = __importDefault(require("typia")); -const encode = (input) => { - const $Reader = typia_1.default.protobuf.createDecode.Reader; +import typia from "typia"; +export const encode = (() => { + const $Reader = typia.protobuf.createDecode.Reader; const $pdo0 = (reader, length = -1) => { length = length < 0 ? reader.size() : reader.index() + length; const output = { @@ -983,10 +974,11 @@ const encode = (input) => { } return output; }; - const reader = new $Reader(input); - return $pdo0(reader); -}; -exports.encode = encode; + return (input) => { + const reader = new $Reader(input); + return $pdo0(reader); + }; +})(); ``` diff --git a/website/pages/docs/protobuf/encode.mdx b/website/pages/docs/protobuf/encode.mdx index d05919e8ed..48061a7860 100644 --- a/website/pages/docs/protobuf/encode.mdx +++ b/website/pages/docs/protobuf/encode.mdx @@ -230,17 +230,10 @@ typia.protobuf.encode(customer); ```typescript copy filename="protobuf.encode.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); +import typia from "typia"; const customer = ((generator) => { - const $generator = typia_1.default.random.generator; - const $pick = typia_1.default.random.pick; + const $generator = typia.random.generator; + const $pick = typia.random.pick; const $ro0 = (_recursive = false, _depth = 0) => ({ id: (generator?.customs ?? $generator.customs)?.number?.([ @@ -343,11 +336,11 @@ const customer = ((generator) => { }); return $ro0(); })(); -((input) => { - const $throws = typia_1.default.protobuf.encode.throws; - const $Sizer = typia_1.default.protobuf.encode.Sizer; - const $Writer = typia_1.default.protobuf.encode.Writer; - const encoder = (writer) => { +(() => { + const $throws = typia.protobuf.encode.throws; + const $Sizer = typia.protobuf.encode.Sizer; + const $Writer = typia.protobuf.encode.Writer; + const encoder = (writer, input) => { const $peo0 = (input) => { // property "id"; writer.uint32(8); @@ -470,7 +463,9 @@ const customer = ((generator) => { input.ip, )) && "string" === typeof input.time && - !isNaN(new Date(input.time).getTime()); + /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(T|\s)([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i.test( + input.time, + ); const $iu0 = (input) => (() => { if ("cat" === input.type) return $io1(input); @@ -481,10 +476,12 @@ const customer = ((generator) => { $peo0(input); return writer; }; - const sizer = encoder(new $Sizer()); - const writer = encoder(new $Writer(sizer)); - return writer.buffer(); -})(customer); + return (input) => { + const sizer = encoder(new $Sizer(), input); + const writer = encoder(new $Writer(sizer), input); + return writer.buffer(); + }; +})()(customer); ``` @@ -826,20 +823,12 @@ interface ICustomerLogin { ```typescript copy filename="protobuf.createEncode.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.encode = void 0; -const typia_1 = __importDefault(require("typia")); -const encode = (input) => { - const $throws = typia_1.default.protobuf.createEncode.throws; - const $Sizer = typia_1.default.protobuf.createEncode.Sizer; - const $Writer = typia_1.default.protobuf.createEncode.Writer; - const encoder = (writer) => { +import typia from "typia"; +export const encode = (() => { + const $throws = typia.protobuf.createEncode.throws; + const $Sizer = typia.protobuf.createEncode.Sizer; + const $Writer = typia.protobuf.createEncode.Writer; + const encoder = (writer, input) => { const $peo0 = (input) => { // property "id"; writer.uint32(8); @@ -962,7 +951,9 @@ const encode = (input) => { input.ip, )) && "string" === typeof input.time && - !isNaN(new Date(input.time).getTime()); + /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(T|\s)([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i.test( + input.time, + ); const $iu0 = (input) => (() => { if ("cat" === input.type) return $io1(input); @@ -973,11 +964,12 @@ const encode = (input) => { $peo0(input); return writer; }; - const sizer = encoder(new $Sizer()); - const writer = encoder(new $Writer(sizer)); - return writer.buffer(); -}; -exports.encode = encode; + return (input) => { + const sizer = encoder(new $Sizer(), input); + const writer = encoder(new $Writer(sizer), input); + return writer.buffer(); + }; +})(); ``` diff --git a/website/pages/docs/protobuf/message.mdx b/website/pages/docs/protobuf/message.mdx index 307b2e71e3..58d115b290 100644 --- a/website/pages/docs/protobuf/message.mdx +++ b/website/pages/docs/protobuf/message.mdx @@ -184,24 +184,17 @@ message TypeTagExample { ``` -```javascript filename="TypeTagExample.js" showLineNumbers copy -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); +```javascript filename="TypeTagExample.js" showLineNumbers +import typia from "typia"; //---- // PROTOBUF MESSAGE SCHEMA //---- -('syntax = "proto3";\n\nmessage TypeTagExample {\n required int32 int32 = 1;\n required uint32 uint32 = 2;\n required uint64 uint64 = 3;\n required int64 int64 = 4;\n required float float = 5;\n optional double double = 6;\n optional string string = 7;\n oneof uint32_or_double {\n uint32 v8 = 8;\n double v9 = 9;\n }\n oneof int32_or_uint64 {\n int32 v10 = 10;\n uint64 v11 = 11;\n }\n oneof int32_or_float_or_uint64 {\n int32 v12 = 12;\n uint64 v13 = 13;\n float v14 = 14;\n }\n repeated uint64 uint64_array = 15;\n map int32_map = 16;\n}'); +('syntax = "proto3";\n\nmessage TypeTagExample {\n required int32 int32 = 1;\n required uint32 uint32 = 2;\n required uint64 uint64 = 3;\n required int64 int64 = 4;\n required float float = 5;\n optional double double = 6;\n optional string string = 7;\n oneof uint32_or_double {\n uint32 v8 = 8;\n double v9 = 9;\n }\n oneof int32_or_uint64 {\n int32 v10 = 10;\n uint64 v11 = 11;\n }\n oneof int32_or_float_or_uint64 {\n int32 v12 = 12;\n uint64 v13 = 13;\n float v14 = 14;\n }\n repeated uint64 uint64_array = 15;\n map int32_map = 16;\n}'); //---- // DECODE FUNCTION //---- -(input) => { - const $Reader = typia_1.default.protobuf.createDecode.Reader; +(() => { + const $Reader = typia.protobuf.createDecode.Reader; const $pdo0 = (reader, length = -1) => { length = length < 0 ? reader.size() : reader.index() + length; const output = { @@ -320,17 +313,19 @@ const typia_1 = __importDefault(require("typia")); } return output; }; - const reader = new $Reader(input); - return $pdo0(reader); -}; + return (input) => { + const reader = new $Reader(input); + return $pdo0(reader); + }; +})(); //---- // ENCODE FUNCTION //---- -(input) => { - const $throws = typia_1.default.protobuf.createEncode.throws; - const $Sizer = typia_1.default.protobuf.createEncode.Sizer; - const $Writer = typia_1.default.protobuf.createEncode.Writer; - const encoder = (writer) => { +(() => { + const $throws = typia.protobuf.createEncode.throws; + const $Sizer = typia.protobuf.createEncode.Sizer; + const $Writer = typia.protobuf.createEncode.Writer; + const encoder = (writer, input) => { const $peo0 = (input) => { // property "int32"; writer.uint32(8); @@ -438,10 +433,12 @@ const typia_1 = __importDefault(require("typia")); $peo0(input); return writer; }; - const sizer = encoder(new $Sizer()); - const writer = encoder(new $Writer(sizer)); - return writer.buffer(); -}; + return (input) => { + const sizer = encoder(new $Sizer(), input); + const writer = encoder(new $Writer(sizer), input); + return writer.buffer(); + }; +})(); ``` @@ -537,24 +534,17 @@ message CommentTagExample { ``` -```javascript filename="CommentTagExample.js" showLineNumbers copy -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); +```javascript filename="CommentTagExample.js" showLineNumbers +import typia from "typia"; //---- // PROTOBUF MESSAGE SCHEMA //---- -('syntax = "proto3";\n\nmessage CommentTagExample {\n required int32 int32 = 1;\n optional uint32 uint32 = 2;\n optional uint64 uint64 = 3;\n required int64 int64 = 4;\n optional float float = 5;\n required double double = 6;\n required string string = 7;\n}'); +('syntax = "proto3";\n\nmessage CommentTagExample {\n required int32 int32 = 1;\n optional uint32 uint32 = 2;\n optional uint64 uint64 = 3;\n required int64 int64 = 4;\n optional float float = 5;\n required double double = 6;\n required string string = 7;\n}'); //---- // DECODE FUNCTION //---- -(input) => { - const $Reader = typia_1.default.protobuf.createDecode.Reader; +(() => { + const $Reader = typia.protobuf.createDecode.Reader; const $pdo0 = (reader, length = -1) => { length = length < 0 ? reader.size() : reader.index() + length; const output = { @@ -604,16 +594,18 @@ const typia_1 = __importDefault(require("typia")); } return output; }; - const reader = new $Reader(input); - return $pdo0(reader); -}; + return (input) => { + const reader = new $Reader(input); + return $pdo0(reader); + }; +})(); //---- // ENCODE FUNCTION //---- -(input) => { - const $Sizer = typia_1.default.protobuf.createEncode.Sizer; - const $Writer = typia_1.default.protobuf.createEncode.Writer; - const encoder = (writer) => { +(() => { + const $Sizer = typia.protobuf.createEncode.Sizer; + const $Writer = typia.protobuf.createEncode.Writer; + const encoder = (writer, input) => { const $peo0 = (input) => { // property "int32"; writer.uint32(8); @@ -647,10 +639,12 @@ const typia_1 = __importDefault(require("typia")); $peo0(input); return writer; }; - const sizer = encoder(new $Sizer()); - const writer = encoder(new $Writer(sizer)); - return writer.buffer(); -}; + return (input) => { + const sizer = encoder(new $Sizer(), input); + const writer = encoder(new $Writer(sizer), input); + return writer.buffer(); + }; +})(); ``` diff --git a/website/pages/docs/pure.mdx b/website/pages/docs/pure.mdx index 5f85c578ef..7b91f88088 100644 --- a/website/pages/docs/pure.mdx +++ b/website/pages/docs/pure.mdx @@ -370,196 +370,277 @@ export const assertArticle = typia.createAssert(); ```javascript filename="assertArticle.js" showLineNumbers -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.assertArticle = void 0; -const typia_1 = __importDefault(require("typia")); -const assertArticle = (input) => { - const __is = (input) => { - const $io0 = (input) => - "string" === typeof input.id && - /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( +import typia from "typia"; +export const assertArticle = (() => { + const $guard = typia.createAssert.guard; + const $io0 = (input) => + "string" === typeof input.id && + /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input.id, + ) && + (null === input.files || + (Array.isArray(input.files) && + input.files.every( + (elem) => "object" === typeof elem && null !== elem && $io1(elem), + ))) && + (null === input.title || + ("string" === typeof input.title && + 5 <= input.title.length && + input.title.length <= 100)) && + "string" === typeof input.body && + "string" === typeof input.created_at && + /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(T|\s)([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i.test( + input.created_at, + ); + const $io1 = (input) => + "string" === typeof input.name && + /^[a-z0-9]+$/.test(input.name) && + input.name.length <= 255 && + (null === input.extension || + ("string" === typeof input.extension && + /^[a-z0-9]+$/.test(input.extension) && + input.extension.length <= 8)) && + "string" === typeof input.url; + const $ao0 = (input, _path, _exceptionable = true) => + (("string" === typeof input.id && + (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( input.id, - ) && - (null === input.files || - (Array.isArray(input.files) && - input.files.every( - (elem) => "object" === typeof elem && null !== elem && $io1(elem), - ))) && - (null === input.title || - ("string" === typeof input.title && - 5 <= input.title.length && - input.title.length <= 100)) && - "string" === typeof input.body && - "string" === typeof input.created_at && - !isNaN(new Date(input.created_at).getTime()); - const $io1 = (input) => - "string" === typeof input.name && - /^[a-z0-9]+$/.test(input.name) && - input.name.length <= 255 && - (null === input.extension || - ("string" === typeof input.extension && - /^[a-z0-9]+$/.test(input.extension) && - input.extension.length <= 8)) && - "string" === typeof input.url; - return "object" === typeof input && null !== input && $io0(input); - }; - if (false === __is(input)) - ((input, _path, _exceptionable = true) => { - const $guard = typia_1.default.createAssert.guard; - const $ao0 = (input, _path, _exceptionable = true) => - (("string" === typeof input.id && - (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input.id, - ) || - $guard(_exceptionable, { - path: _path + ".id", - expected: 'string & Format<"uuid">', - value: input.id, - }))) || - $guard(_exceptionable, { + ) || + $guard( + _exceptionable, + { path: _path + ".id", - expected: '(string & Format<"uuid">)', + expected: 'string & Format<"uuid">', value: input.id, - })) && - (null === input.files || - ((Array.isArray(input.files) || - $guard(_exceptionable, { - path: _path + ".files", - expected: "(Array | null)", - value: input.files, - })) && - input.files.every( - (elem, _index1) => - ((("object" === typeof elem && null !== elem) || - $guard(_exceptionable, { - path: _path + ".files[" + _index1 + "]", - expected: "IAttachmentFile", - value: elem, - })) && - $ao1( - elem, - _path + ".files[" + _index1 + "]", - true && _exceptionable, - )) || - $guard(_exceptionable, { - path: _path + ".files[" + _index1 + "]", - expected: "IAttachmentFile", - value: elem, - }), - )) || - $guard(_exceptionable, { + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".id", + expected: '(string & Format<"uuid">)', + value: input.id, + }, + _errorFactory, + )) && + (null === input.files || + ((Array.isArray(input.files) || + $guard( + _exceptionable, + { path: _path + ".files", expected: "(Array | null)", value: input.files, - })) && - (null === input.title || - ("string" === typeof input.title && - (5 <= input.title.length || - $guard(_exceptionable, { - path: _path + ".title", - expected: "string & MinLength<5>", - value: input.title, - })) && - (input.title.length <= 100 || - $guard(_exceptionable, { - path: _path + ".title", - expected: "string & MaxLength<100>", - value: input.title, - }))) || - $guard(_exceptionable, { - path: _path + ".title", - expected: "((string & MinLength<5> & MaxLength<100>) | null)", - value: input.title, - })) && - ("string" === typeof input.body || - $guard(_exceptionable, { - path: _path + ".body", - expected: "string", - value: input.body, - })) && - (("string" === typeof input.created_at && - (!isNaN(new Date(input.created_at).getTime()) || - $guard(_exceptionable, { - path: _path + ".created_at", - expected: 'string & Format<"date-time">', - value: input.created_at, - }))) || - $guard(_exceptionable, { + }, + _errorFactory, + )) && + input.files.every( + (elem, _index2) => + ((("object" === typeof elem && null !== elem) || + $guard( + _exceptionable, + { + path: _path + ".files[" + _index2 + "]", + expected: "IAttachmentFile", + value: elem, + }, + _errorFactory, + )) && + $ao1( + elem, + _path + ".files[" + _index2 + "]", + true && _exceptionable, + )) || + $guard( + _exceptionable, + { + path: _path + ".files[" + _index2 + "]", + expected: "IAttachmentFile", + value: elem, + }, + _errorFactory, + ), + )) || + $guard( + _exceptionable, + { + path: _path + ".files", + expected: "(Array | null)", + value: input.files, + }, + _errorFactory, + )) && + (null === input.title || + ("string" === typeof input.title && + (5 <= input.title.length || + $guard( + _exceptionable, + { + path: _path + ".title", + expected: "string & MinLength<5>", + value: input.title, + }, + _errorFactory, + )) && + (input.title.length <= 100 || + $guard( + _exceptionable, + { + path: _path + ".title", + expected: "string & MaxLength<100>", + value: input.title, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".title", + expected: "((string & MinLength<5> & MaxLength<100>) | null)", + value: input.title, + }, + _errorFactory, + )) && + ("string" === typeof input.body || + $guard( + _exceptionable, + { + path: _path + ".body", + expected: "string", + value: input.body, + }, + _errorFactory, + )) && + (("string" === typeof input.created_at && + (/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(T|\s)([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i.test( + input.created_at, + ) || + $guard( + _exceptionable, + { path: _path + ".created_at", - expected: '(string & Format<"date-time">)', + expected: 'string & Format<"date-time">', value: input.created_at, - })); - const $ao1 = (input, _path, _exceptionable = true) => - (("string" === typeof input.name && - (/^[a-z0-9]+$/.test(input.name) || - $guard(_exceptionable, { - path: _path + ".name", - expected: 'string & Pattern<"^[a-z0-9]+$">', - value: input.name, - })) && - (input.name.length <= 255 || - $guard(_exceptionable, { - path: _path + ".name", - expected: "string & MaxLength<255>", - value: input.name, - }))) || - $guard(_exceptionable, { + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".created_at", + expected: '(string & Format<"date-time">)', + value: input.created_at, + }, + _errorFactory, + )); + const $ao1 = (input, _path, _exceptionable = true) => + (("string" === typeof input.name && + (/^[a-z0-9]+$/.test(input.name) || + $guard( + _exceptionable, + { path: _path + ".name", - expected: '(string & Pattern<"^[a-z0-9]+$"> & MaxLength<255>)', + expected: 'string & Pattern<"^[a-z0-9]+$">', value: input.name, - })) && - (null === input.extension || - ("string" === typeof input.extension && - (/^[a-z0-9]+$/.test(input.extension) || - $guard(_exceptionable, { - path: _path + ".extension", - expected: 'string & Pattern<"^[a-z0-9]+$">', - value: input.extension, - })) && - (input.extension.length <= 8 || - $guard(_exceptionable, { - path: _path + ".extension", - expected: "string & MaxLength<8>", - value: input.extension, - }))) || - $guard(_exceptionable, { - path: _path + ".extension", - expected: - '((string & Pattern<"^[a-z0-9]+$"> & MaxLength<8>) | null)', - value: input.extension, - })) && - ("string" === typeof input.url || - $guard(_exceptionable, { - path: _path + ".url", - expected: "string", - value: input.url, - })); - return ( + }, + _errorFactory, + )) && + (input.name.length <= 255 || + $guard( + _exceptionable, + { + path: _path + ".name", + expected: "string & MaxLength<255>", + value: input.name, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".name", + expected: '(string & Pattern<"^[a-z0-9]+$"> & MaxLength<255>)', + value: input.name, + }, + _errorFactory, + )) && + (null === input.extension || + ("string" === typeof input.extension && + (/^[a-z0-9]+$/.test(input.extension) || + $guard( + _exceptionable, + { + path: _path + ".extension", + expected: 'string & Pattern<"^[a-z0-9]+$">', + value: input.extension, + }, + _errorFactory, + )) && + (input.extension.length <= 8 || + $guard( + _exceptionable, + { + path: _path + ".extension", + expected: "string & MaxLength<8>", + value: input.extension, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".extension", + expected: '((string & Pattern<"^[a-z0-9]+$"> & MaxLength<8>) | null)', + value: input.extension, + }, + _errorFactory, + )) && + ("string" === typeof input.url || + $guard( + _exceptionable, + { + path: _path + ".url", + expected: "string", + value: input.url, + }, + _errorFactory, + )); + const __is = (input) => + "object" === typeof input && null !== input && $io0(input); + let _errorFactory; + return (input, errorFactory) => { + if (false === __is(input)) { + _errorFactory = errorFactory; + ((input, _path, _exceptionable = true) => ((("object" === typeof input && null !== input) || - $guard(true, { + $guard( + true, + { + path: _path + "", + expected: "IBbsArticle", + value: input, + }, + _errorFactory, + )) && + $ao0(input, _path + "", true)) || + $guard( + true, + { path: _path + "", expected: "IBbsArticle", value: input, - })) && - $ao0(input, _path + "", true)) || - $guard(true, { - path: _path + "", - expected: "IBbsArticle", - value: input, - }) - ); - })(input, "$input", true); - return input; -}; -exports.assertArticle = assertArticle; + }, + _errorFactory, + ))(input, "$input", true); + } + return input; + }; +})(); ``` -![Assert Function Benchmark](https://github.com/samchon/typia/raw/master/benchmark/results/11th%20Gen%20Intel(R)%20Core(TM)%20i5-1135G7%20%40%202.40GHz/images/assert.svg) +![Assert Function Benchmark](https://github.com/samchon/typia/raw/master/benchmark/results/AMD%20Ryzen%209%207940HS%20w%20Radeon%20780M%20Graphics/images/assert.svg) > Measured on [AMD Ryzen 9 7940HS, Rog Flow x13](https://github.com/samchon/typia/tree/master/benchmark/results/AMD%20Ryzen%209%207940HS%20w%20Radeon%20780M%20Graphics#assert) diff --git a/website/pages/docs/random.mdx b/website/pages/docs/random.mdx index e37c0ff99e..4d5213bcd1 100644 --- a/website/pages/docs/random.mdx +++ b/website/pages/docs/random.mdx @@ -570,17 +570,10 @@ interface CommentTag { ```javascript filename="random.tags.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); +import typia from "typia"; const data = ((generator) => { - const $generator = typia_1.default.random.generator; - const $pick = typia_1.default.random.pick; + const $generator = typia.random.generator; + const $pick = typia.random.pick; const $ro0 = (_recursive = false, _depth = 0) => ({ type: (generator?.customs ?? $generator.customs)?.number?.([ @@ -656,6 +649,11 @@ console.log(data); ]}> ```typescript copy +export function random(g?: IRandomGenerator): Resolved; +``` + + +```typescript copy import { Customizable } from "./typings/Customizable"; export interface IRandomGenerator { diff --git a/website/pages/docs/setup.mdx b/website/pages/docs/setup.mdx index af64705d47..de9e33cb62 100644 --- a/website/pages/docs/setup.mdx +++ b/website/pages/docs/setup.mdx @@ -68,20 +68,10 @@ interface IMember { ``` -```javascript filename="examples/bin/check.js" showLineNumbers {2-12} -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.check = void 0; -const typia_1 = __importDefault(require("typia")); -const check = (input) => { - return ( - "object" === typeof input && - null !== input && +```javascript filename="examples/bin/check.js" showLineNumbers {2-16} +import typia from "typia"; +export const check = (() => { + const $io0 = (input) => "string" === typeof input.id && /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( input.id, @@ -92,10 +82,9 @@ const check = (input) => { ) && "number" === typeof input.age && 19 < input.age && - input.age <= 100 - ); -}; -exports.check = check; + input.age <= 100; + return (input) => "object" === typeof input && null !== input && $io0(input); +})(); ``` diff --git a/website/pages/docs/validators/assert.mdx b/website/pages/docs/validators/assert.mdx index f8535c9cd0..247a1048a5 100644 --- a/website/pages/docs/validators/assert.mdx +++ b/website/pages/docs/validators/assert.mdx @@ -75,113 +75,145 @@ interface IMember { ```javascript filename="examples/bin/assert.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); -const uuid_1 = require("uuid"); -((input) => { - const __is = (input) => { - return ( - "object" === typeof input && - null !== input && - "string" === typeof input.id && - /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( +import typia from "typia"; +import { v4 } from "uuid"; +(() => { + const $guard = typia.assert.guard; + const $io0 = (input) => + "string" === typeof input.id && + /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input.id, + ) && + "string" === typeof input.email && + /^[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.test( + input.email, + ) && + "number" === typeof input.age && + Math.floor(input.age) === input.age && + 0 <= input.age && + input.age <= 4294967295 && + 19 < input.age && + input.age <= 100; + const $ao0 = (input, _path, _exceptionable = true) => + (("string" === typeof input.id && + (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( input.id, - ) && - "string" === typeof input.email && - /^[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.test( - input.email, - ) && - "number" === typeof input.age && - Math.floor(input.age) === input.age && - 0 <= input.age && - input.age <= 4294967295 && - 19 < input.age && - input.age <= 100 - ); - }; - if (false === __is(input)) - ((input, _path, _exceptionable = true) => { - const $guard = typia_1.default.assert.guard; - const $ao0 = (input, _path, _exceptionable = true) => - (("string" === typeof input.id && - (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input.id, - ) || - $guard(_exceptionable, { - path: _path + ".id", - expected: 'string & Format<"uuid">', - value: input.id, - }))) || - $guard(_exceptionable, { + ) || + $guard( + _exceptionable, + { path: _path + ".id", - expected: '(string & Format<"uuid">)', + expected: 'string & Format<"uuid">', value: input.id, - })) && - (("string" === typeof input.email && - (/^[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.test( - input.email, - ) || - $guard(_exceptionable, { - path: _path + ".email", - expected: 'string & Format<"email">', - value: input.email, - }))) || - $guard(_exceptionable, { + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".id", + expected: '(string & Format<"uuid">)', + value: input.id, + }, + _errorFactory, + )) && + (("string" === typeof input.email && + (/^[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.test( + input.email, + ) || + $guard( + _exceptionable, + { path: _path + ".email", - expected: '(string & Format<"email">)', + expected: 'string & Format<"email">', value: input.email, - })) && - (("number" === typeof input.age && - ((Math.floor(input.age) === input.age && - 0 <= input.age && - input.age <= 4294967295) || - $guard(_exceptionable, { - path: _path + ".age", - expected: 'number & Type<"uint32">', - value: input.age, - })) && - (19 < input.age || - $guard(_exceptionable, { - path: _path + ".age", - expected: "number & ExclusiveMinimum<19>", - value: input.age, - })) && - (input.age <= 100 || - $guard(_exceptionable, { - path: _path + ".age", - expected: "number & Maximum<100>", - value: input.age, - }))) || - $guard(_exceptionable, { + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".email", + expected: '(string & Format<"email">)', + value: input.email, + }, + _errorFactory, + )) && + (("number" === typeof input.age && + ((Math.floor(input.age) === input.age && + 0 <= input.age && + input.age <= 4294967295) || + $guard( + _exceptionable, + { path: _path + ".age", - expected: - '(number & Type<"uint32"> & ExclusiveMinimum<19> & Maximum<100>)', + expected: 'number & Type<"uint32">', value: input.age, - })); - return ( + }, + _errorFactory, + )) && + (19 < input.age || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: "number & ExclusiveMinimum<19>", + value: input.age, + }, + _errorFactory, + )) && + (input.age <= 100 || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: "number & Maximum<100>", + value: input.age, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: + '(number & Type<"uint32"> & ExclusiveMinimum<19> & Maximum<100>)', + value: input.age, + }, + _errorFactory, + )); + const __is = (input) => + "object" === typeof input && null !== input && $io0(input); + let _errorFactory; + return (input, errorFactory) => { + if (false === __is(input)) { + _errorFactory = errorFactory; + ((input, _path, _exceptionable = true) => ((("object" === typeof input && null !== input) || - $guard(true, { + $guard( + true, + { + path: _path + "", + expected: "IMember", + value: input, + }, + _errorFactory, + )) && + $ao0(input, _path + "", true)) || + $guard( + true, + { path: _path + "", expected: "IMember", value: input, - })) && - $ao0(input, _path + "", true)) || - $guard(true, { - path: _path + "", - expected: "IMember", - value: input, - }) - ); - })(input, "$input", true); - return input; -})({ - id: (0, uuid_1.v4)(), + }, + _errorFactory, + ))(input, "$input", true); + } + return input; + }; +})()({ + id: v4(), email: "samchon.github@gmail.com", age: 18, // wrong, must be greater than 19 }); @@ -251,117 +283,149 @@ interface IMember { ```javascript filename="examples/bin/assertEquals.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); -const uuid_1 = require("uuid"); -((input) => { - const __is = (input) => { - return ( - "object" === typeof input && - null !== input && - "string" === typeof input.id && - /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( +import typia from "typia"; +import { v4 } from "uuid"; +(() => { + const $guard = typia.assert.guard; + const $io0 = (input) => + "string" === typeof input.id && + /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input.id, + ) && + "string" === typeof input.email && + /^[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.test( + input.email, + ) && + "number" === typeof input.age && + Math.floor(input.age) === input.age && + 0 <= input.age && + input.age <= 4294967295 && + 19 < input.age && + input.age <= 100; + const $ao0 = (input, _path, _exceptionable = true) => + (("string" === typeof input.id && + (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( input.id, - ) && - "string" === typeof input.email && - /^[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.test( - input.email, - ) && - "number" === typeof input.age && - Math.floor(input.age) === input.age && - 0 <= input.age && - input.age <= 4294967295 && - 19 < input.age && - input.age <= 100 - ); - }; - if (false === __is(input)) - ((input, _path, _exceptionable = true) => { - const $guard = typia_1.default.assert.guard; - const $ao0 = (input, _path, _exceptionable = true) => - (("string" === typeof input.id && - (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input.id, - ) || - $guard(_exceptionable, { - path: _path + ".id", - expected: 'string & Format<"uuid">', - value: input.id, - }))) || - $guard(_exceptionable, { + ) || + $guard( + _exceptionable, + { path: _path + ".id", - expected: '(string & Format<"uuid">)', + expected: 'string & Format<"uuid">', value: input.id, - })) && - (("string" === typeof input.email && - (/^[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.test( - input.email, - ) || - $guard(_exceptionable, { - path: _path + ".email", - expected: 'string & Format<"email">', - value: input.email, - }))) || - $guard(_exceptionable, { + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".id", + expected: '(string & Format<"uuid">)', + value: input.id, + }, + _errorFactory, + )) && + (("string" === typeof input.email && + (/^[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.test( + input.email, + ) || + $guard( + _exceptionable, + { path: _path + ".email", - expected: '(string & Format<"email">)', + expected: 'string & Format<"email">', value: input.email, - })) && - (("number" === typeof input.age && - ((Math.floor(input.age) === input.age && - 0 <= input.age && - input.age <= 4294967295) || - $guard(_exceptionable, { - path: _path + ".age", - expected: 'number & Type<"uint32">', - value: input.age, - })) && - (19 < input.age || - $guard(_exceptionable, { - path: _path + ".age", - expected: "number & ExclusiveMinimum<19>", - value: input.age, - })) && - (input.age <= 100 || - $guard(_exceptionable, { - path: _path + ".age", - expected: "number & Maximum<100>", - value: input.age, - }))) || - $guard(_exceptionable, { + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".email", + expected: '(string & Format<"email">)', + value: input.email, + }, + _errorFactory, + )) && + (("number" === typeof input.age && + ((Math.floor(input.age) === input.age && + 0 <= input.age && + input.age <= 4294967295) || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: 'number & Type<"uint32">', + value: input.age, + }, + _errorFactory, + )) && + (19 < input.age || + $guard( + _exceptionable, + { path: _path + ".age", - expected: - '(number & Type<"uint32"> & ExclusiveMinimum<19> & Maximum<100>)', + expected: "number & ExclusiveMinimum<19>", value: input.age, - })); - return ( + }, + _errorFactory, + )) && + (input.age <= 100 || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: "number & Maximum<100>", + value: input.age, + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: + '(number & Type<"uint32"> & ExclusiveMinimum<19> & Maximum<100>)', + value: input.age, + }, + _errorFactory, + )); + const __is = (input) => + "object" === typeof input && null !== input && $io0(input); + let _errorFactory; + return (input, errorFactory) => { + if (false === __is(input)) { + _errorFactory = errorFactory; + ((input, _path, _exceptionable = true) => ((("object" === typeof input && null !== input) || - $guard(true, { + $guard( + true, + { + path: _path + "", + expected: "IMember", + value: input, + }, + _errorFactory, + )) && + $ao0(input, _path + "", true)) || + $guard( + true, + { path: _path + "", expected: "IMember", value: input, - })) && - $ao0(input, _path + "", true)) || - $guard(true, { - path: _path + "", - expected: "IMember", - value: input, - }) - ); - })(input, "$input", true); - return input; -})({ - id: (0, uuid_1.v4)(), + }, + _errorFactory, + ))(input, "$input", true); + } + return input; + }; +})()({ + id: v4(), email: "samchon.github@gmail.com", age: 30, sex: 1, // extra -}) +}); ``` @@ -482,113 +546,143 @@ interface IMember { ```javascript filename="examples/bin/createAssert.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.assertMember = void 0; -const typia_1 = __importDefault(require("typia")); -const assertMember = (input) => { - const __is = (input) => { - return ( - "object" === typeof input && - null !== input && - "string" === typeof input.id && - /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( +import typia from "typia"; +export const assertMember = (() => { + const $guard = typia.createAssert.guard; + const $io0 = (input) => + "string" === typeof input.id && + /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input.id, + ) && + "string" === typeof input.email && + /^[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.test( + input.email, + ) && + "number" === typeof input.age && + Math.floor(input.age) === input.age && + 0 <= input.age && + input.age <= 4294967295 && + 19 < input.age && + input.age <= 100; + const $ao0 = (input, _path, _exceptionable = true) => + (("string" === typeof input.id && + (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( input.id, - ) && - "string" === typeof input.email && - /^[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.test( - input.email, - ) && - "number" === typeof input.age && - Math.floor(input.age) === input.age && - 0 <= input.age && - input.age <= 4294967295 && - 19 < input.age && - input.age <= 100 - ); - }; - if (false === __is(input)) - ((input, _path, _exceptionable = true) => { - const $guard = typia_1.default.createAssert.guard; - const $ao0 = (input, _path, _exceptionable = true) => - (("string" === typeof input.id && - (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input.id, - ) || - $guard(_exceptionable, { - path: _path + ".id", - expected: 'string & Format<"uuid">', - value: input.id, - }))) || - $guard(_exceptionable, { + ) || + $guard( + _exceptionable, + { path: _path + ".id", - expected: '(string & Format<"uuid">)', + expected: 'string & Format<"uuid">', value: input.id, - })) && - (("string" === typeof input.email && - (/^[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.test( - input.email, - ) || - $guard(_exceptionable, { - path: _path + ".email", - expected: 'string & Format<"email">', - value: input.email, - }))) || - $guard(_exceptionable, { + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".id", + expected: '(string & Format<"uuid">)', + value: input.id, + }, + _errorFactory, + )) && + (("string" === typeof input.email && + (/^[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.test( + input.email, + ) || + $guard( + _exceptionable, + { path: _path + ".email", - expected: '(string & Format<"email">)', + expected: 'string & Format<"email">', value: input.email, - })) && - (("number" === typeof input.age && - ((Math.floor(input.age) === input.age && - 0 <= input.age && - input.age <= 4294967295) || - $guard(_exceptionable, { - path: _path + ".age", - expected: 'number & Type<"uint32">', - value: input.age, - })) && - (19 < input.age || - $guard(_exceptionable, { - path: _path + ".age", - expected: "number & ExclusiveMinimum<19>", - value: input.age, - })) && - (input.age <= 100 || - $guard(_exceptionable, { - path: _path + ".age", - expected: "number & Maximum<100>", - value: input.age, - }))) || - $guard(_exceptionable, { + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".email", + expected: '(string & Format<"email">)', + value: input.email, + }, + _errorFactory, + )) && + (("number" === typeof input.age && + ((Math.floor(input.age) === input.age && + 0 <= input.age && + input.age <= 4294967295) || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: 'number & Type<"uint32">', + value: input.age, + }, + _errorFactory, + )) && + (19 < input.age || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: "number & ExclusiveMinimum<19>", + value: input.age, + }, + _errorFactory, + )) && + (input.age <= 100 || + $guard( + _exceptionable, + { path: _path + ".age", - expected: - '(number & Type<"uint32"> & ExclusiveMinimum<19> & Maximum<100>)', + expected: "number & Maximum<100>", value: input.age, - })); - return ( + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".age", + expected: + '(number & Type<"uint32"> & ExclusiveMinimum<19> & Maximum<100>)', + value: input.age, + }, + _errorFactory, + )); + const __is = (input) => + "object" === typeof input && null !== input && $io0(input); + let _errorFactory; + return (input, errorFactory) => { + if (false === __is(input)) { + _errorFactory = errorFactory; + ((input, _path, _exceptionable = true) => ((("object" === typeof input && null !== input) || - $guard(true, { + $guard( + true, + { + path: _path + "", + expected: "IMember", + value: input, + }, + _errorFactory, + )) && + $ao0(input, _path + "", true)) || + $guard( + true, + { path: _path + "", expected: "IMember", value: input, - })) && - $ao0(input, _path + "", true)) || - $guard(true, { - path: _path + "", - expected: "IMember", - value: input, - }) - ); - })(input, "$input", true); - return input; -}; -exports.assertMember = assertMember; + }, + _errorFactory, + ))(input, "$input", true); + } + return input; + }; +})(); ``` @@ -655,16 +749,9 @@ typia.createIs>(); ```javascript filename="examples/bin/is-map.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); -(input) => { - return ( +import typia from "typia"; +(() => { + return (input) => input instanceof Map && (() => [...input].every( @@ -675,9 +762,8 @@ const typia_1 = __importDefault(require("typia")); ("string" === typeof elem[1] || "number" === typeof elem[1] || "boolean" === typeof elem[1]), - ))() - ); -}; + ))(); +})(); ``` @@ -745,88 +831,110 @@ interface Something { ```javascript filename="examples/bin/assert-custom-tags.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.assertSomething = void 0; -const typia_1 = __importDefault(require("typia")); -const assertSomething = (input) => { - const __is = (input) => { - return ( - "object" === typeof input && - null !== input && - "string" === typeof input.dollar && - input.dollar[0] === "$" && - !isNaN(Number(input.dollar.substring(1).split(",").join(""))) && - "string" === typeof input.postfix && - input.postfix.endsWith("!!!") && - "number" === typeof input.isEven && - input.isEven % 2 === 0 - ); - }; - if (false === __is(input)) - ((input, _path, _exceptionable = true) => { - const $guard = typia_1.default.createAssert.guard; - const $ao0 = (input, _path, _exceptionable = true) => - (("string" === typeof input.dollar && - ((input.dollar[0] === "$" && - !isNaN(Number(input.dollar.substring(1).split(",").join("")))) || - $guard(_exceptionable, { - path: _path + ".dollar", - expected: "string & Dollar", - value: input.dollar, - }))) || - $guard(_exceptionable, { +import typia from "typia"; +export const assertSomething = (() => { + const $guard = typia.createAssert.guard; + const $io0 = (input) => + "string" === typeof input.dollar && + input.dollar[0] === "$" && + !isNaN(Number(input.dollar.substring(1).split(",").join(""))) && + "string" === typeof input.postfix && + input.postfix.endsWith("!!!") && + "number" === typeof input.isEven && + input.isEven % 2 === 0; + const $ao0 = (input, _path, _exceptionable = true) => + (("string" === typeof input.dollar && + ((input.dollar[0] === "$" && + !isNaN(Number(input.dollar.substring(1).split(",").join("")))) || + $guard( + _exceptionable, + { path: _path + ".dollar", - expected: "(string & Dollar)", + expected: "string & Dollar", value: input.dollar, - })) && - (("string" === typeof input.postfix && - (input.postfix.endsWith("!!!") || - $guard(_exceptionable, { - path: _path + ".postfix", - expected: 'string & Postfix<"!!!">', - value: input.postfix, - }))) || - $guard(_exceptionable, { + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".dollar", + expected: "(string & Dollar)", + value: input.dollar, + }, + _errorFactory, + )) && + (("string" === typeof input.postfix && + (input.postfix.endsWith("!!!") || + $guard( + _exceptionable, + { path: _path + ".postfix", - expected: '(string & Postfix<"!!!">)', + expected: 'string & Postfix<"!!!">', value: input.postfix, - })) && - (("number" === typeof input.isEven && - (input.isEven % 2 === 0 || - $guard(_exceptionable, { - path: _path + ".isEven", - expected: "number & IsEven", - value: input.isEven, - }))) || - $guard(_exceptionable, { + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".postfix", + expected: '(string & Postfix<"!!!">)', + value: input.postfix, + }, + _errorFactory, + )) && + (("number" === typeof input.isEven && + (input.isEven % 2 === 0 || + $guard( + _exceptionable, + { path: _path + ".isEven", - expected: "(number & IsEven)", + expected: "number & IsEven", value: input.isEven, - })); - return ( + }, + _errorFactory, + ))) || + $guard( + _exceptionable, + { + path: _path + ".isEven", + expected: "(number & IsEven)", + value: input.isEven, + }, + _errorFactory, + )); + const __is = (input) => + "object" === typeof input && null !== input && $io0(input); + let _errorFactory; + return (input, errorFactory) => { + if (false === __is(input)) { + _errorFactory = errorFactory; + ((input, _path, _exceptionable = true) => ((("object" === typeof input && null !== input) || - $guard(true, { + $guard( + true, + { + path: _path + "", + expected: "Something", + value: input, + }, + _errorFactory, + )) && + $ao0(input, _path + "", true)) || + $guard( + true, + { path: _path + "", expected: "Something", value: input, - })) && - $ao0(input, _path + "", true)) || - $guard(true, { - path: _path + "", - expected: "Something", - value: input, - }) - ); - })(input, "$input", true); - return input; -}; -exports.assertSomething = assertSomething; + }, + _errorFactory, + ))(input, "$input", true); + } + return input; + }; +})(); ``` @@ -841,7 +949,7 @@ Comparing `typia.assert()` function with other competitive libraries, maximum Furthermore, only `typia` can validate complicate union types. -![Assert Function Benchmark](https://github.com/samchon/typia/raw/master/benchmark/results/11th%20Gen%20Intel(R)%20Core(TM)%20i5-1135G7%20%40%202.40GHz/images/assert.svg) +![Assert Function Benchmark](https://github.com/samchon/typia/raw/master/benchmark/results/AMD%20Ryzen%209%207940HS%20w%20Radeon%20780M%20Graphics/images/assert.svg) > Measured on [AMD Ryzen 9 7940HS, Rog Flow x13](https://github.com/samchon/typia/tree/master/benchmark/results/AMD%20Ryzen%209%207940HS%20w%20Radeon%20780M%20Graphics#assert) diff --git a/website/pages/docs/validators/functional.mdx b/website/pages/docs/validators/functional.mdx index 18c0582e29..d5f8345dce 100644 --- a/website/pages/docs/validators/functional.mdx +++ b/website/pages/docs/validators/functional.mdx @@ -59,34 +59,26 @@ func(4, 5); ```javascript filename="examples/bin/assertFunction.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); -const func = (x, y) => { - const errorFactoryWrapper = - typia_1.default.functional.assertFunction.errorFactory; - (( - input, - errorFactory = (p) => - errorFactoryWrapper({ - ...p, - path: p.path - ? p.path.replace("$input", "$input.parameters[0]") - : undefined, - }), - ) => { - const __is = (input) => { - return "number" === typeof input; - }; - if (false === __is(input)) - ((input, _path, _exceptionable = true) => { - const $guard = typia_1.default.functional.assertFunction.guard; - return ( +import typia from "typia"; +const func = (() => { + const errorFactoryWrapper = typia.functional.assertFunction.errorFactory; + const __assert_param_0 = (() => { + const $guard = typia.functional.assertFunction.guard; + const __is = (input) => "number" === typeof input; + let _errorFactory; + return ( + input, + errorFactory = (p) => + errorFactoryWrapper({ + ...p, + path: p.path + ? p.path.replace("$input", "$input.parameters[0]") + : undefined, + }), + ) => { + if (false === __is(input)) { + _errorFactory = errorFactory; + ((input, _path, _exceptionable = true) => "number" === typeof input || $guard( true, @@ -95,29 +87,29 @@ const func = (x, y) => { expected: "number", value: input, }, - errorFactory, - ) - ); - })(input, "$input", true); - return input; - })(x); - (( - input, - errorFactory = (p) => - errorFactoryWrapper({ - ...p, - path: p.path - ? p.path.replace("$input", "$input.parameters[1]") - : undefined, - }), - ) => { - const __is = (input) => { - return "number" === typeof input; + _errorFactory, + ))(input, "$input", true); + } + return input; }; - if (false === __is(input)) - ((input, _path, _exceptionable = true) => { - const $guard = typia_1.default.functional.assertFunction.guard; - return ( + })(); + const __assert_param_1 = (() => { + const $guard = typia.functional.assertFunction.guard; + const __is = (input) => "number" === typeof input; + let _errorFactory; + return ( + input, + errorFactory = (p) => + errorFactoryWrapper({ + ...p, + path: p.path + ? p.path.replace("$input", "$input.parameters[1]") + : undefined, + }), + ) => { + if (false === __is(input)) { + _errorFactory = errorFactory; + ((input, _path, _exceptionable = true) => "number" === typeof input || $guard( true, @@ -126,27 +118,27 @@ const func = (x, y) => { expected: "number", value: input, }, - errorFactory, - ) - ); - })(input, "$input", true); - return input; - })(y); - return (( - input, - errorFactory = (p) => - errorFactoryWrapper({ - ...p, - path: p.path ? p.path.replace("$input", "$input.return") : undefined, - }), - ) => { - const __is = (input) => { - return "number" === typeof input; + _errorFactory, + ))(input, "$input", true); + } + return input; }; - if (false === __is(input)) - ((input, _path, _exceptionable = true) => { - const $guard = typia_1.default.functional.assertFunction.guard; - return ( + })(); + const __assert_return = (() => { + const $guard = typia.functional.assertFunction.guard; + const __is = (input) => "number" === typeof input; + let _errorFactory; + return ( + input, + errorFactory = (p) => + errorFactoryWrapper({ + ...p, + path: p.path ? p.path.replace("$input", "$input.return") : undefined, + }), + ) => { + if (false === __is(input)) { + _errorFactory = errorFactory; + ((input, _path, _exceptionable = true) => "number" === typeof input || $guard( true, @@ -155,13 +147,18 @@ const func = (x, y) => { expected: "number", value: input, }, - errorFactory, - ) - ); - })(input, "$input", true); - return input; - })(((x, y) => x + y)(x, y)); -}; + _errorFactory, + ))(input, "$input", true); + } + return input; + }; + })(); + return (x, y) => { + __assert_param_0(x); + __assert_param_1(y); + return __assert_return(((x, y) => x + y)(x, y)); + }; +})(); func(3, 4); func(4, 5); ``` @@ -212,36 +209,24 @@ func(4, 5); ```javascript filename="examples/bin/isFunction.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; +import typia from "typia"; +const func = (() => { + const __is_param_0 = (() => { + return (input) => "number" === typeof input; + })(); + const __is_param_1 = (() => { + return (input) => "number" === typeof input; + })(); + const __is_return = (() => { + return (input) => "number" === typeof input; + })(); + return (x, y) => { + if (false === __is_param_0(x)) return null; + if (false === __is_param_1(y)) return null; + const result = ((x, y) => x + y)(x, y); + return __is_return(result) ? result : null; }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); -const func = (x, y) => { - if ( - false === - ((input) => { - return "number" === typeof input; - })(x) - ) - return null; - if ( - false === - ((input) => { - return "number" === typeof input; - })(y) - ) - return null; - const result = ((x, y) => x + y)(x, y); - return ((input) => { - return "number" === typeof input; - })(result) - ? result - : null; -}; +})(); func(3, 4); func(4, 5); ``` @@ -275,114 +260,123 @@ func(4, 5); ```javascript filename="examples/bin/validateFunction.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); -const func = (x, y) => { - const paramResults = [ - ((input) => { - const errors = []; - const __is = (input) => { - return "number" === typeof input; - }; +import typia from "typia"; +const func = (() => { + const __validate_param_0 = (() => { + const __is = (input) => "number" === typeof input; + let errors; + let $report; + return (input) => { if (false === __is(input)) { - const $report = - typia_1.default.functional.validateFunction.report(errors); - ((input, _path, _exceptionable = true) => { - return ( - "number" === typeof input || - $report(true, { - path: _path + "", - expected: "number", - value: input, - }) - ); - })(input, "$input", true); + errors = []; + $report = typia.functional.validateFunction.report(errors); + ((input, _path, _exceptionable = true) => + "number" === typeof input || + $report(true, { + path: _path + "", + expected: "number", + value: input, + }))(input, "$input", true); + const success = 0 === errors.length; + return { + success, + errors, + data: success ? input : undefined, + }; } - const success = 0 === errors.length; return { - success, - errors, - data: success ? input : undefined, - }; - })(x), - ((input) => { - const errors = []; - const __is = (input) => { - return "number" === typeof input; + success: true, + errors: [], + data: input, }; + }; + })(); + const __validate_param_1 = (() => { + const __is = (input) => "number" === typeof input; + let errors; + let $report; + return (input) => { if (false === __is(input)) { - const $report = - typia_1.default.functional.validateFunction.report(errors); - ((input, _path, _exceptionable = true) => { - return ( - "number" === typeof input || - $report(true, { - path: _path + "", - expected: "number", - value: input, - }) - ); - })(input, "$input", true); + errors = []; + $report = typia.functional.validateFunction.report(errors); + ((input, _path, _exceptionable = true) => + "number" === typeof input || + $report(true, { + path: _path + "", + expected: "number", + value: input, + }))(input, "$input", true); + const success = 0 === errors.length; + return { + success, + errors, + data: success ? input : undefined, + }; } - const success = 0 === errors.length; return { - success, - errors, - data: success ? input : undefined, + success: true, + errors: [], + data: input, }; - })(y), - ].filter((r) => false === r.success); - if (paramResults.length > 0) - return { - success: false, - errors: paramResults - .map((r, i) => - r.errors.map((error) => ({ - ...error, - path: error.path.replace("$input", `$input.parameters[${i}]`), - })), - ) - .flat(), - }; - const result = ((input) => { - const errors = []; - const __is = (input) => { - return "number" === typeof input; }; - if (false === __is(input)) { - const $report = - typia_1.default.functional.validateFunction.report(errors); - ((input, _path, _exceptionable = true) => { - return ( + })(); + const __validate_return = (() => { + const __is = (input) => "number" === typeof input; + let errors; + let $report; + return (input) => { + if (false === __is(input)) { + errors = []; + $report = typia.functional.validateFunction.report(errors); + ((input, _path, _exceptionable = true) => "number" === typeof input || $report(true, { path: _path + "", expected: "number", value: input, - }) - ); - })(input, "$input", true); - } - const success = 0 === errors.length; - return { - success, - errors, - data: success ? input : undefined, + }))(input, "$input", true); + const success = 0 === errors.length; + return { + success, + errors, + data: success ? input : undefined, + }; + } + return { + success: true, + errors: [], + data: input, + }; }; - })(((x, y) => x + y)(x, y)); - if (!result.success) - result.errors = result.errors.map((error) => ({ - ...error, - path: error.path.replace("$input", "$input.return"), - })); - return result; -}; + })(); + return (x, y) => { + const paramErrorResults = [__validate_param_0(x), __validate_param_1(y)] + .map((r, i) => + true === r.success + ? r + : { + ...r, + errors: r.errors.map((error) => ({ + ...error, + path: error.path.replace("$input", `$input.parameters[${i}]`), + })), + }, + ) + .filter((r) => false === r.success); + if (0 !== paramErrorResults.length) + return { + success: false, + errors: paramErrorResults.map((r) => r.errors).flat(), + }; + const result = __validate_return(((x, y) => x + y)(x, y)); + if (false === result.success) + result.errors = result.errors.map((error) => ({ + ...error, + path: error.path.replace("$input", "$input.return"), + })); + return result; + }; +})(); func(3, 4); func(4, 5); ``` diff --git a/website/pages/docs/validators/is.mdx b/website/pages/docs/validators/is.mdx index e91fa5fa21..926f052b4d 100644 --- a/website/pages/docs/validators/is.mdx +++ b/website/pages/docs/validators/is.mdx @@ -55,19 +55,10 @@ interface IMember { ```javascript filename="examples/bin/is.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); -const uuid_1 = require("uuid"); -const matched = ((input) => { - return ( - "object" === typeof input && - null !== input && +import typia from "typia"; +import { v4 } from "uuid"; +const matched = (() => { + const $io0 = (input) => "string" === typeof input.id && /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( input.id, @@ -81,10 +72,10 @@ const matched = ((input) => { 0 <= input.age && input.age <= 4294967295 && 19 < input.age && - input.age <= 100 - ); -})({ - id: (0, uuid_1.v4)(), + input.age <= 100; + return (input) => "object" === typeof input && null !== input && $io0(input); +})()({ + id: v4(), email: "samchon.github@gmai19l.com", age: 30, }); @@ -137,25 +128,16 @@ interface IMember { ```javascript filename="examples/bin/equals.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); -const uuid_1 = require("uuid"); +import typia from "typia"; +import { v4 } from "uuid"; const input = { - id: (0, uuid_1.v4)(), + id: v4(), email: "samchon.github@gmail.com", age: 30, extra: "superfluous property", // extra }; -const is = ((input) => { - return ( - "object" === typeof input && - null !== input && +const is = (() => { + const $io0 = (input) => "string" === typeof input.id && /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( input.id, @@ -169,10 +151,10 @@ const is = ((input) => { 0 <= input.age && input.age <= 4294967295 && 19 < input.age && - input.age <= 100 - ); -})(input); -const equals = ((input, _exceptionable = true) => { + input.age <= 100; + return (input) => "object" === typeof input && null !== input && $io0(input); +})()(input); +const equals = (() => { const $io0 = (input, _exceptionable = true) => "string" === typeof input.id && /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( @@ -195,8 +177,9 @@ const equals = ((input, _exceptionable = true) => { if (undefined === value) return true; return false; })); - return "object" === typeof input && null !== input && $io0(input, true); -})(input); + return (input, _exceptionable = true) => + "object" === typeof input && null !== input && $io0(input, true); +})()(input); console.log(is, equals); // true, false ``` @@ -236,19 +219,9 @@ interface IMember { ```javascript filename="examples/bin/createIs.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.check = void 0; -const typia_1 = __importDefault(require("typia")); -const check = (input) => { - return ( - "object" === typeof input && - null !== input && +import typia from "typia"; +export const check = (() => { + const $io0 = (input) => "string" === typeof input.id && /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( input.id, @@ -262,10 +235,9 @@ const check = (input) => { 0 <= input.age && input.age <= 4294967295 && 19 < input.age && - input.age <= 100 - ); -}; -exports.check = check; + input.age <= 100; + return (input) => "object" === typeof input && null !== input && $io0(input); +})(); ``` @@ -335,16 +307,9 @@ typia.createIs>(); ```javascript filename="examples/bin/is-map.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); -(input) => { - return ( +import typia from "typia"; +(() => { + return (input) => input instanceof Map && (() => [...input].every( @@ -355,9 +320,8 @@ const typia_1 = __importDefault(require("typia")); ("string" === typeof elem[1] || "number" === typeof elem[1] || "boolean" === typeof elem[1]), - ))() - ); -}; + ))(); +})(); ``` @@ -425,29 +389,18 @@ interface Something { ```javascript filename="examples/bin/is-comment-tags.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.checkSomething = void 0; -const typia_1 = __importDefault(require("typia")); -const checkSomething = (input) => { - return ( - "object" === typeof input && - null !== input && +import typia from "typia"; +export const checkSomething = (() => { + const $io0 = (input) => "string" === typeof input.dollar && input.dollar[0] === "$" && !isNaN(Number(input.dollar.substring(1).split(",").join(""))) && "string" === typeof input.postfix && input.postfix.endsWith("!!!") && "number" === typeof input.isEven && - input.isEven % 2 === 0 - ); -}; -exports.checkSomething = checkSomething; + input.isEven % 2 === 0; + return (input) => "object" === typeof input && null !== input && $io0(input); +})(); ``` @@ -462,7 +415,7 @@ Comparing `typia.is()` function with other competitive libraries, maximum 20, Furthermore, only `typia` can validate complicate union types. -![Is Function Benchmark](https://github.com/samchon/typia/raw/master/benchmark/results/11th%20Gen%20Intel(R)%20Core(TM)%20i5-1135G7%20%40%202.40GHz/images/is.svg) +![Is Function Benchmark](https://github.com/samchon/typia/raw/master/benchmark/results/AMD%20Ryzen%209%207940HS%20w%20Radeon%20780M%20Graphics/images/is.svg) > Measured on [AMD Ryzen 9 7940HS, Rog Flow x13](https://github.com/samchon/typia/tree/master/benchmark/results/AMD%20Ryzen%209%207940HS%20w%20Radeon%20780M%20Graphics#is) diff --git a/website/pages/docs/validators/tags.mdx b/website/pages/docs/validators/tags.mdx index 670c52d366..94c870eb94 100644 --- a/website/pages/docs/validators/tags.mdx +++ b/website/pages/docs/validators/tags.mdx @@ -66,17 +66,8 @@ interface CustomTag { ```javascript filename="is.tag.js" showLineNumbers ------------------------------------------------------------ */ -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.checkCustomTag = void 0; -const typia_1 = __importDefault(require("typia")); -const checkCustomTag = (input) => { +import typia from "typia"; +export const checkCustomTag = (() => { const $io0 = (input) => "number" === typeof input.type && Math.floor(input.type) === input.type && @@ -128,9 +119,8 @@ const checkCustomTag = (input) => { ), ), ))(); - return "object" === typeof input && null !== input && $io0(input); -}; -exports.checkCustomTag = checkCustomTag; + return (input) => "object" === typeof input && null !== input && $io0(input); +})(); ``` @@ -250,16 +240,8 @@ interface CustomTag { ```javascript filename="is.tag.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.checkCustomTag = void 0; -const typia_1 = __importDefault(require("typia")); -const checkCustomTag = (input) => { +import typia from "typia"; +export const checkCustomTag = (() => { const $io0 = (input) => "number" === typeof input.type && Math.floor(input.type) === input.type && @@ -311,9 +293,8 @@ const checkCustomTag = (input) => { ), ), ))(); - return "object" === typeof input && null !== input && $io0(input); -}; -exports.checkCustomTag = checkCustomTag; + return (input) => "object" === typeof input && null !== input && $io0(input); +})(); ``` @@ -451,16 +432,8 @@ interface CustomTag { ```javascript filename="is.tag.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.checkCustomTag = void 0; -const typia_1 = __importDefault(require("typia")); -const checkCustomTag = (input) => { +import typia from "typia"; +export const checkCustomTag = (() => { const $io0 = (input) => "number" === typeof input.type && Math.floor(input.type) === input.type && @@ -473,9 +446,8 @@ const checkCustomTag = (input) => { "string" === typeof input.string && 3 <= input.string.length && "string" === typeof input.pattern; - return "object" === typeof input && null !== input && $io0(input); -}; -exports.checkCustomTag = checkCustomTag; + return (input) => "object" === typeof input && null !== input && $io0(input); +})(); ``` diff --git a/website/pages/docs/validators/validate.mdx b/website/pages/docs/validators/validate.mdx index fef057bd0c..6e747e26c8 100644 --- a/website/pages/docs/validators/validate.mdx +++ b/website/pages/docs/validators/validate.mdx @@ -90,98 +90,90 @@ interface IMember { ```javascript filename="examples/bin/validate.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); -const res = ((input) => { - const errors = []; - const __is = (input) => { - return ( - "object" === typeof input && - null !== input && - "string" === typeof input.id && - /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input.id, - ) && - "string" === typeof input.email && - /^[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.test( - input.email, - ) && - "number" === typeof input.age && - Math.floor(input.age) === input.age && - 0 <= input.age && - input.age <= 4294967295 && - 19 < input.age && - input.age <= 100 - ); - }; - if (false === __is(input)) { - const $report = typia_1.default.validate.report(errors); - ((input, _path, _exceptionable = true) => { - const $vo0 = (input, _path, _exceptionable = true) => - [ - ("string" === typeof input.id && - (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input.id, - ) || - $report(_exceptionable, { - path: _path + ".id", - expected: 'string & Format<"uuid">', - value: input.id, - }))) || - $report(_exceptionable, { - path: _path + ".id", - expected: '(string & Format<"uuid">)', - value: input.id, - }), - ("string" === typeof input.email && - (/^[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.test( - input.email, - ) || - $report(_exceptionable, { - path: _path + ".email", - expected: 'string & Format<"email">', - value: input.email, - }))) || - $report(_exceptionable, { - path: _path + ".email", - expected: '(string & Format<"email">)', - value: input.email, - }), - ("number" === typeof input.age && - ((Math.floor(input.age) === input.age && - 0 <= input.age && - input.age <= 4294967295) || - $report(_exceptionable, { - path: _path + ".age", - expected: 'number & Type<"uint32">', - value: input.age, - })) && - (19 < input.age || - $report(_exceptionable, { - path: _path + ".age", - expected: "number & ExclusiveMinimum<19>", - value: input.age, - })) && - (input.age <= 100 || - $report(_exceptionable, { - path: _path + ".age", - expected: "number & Maximum<100>", - value: input.age, - }))) || - $report(_exceptionable, { - path: _path + ".age", - expected: - '(number & Type<"uint32"> & ExclusiveMinimum<19> & Maximum<100>)', - value: input.age, - }), - ].every((flag) => flag); - return ( +import typia from "typia"; +const res = (() => { + const $io0 = (input) => + "string" === typeof input.id && + /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input.id, + ) && + "string" === typeof input.email && + /^[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.test( + input.email, + ) && + "number" === typeof input.age && + Math.floor(input.age) === input.age && + 0 <= input.age && + input.age <= 4294967295 && + 19 < input.age && + input.age <= 100; + const $vo0 = (input, _path, _exceptionable = true) => + [ + ("string" === typeof input.id && + (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input.id, + ) || + $report(_exceptionable, { + path: _path + ".id", + expected: 'string & Format<"uuid">', + value: input.id, + }))) || + $report(_exceptionable, { + path: _path + ".id", + expected: '(string & Format<"uuid">)', + value: input.id, + }), + ("string" === typeof input.email && + (/^[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.test( + input.email, + ) || + $report(_exceptionable, { + path: _path + ".email", + expected: 'string & Format<"email">', + value: input.email, + }))) || + $report(_exceptionable, { + path: _path + ".email", + expected: '(string & Format<"email">)', + value: input.email, + }), + ("number" === typeof input.age && + ((Math.floor(input.age) === input.age && + 0 <= input.age && + input.age <= 4294967295) || + $report(_exceptionable, { + path: _path + ".age", + expected: 'number & Type<"uint32">', + value: input.age, + })) && + (19 < input.age || + $report(_exceptionable, { + path: _path + ".age", + expected: "number & ExclusiveMinimum<19>", + value: input.age, + })) && + (input.age <= 100 || + $report(_exceptionable, { + path: _path + ".age", + expected: "number & Maximum<100>", + value: input.age, + }))) || + $report(_exceptionable, { + path: _path + ".age", + expected: + '(number & Type<"uint32"> & ExclusiveMinimum<19> & Maximum<100>)', + value: input.age, + }), + ].every((flag) => flag); + const __is = (input) => + "object" === typeof input && null !== input && $io0(input); + let errors; + let $report; + return (input) => { + if (false === __is(input)) { + errors = []; + $report = typia.validate.report(errors); + ((input, _path, _exceptionable = true) => ((("object" === typeof input && null !== input) || $report(true, { path: _path + "", @@ -193,17 +185,21 @@ const res = ((input) => { path: _path + "", expected: "IMember", value: input, - }) - ); - })(input, "$input", true); - } - const success = 0 === errors.length; - return { - success, - errors, - data: success ? input : undefined, + }))(input, "$input", true); + const success = 0 === errors.length; + return { + success, + errors, + data: success ? input : undefined, + }; + } + return { + success: true, + errors: [], + data: input, + }; }; -})({ +})()({ id: 5, // wrong, must be string (uuid) age: 20.75, // wrong, not integer email: "samchon.github@gmail.com", @@ -290,119 +286,113 @@ interface IMember { ```javascript filename="examples/bin/validateEquals.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); -const res = ((input) => { - const errors = []; - const __is = (input, _exceptionable = true) => { - const $io0 = (input, _exceptionable = true) => - "string" === typeof input.id && - /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input.id, - ) && - "string" === typeof input.email && - /^[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.test( - input.email, - ) && - "number" === typeof input.age && - Math.floor(input.age) === input.age && - 0 <= input.age && - input.age <= 4294967295 && - 19 < input.age && - input.age <= 100 && - (3 === Object.keys(input).length || - Object.keys(input).every((key) => { - if (["id", "email", "age"].some((prop) => key === prop)) return true; - const value = input[key]; - if (undefined === value) return true; - return false; - })); - return "object" === typeof input && null !== input && $io0(input, true); - }; - if (false === __is(input)) { - const $report = typia_1.default.validateEquals.report(errors); - ((input, _path, _exceptionable = true) => { - const $join = typia_1.default.validateEquals.join; - const $vo0 = (input, _path, _exceptionable = true) => - [ - ("string" === typeof input.id && - (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input.id, - ) || - $report(_exceptionable, { - path: _path + ".id", - expected: 'string & Format<"uuid">', - value: input.id, - }))) || - $report(_exceptionable, { - path: _path + ".id", - expected: '(string & Format<"uuid">)', - value: input.id, - }), - ("string" === typeof input.email && - (/^[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.test( - input.email, - ) || - $report(_exceptionable, { - path: _path + ".email", - expected: 'string & Format<"email">', - value: input.email, - }))) || - $report(_exceptionable, { - path: _path + ".email", - expected: '(string & Format<"email">)', - value: input.email, - }), - ("number" === typeof input.age && - ((Math.floor(input.age) === input.age && - 0 <= input.age && - input.age <= 4294967295) || - $report(_exceptionable, { - path: _path + ".age", - expected: 'number & Type<"uint32">', - value: input.age, - })) && - (19 < input.age || - $report(_exceptionable, { - path: _path + ".age", - expected: "number & ExclusiveMinimum<19>", - value: input.age, - })) && - (input.age <= 100 || - $report(_exceptionable, { - path: _path + ".age", - expected: "number & Maximum<100>", - value: input.age, - }))) || - $report(_exceptionable, { - path: _path + ".age", - expected: - '(number & Type<"uint32"> & ExclusiveMinimum<19> & Maximum<100>)', - value: input.age, - }), - 3 === Object.keys(input).length || - false === _exceptionable || - Object.keys(input) - .map((key) => { - if (["id", "email", "age"].some((prop) => key === prop)) - return true; - const value = input[key]; - if (undefined === value) return true; - return $report(_exceptionable, { - path: _path + $join(key), - expected: "undefined", - value: value, - }); - }) - .every((flag) => flag), - ].every((flag) => flag); - return ( +import typia from "typia"; +const res = (() => { + const $join = typia.validateEquals.join; + const $io0 = (input, _exceptionable = true) => + "string" === typeof input.id && + /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input.id, + ) && + "string" === typeof input.email && + /^[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.test( + input.email, + ) && + "number" === typeof input.age && + Math.floor(input.age) === input.age && + 0 <= input.age && + input.age <= 4294967295 && + 19 < input.age && + input.age <= 100 && + (3 === Object.keys(input).length || + Object.keys(input).every((key) => { + if (["id", "email", "age"].some((prop) => key === prop)) return true; + const value = input[key]; + if (undefined === value) return true; + return false; + })); + const $vo0 = (input, _path, _exceptionable = true) => + [ + ("string" === typeof input.id && + (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input.id, + ) || + $report(_exceptionable, { + path: _path + ".id", + expected: 'string & Format<"uuid">', + value: input.id, + }))) || + $report(_exceptionable, { + path: _path + ".id", + expected: '(string & Format<"uuid">)', + value: input.id, + }), + ("string" === typeof input.email && + (/^[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.test( + input.email, + ) || + $report(_exceptionable, { + path: _path + ".email", + expected: 'string & Format<"email">', + value: input.email, + }))) || + $report(_exceptionable, { + path: _path + ".email", + expected: '(string & Format<"email">)', + value: input.email, + }), + ("number" === typeof input.age && + ((Math.floor(input.age) === input.age && + 0 <= input.age && + input.age <= 4294967295) || + $report(_exceptionable, { + path: _path + ".age", + expected: 'number & Type<"uint32">', + value: input.age, + })) && + (19 < input.age || + $report(_exceptionable, { + path: _path + ".age", + expected: "number & ExclusiveMinimum<19>", + value: input.age, + })) && + (input.age <= 100 || + $report(_exceptionable, { + path: _path + ".age", + expected: "number & Maximum<100>", + value: input.age, + }))) || + $report(_exceptionable, { + path: _path + ".age", + expected: + '(number & Type<"uint32"> & ExclusiveMinimum<19> & Maximum<100>)', + value: input.age, + }), + 3 === Object.keys(input).length || + false === _exceptionable || + Object.keys(input) + .map((key) => { + if (["id", "email", "age"].some((prop) => key === prop)) + return true; + const value = input[key]; + if (undefined === value) return true; + return $report(_exceptionable, { + path: _path + $join(key), + expected: "undefined", + value: value, + }); + }) + .every((flag) => flag), + ].every((flag) => flag); + const __is = (input, _exceptionable = true) => + "object" === typeof input && null !== input && $io0(input, true); + let errors; + let $report; + return (input) => { + if (false === __is(input)) { + errors = []; + $report = typia.validateEquals.report(errors); + ((input, _path, _exceptionable = true) => ((("object" === typeof input && null !== input) || $report(true, { path: _path + "", @@ -414,17 +404,21 @@ const res = ((input) => { path: _path + "", expected: "IMember", value: input, - }) - ); - })(input, "$input", true); - } - const success = 0 === errors.length; - return { - success, - errors, - data: success ? input : undefined, + }))(input, "$input", true); + const success = 0 === errors.length; + return { + success, + errors, + data: success ? input : undefined, + }; + } + return { + success: true, + errors: [], + data: input, + }; }; -})({ +})()({ age: 30, email: "samchon.github@gmail.com", id: "something", // wrong, must be string (uuid) @@ -496,99 +490,90 @@ interface IMember { ```javascript filename="examples/bin/createValidate.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.validateMember = void 0; -const typia_1 = __importDefault(require("typia")); -const validateMember = (input) => { - const errors = []; - const __is = (input) => { - return ( - "object" === typeof input && - null !== input && - "string" === typeof input.id && - /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input.id, - ) && - "string" === typeof input.email && - /^[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.test( - input.email, - ) && - "number" === typeof input.age && - Math.floor(input.age) === input.age && - 0 <= input.age && - input.age <= 4294967295 && - 19 < input.age && - input.age <= 100 - ); - }; - if (false === __is(input)) { - const $report = typia_1.default.createValidate.report(errors); - ((input, _path, _exceptionable = true) => { - const $vo0 = (input, _path, _exceptionable = true) => - [ - ("string" === typeof input.id && - (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( - input.id, - ) || - $report(_exceptionable, { - path: _path + ".id", - expected: 'string & Format<"uuid">', - value: input.id, - }))) || - $report(_exceptionable, { - path: _path + ".id", - expected: '(string & Format<"uuid">)', - value: input.id, - }), - ("string" === typeof input.email && - (/^[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.test( - input.email, - ) || - $report(_exceptionable, { - path: _path + ".email", - expected: 'string & Format<"email">', - value: input.email, - }))) || - $report(_exceptionable, { - path: _path + ".email", - expected: '(string & Format<"email">)', - value: input.email, - }), - ("number" === typeof input.age && - ((Math.floor(input.age) === input.age && - 0 <= input.age && - input.age <= 4294967295) || - $report(_exceptionable, { - path: _path + ".age", - expected: 'number & Type<"uint32">', - value: input.age, - })) && - (19 < input.age || - $report(_exceptionable, { - path: _path + ".age", - expected: "number & ExclusiveMinimum<19>", - value: input.age, - })) && - (input.age <= 100 || - $report(_exceptionable, { - path: _path + ".age", - expected: "number & Maximum<100>", - value: input.age, - }))) || - $report(_exceptionable, { - path: _path + ".age", - expected: - '(number & Type<"uint32"> & ExclusiveMinimum<19> & Maximum<100>)', - value: input.age, - }), - ].every((flag) => flag); - return ( +import typia from "typia"; +export const validateMember = (() => { + const $io0 = (input) => + "string" === typeof input.id && + /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input.id, + ) && + "string" === typeof input.email && + /^[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.test( + input.email, + ) && + "number" === typeof input.age && + Math.floor(input.age) === input.age && + 0 <= input.age && + input.age <= 4294967295 && + 19 < input.age && + input.age <= 100; + const $vo0 = (input, _path, _exceptionable = true) => + [ + ("string" === typeof input.id && + (/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test( + input.id, + ) || + $report(_exceptionable, { + path: _path + ".id", + expected: 'string & Format<"uuid">', + value: input.id, + }))) || + $report(_exceptionable, { + path: _path + ".id", + expected: '(string & Format<"uuid">)', + value: input.id, + }), + ("string" === typeof input.email && + (/^[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.test( + input.email, + ) || + $report(_exceptionable, { + path: _path + ".email", + expected: 'string & Format<"email">', + value: input.email, + }))) || + $report(_exceptionable, { + path: _path + ".email", + expected: '(string & Format<"email">)', + value: input.email, + }), + ("number" === typeof input.age && + ((Math.floor(input.age) === input.age && + 0 <= input.age && + input.age <= 4294967295) || + $report(_exceptionable, { + path: _path + ".age", + expected: 'number & Type<"uint32">', + value: input.age, + })) && + (19 < input.age || + $report(_exceptionable, { + path: _path + ".age", + expected: "number & ExclusiveMinimum<19>", + value: input.age, + })) && + (input.age <= 100 || + $report(_exceptionable, { + path: _path + ".age", + expected: "number & Maximum<100>", + value: input.age, + }))) || + $report(_exceptionable, { + path: _path + ".age", + expected: + '(number & Type<"uint32"> & ExclusiveMinimum<19> & Maximum<100>)', + value: input.age, + }), + ].every((flag) => flag); + const __is = (input) => + "object" === typeof input && null !== input && $io0(input); + let errors; + let $report; + return (input) => { + if (false === __is(input)) { + errors = []; + $report = typia.createValidate.report(errors); + ((input, _path, _exceptionable = true) => ((("object" === typeof input && null !== input) || $report(true, { path: _path + "", @@ -600,18 +585,21 @@ const validateMember = (input) => { path: _path + "", expected: "IMember", value: input, - }) - ); - })(input, "$input", true); - } - const success = 0 === errors.length; - return { - success, - errors, - data: success ? input : undefined, + }))(input, "$input", true); + const success = 0 === errors.length; + return { + success, + errors, + data: success ? input : undefined, + }; + } + return { + success: true, + errors: [], + data: input, + }; }; -}; -exports.validateMember = validateMember; +})(); ``` @@ -653,16 +641,9 @@ typia.createIs>(); ```javascript filename="examples/bin/is-map.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -const typia_1 = __importDefault(require("typia")); -(input) => { - return ( +import typia from "typia"; +(() => { + return (input) => input instanceof Map && (() => [...input].every( @@ -673,9 +654,8 @@ const typia_1 = __importDefault(require("typia")); ("string" === typeof elem[1] || "number" === typeof elem[1] || "boolean" === typeof elem[1]), - ))() - ); -}; + ))(); +})(); ``` @@ -803,74 +783,65 @@ interface Something { ```javascript filename="examples/bin/validate-custom-tags.js" showLineNumbers -"use strict"; -var __importDefault = - (this && this.__importDefault) || - function (mod) { - return mod && mod.__esModule ? mod : { default: mod }; - }; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.validateSomething = void 0; -const typia_1 = __importDefault(require("typia")); -const validateSomething = (input) => { - const errors = []; - const __is = (input) => { - return ( - "object" === typeof input && - null !== input && - "string" === typeof input.dollar && - input.dollar[0] === "$" && - !isNaN(Number(input.dollar.substring(1).split(",").join(""))) && - "string" === typeof input.postfix && - input.postfix.endsWith("!!!") && - "number" === typeof input.isEven && - input.isEven % 2 === 0 - ); - }; - if (false === __is(input)) { - const $report = typia_1.default.createValidate.report(errors); - ((input, _path, _exceptionable = true) => { - const $vo0 = (input, _path, _exceptionable = true) => - [ - ("string" === typeof input.dollar && - ((input.dollar[0] === "$" && - !isNaN(Number(input.dollar.substring(1).split(",").join("")))) || - $report(_exceptionable, { - path: _path + ".dollar", - expected: "string & Dollar", - value: input.dollar, - }))) || - $report(_exceptionable, { - path: _path + ".dollar", - expected: "(string & Dollar)", - value: input.dollar, - }), - ("string" === typeof input.postfix && - (input.postfix.endsWith("!!!") || - $report(_exceptionable, { - path: _path + ".postfix", - expected: 'string & Postfix<"!!!">', - value: input.postfix, - }))) || - $report(_exceptionable, { - path: _path + ".postfix", - expected: '(string & Postfix<"!!!">)', - value: input.postfix, - }), - ("number" === typeof input.isEven && - (input.isEven % 2 === 0 || - $report(_exceptionable, { - path: _path + ".isEven", - expected: "number & IsEven", - value: input.isEven, - }))) || - $report(_exceptionable, { - path: _path + ".isEven", - expected: "(number & IsEven)", - value: input.isEven, - }), - ].every((flag) => flag); - return ( +import typia from "typia"; +export const validateSomething = (() => { + const $io0 = (input) => + "string" === typeof input.dollar && + input.dollar[0] === "$" && + !isNaN(Number(input.dollar.substring(1).split(",").join(""))) && + "string" === typeof input.postfix && + input.postfix.endsWith("!!!") && + "number" === typeof input.isEven && + input.isEven % 2 === 0; + const $vo0 = (input, _path, _exceptionable = true) => + [ + ("string" === typeof input.dollar && + ((input.dollar[0] === "$" && + !isNaN(Number(input.dollar.substring(1).split(",").join("")))) || + $report(_exceptionable, { + path: _path + ".dollar", + expected: "string & Dollar", + value: input.dollar, + }))) || + $report(_exceptionable, { + path: _path + ".dollar", + expected: "(string & Dollar)", + value: input.dollar, + }), + ("string" === typeof input.postfix && + (input.postfix.endsWith("!!!") || + $report(_exceptionable, { + path: _path + ".postfix", + expected: 'string & Postfix<"!!!">', + value: input.postfix, + }))) || + $report(_exceptionable, { + path: _path + ".postfix", + expected: '(string & Postfix<"!!!">)', + value: input.postfix, + }), + ("number" === typeof input.isEven && + (input.isEven % 2 === 0 || + $report(_exceptionable, { + path: _path + ".isEven", + expected: "number & IsEven", + value: input.isEven, + }))) || + $report(_exceptionable, { + path: _path + ".isEven", + expected: "(number & IsEven)", + value: input.isEven, + }), + ].every((flag) => flag); + const __is = (input) => + "object" === typeof input && null !== input && $io0(input); + let errors; + let $report; + return (input) => { + if (false === __is(input)) { + errors = []; + $report = typia.createValidate.report(errors); + ((input, _path, _exceptionable = true) => ((("object" === typeof input && null !== input) || $report(true, { path: _path + "", @@ -882,18 +853,21 @@ const validateSomething = (input) => { path: _path + "", expected: "Something", value: input, - }) - ); - })(input, "$input", true); - } - const success = 0 === errors.length; - return { - success, - errors, - data: success ? input : undefined, + }))(input, "$input", true); + const success = 0 === errors.length; + return { + success, + errors, + data: success ? input : undefined, + }; + } + return { + success: true, + errors: [], + data: input, + }; }; -}; -exports.validateSomething = validateSomething; +})(); ``` @@ -909,7 +883,7 @@ Comparing `typia.validate()` function with other competitive libraries, maxim Furthermore, only `typia` can validate complicate union types. -![validate Function Benchmark](https://github.com/samchon/typia/raw/master/benchmark/results/11th%20Gen%20Intel(R)%20Core(TM)%20i5-1135G7%20%40%202.40GHz/images/validate.svg) +![validate Function Benchmark](https://github.com/samchon/typia/raw/master/benchmark/results/AMD%20Ryzen%209%207940HS%20w%20Radeon%20780M%20Graphics/images/validate.svg) > Measured on [AMD Ryzen 9 7940HS, Rog Flow x13](https://github.com/samchon/typia/tree/master/benchmark/results/AMD%20Ryzen%209%207940HS%20w%20Radeon%20780M%20Graphics#validate) diff --git a/website/src/compilers/COMPILER_OPTIONS.ts b/website/src/compilers/COMPILER_OPTIONS.ts index 66f891f579..425709350c 100644 --- a/website/src/compilers/COMPILER_OPTIONS.ts +++ b/website/src/compilers/COMPILER_OPTIONS.ts @@ -1,8 +1,8 @@ import ts from "typescript"; export const COMPILER_OPTIONS: ts.CompilerOptions = { - target: ts.ScriptTarget.ES2015, - module: ts.ModuleKind.ES2015, + target: ts.ScriptTarget.ESNext, + module: ts.ModuleKind.ESNext, // lib: ["DOM", "ES2015"], esModuleInterop: true, downlevelIteration: true,