Skip to content

Commit 054e79d

Browse files
committed
Add stnl:
- 'composition' and 'just-in-time' mode
1 parent ccd5f8c commit 054e79d

File tree

6 files changed

+60
-1
lines changed

6 files changed

+60
-1
lines changed

bun.lock

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"lockfileVersion": 0,
2+
"lockfileVersion": 1,
33
"workspaces": {
44
"": {
55
"name": "typescript-runtime-type-benchmarks",
@@ -54,6 +54,7 @@
5454
"serve": "14.2.4",
5555
"simple-runtypes": "7.1.3",
5656
"spectypes": "2.1.11",
57+
"stnl": "0.3.3",
5758
"succulent": "0.18.1",
5859
"superstruct": "2.0.2",
5960
"suretype": "2.4.1",
@@ -1415,6 +1416,8 @@
14151416

14161417
"std-env": ["std-env@3.8.0", "", {}, "sha512-Bc3YwwCB+OzldMxOXJIIvC6cPRWr/LxOp48CdQTOkPyk/t4JWWJbrilwBd7RJzKV8QW7tJkcgAmeuLLJugl5/w=="],
14171418

1419+
"stnl": ["stnl@0.3.3", "", {}, "sha512-8uMWUCQcvWDE3CwbmNPj9QogtFUL2n+J+6XoDhDYT2EJ4fnHu1Xdvxs5WUnBseJQP7Nl/1YfIPT4BLrLC6AhJA=="],
1420+
14181421
"string-width": ["string-width@4.2.3", "", { "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", "strip-ansi": "^6.0.1" } }, "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g=="],
14191422

14201423
"string-width-cjs": ["string-width@4.2.3", "", { "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", "strip-ansi": "^6.0.1" } }, "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g=="],

cases/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const cases = [
3030
'sinclair-typebox-dynamic',
3131
'sinclair-typebox-just-in-time',
3232
'spectypes',
33+
'stnl',
3334
'succulent',
3435
'superstruct',
3536
'suretype',

cases/stnl.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import compose from 'stnl/compilers/validate-json/compose';
2+
import { build } from 'stnl/compilers/validate-json';
3+
import stnl from 'stnl';
4+
5+
import { createCase } from '../benchmarks';
6+
7+
const assertLoose = stnl({
8+
props: {
9+
number: 'f64',
10+
negNumber: 'f64',
11+
maxNumber: 'f64',
12+
string: 'string',
13+
longString: 'string',
14+
boolean: 'bool',
15+
deeplyNested: {
16+
props: {
17+
foo: 'string',
18+
num: 'f64',
19+
bool: 'bool',
20+
},
21+
},
22+
},
23+
});
24+
25+
createCase('stnl (composition)', 'assertLoose', () => {
26+
const check = compose(assertLoose);
27+
28+
return data => {
29+
if (check(data)) return true;
30+
throw null;
31+
};
32+
});
33+
34+
createCase('stnl (just-in-time)', 'assertLoose', () => {
35+
const check = build(assertLoose);
36+
37+
return data => {
38+
if (check(data)) return true;
39+
throw null;
40+
};
41+
});

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"serve": "14.2.4",
8181
"simple-runtypes": "7.1.3",
8282
"spectypes": "2.1.11",
83+
"stnl": "0.3.3",
8384
"succulent": "0.18.1",
8485
"superstruct": "2.0.2",
8586
"suretype": "2.4.1",

test/benchmarks.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import '../cases/sinclair-typebox-ahead-of-time';
3535
import '../cases/sinclair-typebox-dynamic';
3636
import '../cases/sinclair-typebox-just-in-time';
3737
import '../cases/spectypes';
38+
import '../cases/stnl';
3839
import '../cases/succulent';
3940
import '../cases/superstruct';
4041
import '../cases/suretype';

0 commit comments

Comments
 (0)