typia 3.6.0-dev.20230225 → 3.6.0-dev.20230226
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -39
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,34 +54,55 @@ Thanks for your support.
|
|
|
54
54
|
|
|
55
55
|
Your donation would encourage `typia` development.
|
|
56
56
|
|
|
57
|
-
[)](https://opencollective.com/typia)
|
|
58
58
|
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
## Setup
|
|
63
|
-
###
|
|
63
|
+
### Transformation (stable)
|
|
64
64
|
```bash
|
|
65
65
|
npx typia setup
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
AOT (Ahead of Time) compilation mode.
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
When you write a TypeScript code calling `typia.createIs<string | null>()` function and compile the file, `typia` will write optimal validation code for the `string | null` type like below. This is the transform mode performing AOT (Ahead of Time) compilation.
|
|
71
|
+
|
|
72
|
+
As long as you're using standard TypeScript compiler, I just recommend you to use this transform mode. Otherwise, you're using non-standard compiler like [SWC](https://swc.rs/) or [Babel](https://babeljs.io/) (mostly designed for frontend development), you've to use the generation mode instead.
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
// TYPESCRIPT CODE
|
|
76
|
+
import typia from "typia";
|
|
77
|
+
export const check = typia.createIs<string | null>();
|
|
78
|
+
|
|
79
|
+
// COMPILED JAVASCRIPT CODE
|
|
80
|
+
export const check = (input) => "string" === typeof input || null === input;
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+

|
|
84
|
+
|
|
85
|
+
By the way, to use the transform mode, you've install one onf them; [ttypescript](https://github.com/cevek/ttypescript) or [ts-patch](https://github.com/nonara/ts-patch).
|
|
86
|
+
|
|
87
|
+
If [ttypescript](https://github.com/cevek/ttypescript), you should compile through `ttsc` command, instead of using `tsc`.
|
|
88
|
+
|
|
89
|
+
Otherwise, you've chosen [ts-patch](https://github.com/nonara/ts-patch), you can use original `tsc` command. However, [ts-patch](https://github.com/nonara/ts-patch) hacks `node_modules/typescript` source code. Also, whenever update `typescrtip` version, you have to run `npm run prepare` command repeatedly.
|
|
90
|
+
|
|
91
|
+
By the way, when using [@nest/cli](https://nestjs.com), you must just choose [ts-patch](https://github.com/nonara/ts-patch).
|
|
71
92
|
|
|
72
93
|
```bash
|
|
94
|
+
##########################################################
|
|
95
|
+
# TTYPESCRIPT
|
|
96
|
+
##########################################################
|
|
73
97
|
# COMPILE THROUGH TTYPESCRIPT
|
|
74
98
|
npx ttsc
|
|
75
99
|
|
|
76
100
|
# RUN TS-NODE WITH TTYPESCRIPT
|
|
77
101
|
npx ts-node -C ttypescript src/index.ts
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
Otherwise, you've chosen [ts-patch](https://github.com/nonara/ts-patch), you can use original `tsc` command. However, [ts-patch](https://github.com/nonara/ts-patch) hacks `node_modules/typescript` source code. Also, whenever update `typescript` version, you've to run `npm run prepare` command repeatedly.
|
|
81
|
-
|
|
82
|
-
By the way, when using `@nest/cli`, you must just choose [ts-patch](https://github.com/nonara/ts-patch)
|
|
83
102
|
|
|
84
|
-
|
|
103
|
+
##########################################################
|
|
104
|
+
# TS-PATCH
|
|
105
|
+
##########################################################
|
|
85
106
|
# USE ORIGINAL TSC COMMAND
|
|
86
107
|
tsc
|
|
87
108
|
npx ts-node src/index.ts
|
|
@@ -91,42 +112,35 @@ npm install --save-dev typescript@latest
|
|
|
91
112
|
npm run prepare
|
|
92
113
|
```
|
|
93
114
|
|
|
94
|
-
###
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
- [NPM Packages](https://github.com/samchon/typia/wiki/Setup#npm-packages)
|
|
99
|
-
- [`tsconfig.json`](https://github.com/samchon/typia/wiki/Setup#tsconfigjson)
|
|
100
|
-
- [vite](https://github.com/samchon/typia/wiki/Setup#vite)
|
|
101
|
-
- [webpack](https://github.com/samchon/typia/wiki/Setup#webpack)
|
|
115
|
+
### Generation (beta)
|
|
116
|
+
```bash
|
|
117
|
+
# INSTALL TYPIA
|
|
118
|
+
npm install --save typia
|
|
102
119
|
|
|
103
|
-
|
|
104
|
-
|
|
120
|
+
# GENERATE TRANSFORMED TYPESCRIPT CODES
|
|
121
|
+
npx typia generate \
|
|
122
|
+
--input src/templates \
|
|
123
|
+
--output src/generated
|
|
124
|
+
```
|
|
105
125
|
|
|
106
|
-
|
|
126
|
+
If you're not using standard TypeScript compiler, you can't use [transform mode](#transformation-stable). Instead, you can utilize the generation mode. Install `typia` through `npm install` command and run `typia generate` command like above.
|
|
107
127
|
|
|
108
|
-
|
|
128
|
+
The generator of `typia` reads your TypeScript code of `--input` and writes transformed TypeScript code into the `--output` directory. However, as this feature generates duplicated TypeScript code even even not perfectly stable like [transform mode](#transformation-stable), I recommend you to use generation mode only when you're using non-standard TypeScript compiler.
|
|
109
129
|
|
|
110
130
|
```typescript
|
|
111
|
-
|
|
112
|
-
import
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
export
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
// when using "ttypescript"
|
|
121
|
-
typescript({
|
|
122
|
-
typescript: ttsc,
|
|
123
|
-
}),
|
|
124
|
-
// otherwise using "ts-patch"
|
|
125
|
-
typescript()
|
|
126
|
-
]
|
|
127
|
-
});
|
|
131
|
+
// src/templates/check.ts
|
|
132
|
+
import typia from "typia";
|
|
133
|
+
export const check = typia.createIs<string | null>();
|
|
134
|
+
|
|
135
|
+
// src/generated/check.ts
|
|
136
|
+
import typia from "typia";
|
|
137
|
+
export const check =
|
|
138
|
+
(input: unknown): input is string | null
|
|
139
|
+
=> "string" === typeof input || null === input;
|
|
128
140
|
```
|
|
129
141
|
|
|
142
|
+
> For reference, most of frontend projects are using non-standard TypeScript compiler like [SWC](https://swc.rs/) or [Babel](https://babeljs.io/) (mostly designed for frontend development). Therefore, I just recomend you to use the generation mode when developing frontend project.
|
|
143
|
+
|
|
130
144
|
|
|
131
145
|
|
|
132
146
|
|