Skip to content

Commit bfc9e6e

Browse files
authored
feat: add typia (moltar#1023)
* Add typia * For lint * Add new line * typia on npm commands * Understood what parseSafe is * More simple parseSafe * Update README.md - add typia * Change `ITransformOptions.undefined` value * Upgrade typia version * Upgrade typia version * Update typia again * block undefined value
1 parent 650ec55 commit bfc9e6e

File tree

12 files changed

+114
-43
lines changed

12 files changed

+114
-43
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
docs/dist
33
cases/spectypes/build
44
cases/ts-runtime-checks/build
5+
case/typia/build

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,6 @@ cases/spectypes/build
105105

106106
# ts-runtime-checks build artifacts
107107
cases/ts-runtime-checks/build
108+
109+
# typia build artifacts
110+
cases/typia/build

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
* [ts-runtime-checks](https://github.com/GoogleFeud/ts-runtime-checks)
4343
* [tson](https://github.com/skarab42/tson)
4444
* [ts-utils](https://github.com/ai-labs-team/ts-utils)
45+
* [typia](https://github.com/samchon/typia)
4546
* [@typeofweb/schema](https://github.com/typeofweb/schema)
4647
* [valita](https://github.com/badrap/valita)
4748
* [Vality](https://github.com/jeengbe/vality)

cases/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const cases = [
3131
'ts-utils',
3232
'tson',
3333
'typeofweb-schema',
34+
'typia',
3435
'valita',
3536
'vality',
3637
'yup',

cases/typia/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { parseSafe, parseStrict, assertLoose, assertStrict } from './build';
2+
import { addCase } from '../../benchmarks';
3+
4+
addCase('typia', 'parseSafe', parseSafe);
5+
addCase('typia', 'parseStrict', parseStrict);
6+
addCase('typia', 'assertStrict', assertStrict);
7+
addCase('typia', 'assertLoose', assertLoose);

cases/typia/src/index.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import typia from 'typia';
2+
3+
interface ToBeChecked {
4+
number: number;
5+
negNumber: number;
6+
maxNumber: number;
7+
string: string;
8+
longString: string;
9+
boolean: boolean;
10+
deeplyNested: {
11+
foo: string;
12+
num: number;
13+
bool: boolean;
14+
};
15+
}
16+
17+
const is = typia.createIs<ToBeChecked>();
18+
const equals = typia.createEquals<ToBeChecked>();
19+
const stringify = typia.createStringify<ToBeChecked>();
20+
21+
export function assertLoose(input: unknown): boolean {
22+
if (!is(input)) throw new Error('wrong type.');
23+
return true;
24+
}
25+
26+
export function assertStrict(input: unknown): boolean {
27+
if (!equals(input)) throw new Error('wrong type.');
28+
return true;
29+
}
30+
31+
export function parseStrict(input: unknown): ToBeChecked {
32+
if (!equals(input)) throw new Error('wrong type.');
33+
return input;
34+
}
35+
36+
export function parseSafe(input: unknown): ToBeChecked {
37+
if (!is(input)) throw new Error('wrong type.');
38+
return JSON.parse(stringify(input));
39+
}

cases/typia/tsconfig.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"module": "commonjs",
5+
"outDir": "build",
6+
"strict": true,
7+
"plugins": [
8+
{
9+
"transform": "typia/lib/transform",
10+
"undefined": false,
11+
}
12+
]
13+
},
14+
"include": ["src/index.ts"]
15+
}
16+

docs/results/node-18.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ async function main() {
3131
stdio: 'inherit',
3232
});
3333
}
34+
if (c === 'typia') {
35+
childProcess.execSync('npm run compile:typia', {
36+
stdio: 'inherit',
37+
});
38+
}
3439

3540
const cmd = [...process.argv.slice(0, 2), 'run-internal', c];
3641

package-lock.json

Lines changed: 33 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)