Skip to content

Commit e48d96f

Browse files
authored
Merge pull request #1608 from aquapi/master
Add stnl validator
2 parents c97220d + c1bbff4 commit e48d96f

File tree

7 files changed

+60
-0
lines changed

7 files changed

+60
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
* [@sinclair/typebox](https://github.com/sinclairzx81/typebox)
4545
* [simple-runtypes](https://github.com/hoeck/simple-runtypes)
4646
* [spectypes](https://github.com/iyegoroff/spectypes)
47+
* [stnl](https://github.com/re-utils/stnl)
4748
* [succulent](https://github.com/aslilac/succulent)
4849
* [superstruct](https://github.com/ianstormtaylor/superstruct)
4950
* [suretype](https://github.com/grantila/suretype)

bun.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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",
@@ -1411,6 +1412,8 @@
14111412

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

1415+
"stnl": ["stnl@0.3.3", "", {}, "sha512-8uMWUCQcvWDE3CwbmNPj9QogtFUL2n+J+6XoDhDYT2EJ4fnHu1Xdvxs5WUnBseJQP7Nl/1YfIPT4BLrLC6AhJA=="],
1416+
14141417
"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=="],
14151418

14161419
"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)