Skip to content

Commit 2e3c796

Browse files
committed
Complement custom type tags' documentations
1 parent 5c2186f commit 2e3c796

File tree

5 files changed

+101
-84
lines changed

5 files changed

+101
-84
lines changed

website/package-lock.json

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"nextra-theme-docs": "latest",
3131
"react": "^18.2.0",
3232
"react-dom": "^18.2.0",
33-
"typescript": "5.1.6"
33+
"typescript": "^5.2.2"
3434
},
3535
"devDependencies": {
3636
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
@@ -41,6 +41,6 @@
4141
"prettier": "^2.8.8",
4242
"rimraf": "^5.0.0",
4343
"ts-node": "^10.9.1",
44-
"typia": "^5.0.4"
44+
"typia": "^5.0.5"
4545
}
4646
}

website/pages/docs/random.mdx

+34-20
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ interface TagCustom {
611611
id: string & typia.tags.Format<"uuid">;
612612
dollar: string & Dolloar;
613613
postfix: string & Postfix<"abcd">;
614+
powerOf: number & PowerOf<2>;
614615
}
615616

616617
type Dolloar = typia.tags.TagBase<{
@@ -626,58 +627,71 @@ type Postfix<Value extends string> = typia.tags.TagBase<{
626627
value: Value;
627628
validate: `$input.endsWith("${Value}")`;
628629
}>;
630+
631+
type PowerOf<Value extends number> = typia.tags.TagBase<{
632+
kind: "powerOf";
633+
target: "number";
634+
value: Value;
635+
validate: `(() => {
636+
const denominator: number = Math.log(${Value});
637+
const value: number = Math.log($input) / denominator;
638+
return Math.abs(value - Math.round(value)) < 0.00000001;
639+
})()`;
640+
}>;
629641
```
630642
</Tab>
631643
<Tab>
632644
```javascript filename="examples/bin/random-customization.js"
633-
import typia from "typia";
634-
import { RandomGenerator } from "typia/lib/utils/RandomGenerator";
635-
645+
"use strict";
646+
var __importDefault = (this && this.__importDefault) || function (mod) {
647+
return (mod && mod.__esModule) ? mod : { "default": mod };
648+
};
649+
Object.defineProperty(exports, "__esModule", { value: true });
650+
const typia_1 = __importDefault(require("typia"));
651+
const RandomGenerator_1 = require("typia/lib/utils/RandomGenerator");
636652
const data = (generator => {
637-
const $generator = typia.random.generator;
653+
const $generator = typia_1.default.random.generator;
638654
const $ro0 = (_recursive = false, _depth = 0) => ({
639655
id: (generator?.customs ?? $generator.customs)?.string?.([
640656
{
641-
name: "format",
657+
name: "Format<\"uuid\">",
658+
kind: "format",
642659
value: "uuid"
643660
}
644661
]) ?? (generator?.uuid ?? $generator.uuid)(),
645662
dollar: (generator?.customs ?? $generator.customs)?.string?.([
646663
{
647-
name: "dollar"
664+
name: "Dolloar",
665+
kind: "dollar"
648666
}
649667
]) ?? (generator?.string ?? $generator.string)(),
650668
postfix: (generator?.customs ?? $generator.customs)?.string?.([
651669
{
652-
name: "postfix",
670+
name: "Postfix<\"abcd\">",
671+
kind: "postfix",
653672
value: "abcd"
654673
}
655674
]) ?? (generator?.string ?? $generator.string)(),
656-
power: (generator?.customs ?? $generator.customs)?.number?.([
675+
powerOf: (generator?.customs ?? $generator.customs)?.number?.([
657676
{
658-
name: "powerOf",
659-
value: "10"
677+
name: "PowerOf<2>",
678+
kind: "powerOf",
679+
value: 2
660680
}
661681
]) ?? (generator?.number ?? $generator.number)(0, 100)
662682
});
663683
return $ro0();
664684
})({
665685
customs: {
666686
string: (tags) => {
667-
if (tags.find((t) => t.name === "dollar") !== undefined)
668-
return "$" + RandomGenerator.integer();
669-
const postfix = tags.find((t) => t.name === "postfix");
687+
if (tags.find((t) => t.kind === "dollar") !== undefined)
688+
return "$" + RandomGenerator_1.RandomGenerator.integer();
689+
const postfix = tags.find((t) => t.kind === "postfix");
670690
if (postfix !== undefined)
671-
return RandomGenerator.string() + postfix.value;
672-
},
673-
number: (tags) => {
674-
const powerOf = tags.find((t) => t.name === "powerOf");
675-
if (powerOf !== undefined)
676-
return Math.pow(Number(powerOf.value), RandomGenerator.integer(1, 4));
691+
return RandomGenerator_1.RandomGenerator.string() + postfix.value;
677692
},
678693
},
679694
});
680-
681695
console.log(data);
682696
```
683697
</Tab>

website/pages/docs/validators/tags.mdx

+37-34
Original file line numberDiff line numberDiff line change
@@ -602,46 +602,41 @@ Here is the example code, and I think that it may easy to understand.
602602
<Tabs items={['TypeScript Source Code', 'Compiled JavaScript File']}>
603603
<Tab>
604604
```typescript showLineNumbers copy filename="is.tag.custom.ts"
605-
import typia, { tags } from "typia";
606-
607-
export const checkSomething = typia.createIs<Something>();
605+
import typia from "typia";
608606

609-
//----
610-
// DEFINE CUSTOM TYPE TAGS
611-
//----
612-
type Dollar = tags.TagBase<{
607+
export const checkTagCustom = typia.createIs<TagCustom>();
608+
609+
interface TagCustom {
610+
id: string & typia.tags.Format<"uuid">;
611+
dollar: string & Dolloar;
612+
postfix: string & Postfix<"abcd">;
613+
powerOf: number & PowerOf<2>;
614+
}
615+
616+
type Dolloar = typia.tags.TagBase<{
613617
kind: "dollar";
614618
target: "string";
615619
value: undefined;
616620
validate: `$input[0] === "$" && !isNaN(Number($input.substring(1).split(",").join("")))`;
617621
}>;
618-
619-
type Postfix<Value extends string> = tags.TagBase<{
622+
623+
type Postfix<Value extends string> = typia.tags.TagBase<{
620624
kind: "postfix";
621625
target: "string";
622626
value: Value;
623627
validate: `$input.endsWith("${Value}")`;
624628
}>;
625-
626-
type IsEven<Value extends number | bigint> = tags.TagBase<{
627-
kind: "isEven";
628-
target: Value extends number ? "number" : "bigint";
629-
value: undefined;
630-
validate: `$input % ${Numeric<2>} === ${Numeric<0>}`;
629+
630+
type PowerOf<Value extends number> = typia.tags.TagBase<{
631+
kind: "powerOf";
632+
target: "number";
633+
value: Value;
634+
validate: `(() => {
635+
const denominator: number = Math.log(${Value});
636+
const value: number = Math.log($input) / denominator;
637+
return Math.abs(value - Math.round(value)) < 0.00000001;
638+
})()`;
631639
}>;
632-
633-
type Numeric<Value extends number | bigint> = Value extends number
634-
? Value
635-
: `BigInt(${Value})`;
636-
637-
//----
638-
// VALIDATION
639-
//----
640-
interface Something {
641-
dollar: string & Dollar;
642-
postfix: string & Postfix<"!!!">;
643-
isEven: number & IsEven<number>;
644-
}
645640
```
646641
</Tab>
647642
<Tab>
@@ -653,22 +648,30 @@ var __importDefault =
653648
return mod && mod.__esModule ? mod : { default: mod };
654649
};
655650
Object.defineProperty(exports, "__esModule", { value: true });
656-
exports.checkSomething = void 0;
651+
exports.checkTagCustom = void 0;
657652
const typia_1 = __importDefault(require("typia"));
658-
const checkSomething = (input) => {
653+
const checkTagCustom = (input) => {
659654
return (
660655
"object" === typeof input &&
661656
null !== input &&
657+
"string" === typeof input.id &&
658+
/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i.test(
659+
input.id,
660+
) &&
662661
"string" === typeof input.dollar &&
663662
input.dollar[0] === "$" &&
664663
!isNaN(Number(input.dollar.substring(1).split(",").join(""))) &&
665664
"string" === typeof input.postfix &&
666-
input.postfix.endsWith("!!!") &&
667-
"number" === typeof input.isEven &&
668-
input.isEven % 2 === 0
665+
input.postfix.endsWith("abcd") &&
666+
"number" === typeof input.powerOf &&
667+
(() => {
668+
const denominator = Math.log(2);
669+
const value = Math.log(input.powerOf) / denominator;
670+
return Math.abs(value - Math.round(value)) < 1e-8;
671+
})()
669672
);
670673
};
671-
exports.checkSomething = checkSomething;
674+
exports.checkTagCustom = checkTagCustom;
672675
```
673676
</Tab>
674677
</Tabs>

website/public/sitemap-0.xml

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
3-
<url><loc>https://typia.io/</loc><lastmod>2023-09-18T16:20:38.485Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
4-
<url><loc>https://typia.io/docs/</loc><lastmod>2023-09-18T16:20:38.486Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
5-
<url><loc>https://typia.io/docs/json/parse/</loc><lastmod>2023-09-18T16:20:38.486Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
6-
<url><loc>https://typia.io/docs/json/schema/</loc><lastmod>2023-09-18T16:20:38.486Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
7-
<url><loc>https://typia.io/docs/json/stringify/</loc><lastmod>2023-09-18T16:20:38.486Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
8-
<url><loc>https://typia.io/docs/misc/</loc><lastmod>2023-09-18T16:20:38.486Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
9-
<url><loc>https://typia.io/docs/protobuf/decode/</loc><lastmod>2023-09-18T16:20:38.486Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
10-
<url><loc>https://typia.io/docs/protobuf/encode/</loc><lastmod>2023-09-18T16:20:38.486Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
11-
<url><loc>https://typia.io/docs/protobuf/message/</loc><lastmod>2023-09-18T16:20:38.486Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
12-
<url><loc>https://typia.io/docs/pure/</loc><lastmod>2023-09-18T16:20:38.486Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
13-
<url><loc>https://typia.io/docs/random/</loc><lastmod>2023-09-18T16:20:38.486Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
14-
<url><loc>https://typia.io/docs/setup/</loc><lastmod>2023-09-18T16:20:38.486Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
15-
<url><loc>https://typia.io/docs/utilization/nestjs/</loc><lastmod>2023-09-18T16:20:38.486Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
16-
<url><loc>https://typia.io/docs/utilization/prisma/</loc><lastmod>2023-09-18T16:20:38.486Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
17-
<url><loc>https://typia.io/docs/utilization/trpc/</loc><lastmod>2023-09-18T16:20:38.486Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
18-
<url><loc>https://typia.io/docs/validators/assert/</loc><lastmod>2023-09-18T16:20:38.486Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
19-
<url><loc>https://typia.io/docs/validators/is/</loc><lastmod>2023-09-18T16:20:38.486Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
20-
<url><loc>https://typia.io/docs/validators/tags/</loc><lastmod>2023-09-18T16:20:38.486Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
21-
<url><loc>https://typia.io/docs/validators/validate/</loc><lastmod>2023-09-18T16:20:38.486Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
22-
<url><loc>https://typia.io/playground/</loc><lastmod>2023-09-18T16:20:38.486Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
3+
<url><loc>https://typia.io/</loc><lastmod>2023-09-22T17:02:54.231Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
4+
<url><loc>https://typia.io/docs/</loc><lastmod>2023-09-22T17:02:54.233Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
5+
<url><loc>https://typia.io/docs/json/parse/</loc><lastmod>2023-09-22T17:02:54.233Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
6+
<url><loc>https://typia.io/docs/json/schema/</loc><lastmod>2023-09-22T17:02:54.233Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
7+
<url><loc>https://typia.io/docs/json/stringify/</loc><lastmod>2023-09-22T17:02:54.233Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
8+
<url><loc>https://typia.io/docs/misc/</loc><lastmod>2023-09-22T17:02:54.233Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
9+
<url><loc>https://typia.io/docs/protobuf/decode/</loc><lastmod>2023-09-22T17:02:54.233Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
10+
<url><loc>https://typia.io/docs/protobuf/encode/</loc><lastmod>2023-09-22T17:02:54.233Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
11+
<url><loc>https://typia.io/docs/protobuf/message/</loc><lastmod>2023-09-22T17:02:54.233Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
12+
<url><loc>https://typia.io/docs/pure/</loc><lastmod>2023-09-22T17:02:54.233Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
13+
<url><loc>https://typia.io/docs/random/</loc><lastmod>2023-09-22T17:02:54.233Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
14+
<url><loc>https://typia.io/docs/setup/</loc><lastmod>2023-09-22T17:02:54.233Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
15+
<url><loc>https://typia.io/docs/utilization/nestjs/</loc><lastmod>2023-09-22T17:02:54.233Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
16+
<url><loc>https://typia.io/docs/utilization/prisma/</loc><lastmod>2023-09-22T17:02:54.233Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
17+
<url><loc>https://typia.io/docs/utilization/trpc/</loc><lastmod>2023-09-22T17:02:54.233Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
18+
<url><loc>https://typia.io/docs/validators/assert/</loc><lastmod>2023-09-22T17:02:54.233Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
19+
<url><loc>https://typia.io/docs/validators/is/</loc><lastmod>2023-09-22T17:02:54.233Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
20+
<url><loc>https://typia.io/docs/validators/tags/</loc><lastmod>2023-09-22T17:02:54.233Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
21+
<url><loc>https://typia.io/docs/validators/validate/</loc><lastmod>2023-09-22T17:02:54.233Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
22+
<url><loc>https://typia.io/playground/</loc><lastmod>2023-09-22T17:02:54.233Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
2323
</urlset>

0 commit comments

Comments
 (0)