Skip to content

Commit

Permalink
Add rescript-struct
Browse files Browse the repository at this point in the history
  • Loading branch information
DZakh committed Dec 5, 2022
1 parent f46b158 commit 38cdb38
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* [purify-ts](https://github.com/gigobyte/purify)
* [parse-dont-validate](https://github.com/Packer-Man/parse-dont-validate)
* [r-assign](https://github.com/micnic/r-assign)
* [rescript-struct](https://github.com/DZakh/rescript-struct)
* [rulr](https://github.com/ryansmith94/rulr)
* [runtypes](https://github.com/pelotom/runtypes)
* [@sapphire/shapeshift](https://github.com/sapphiredev/shapeshift)
Expand Down
1 change: 1 addition & 0 deletions cases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const cases = [
'parse-dont-validate',
'purify-ts',
'r-assign',
'rescript-struct',
'rulr',
'runtypes',
'sapphire-shapeshift',
Expand Down
87 changes: 87 additions & 0 deletions cases/rescript-struct.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import * as S from 'rescript-struct';

import { createCase } from '../benchmarks';

createCase('rescript-struct', 'parseSafe', () => {
const struct = S.object({
number: S.number(),
negNumber: S.number(),
maxNumber: S.number(),
string: S.string(),
longString: S.string(),
boolean: S.boolean(),
deeplyNested: S.object({
foo: S.string(),
num: S.number(),
bool: S.boolean(),
}),
});

return data => {
return struct.parseOrThrow(data);
};
});

createCase('rescript-struct', 'parseStrict', () => {
const struct = S.object({
number: S.number(),
negNumber: S.number(),
maxNumber: S.number(),
string: S.string(),
longString: S.string(),
boolean: S.boolean(),
deeplyNested: S.object({
foo: S.string(),
num: S.number(),
bool: S.boolean(),
}).strict(),
}).strict();

return data => {
return struct.parseOrThrow(data);
};
});

createCase('rescript-struct', 'assertLoose', () => {
const struct = S.object({
number: S.number(),
negNumber: S.number(),
maxNumber: S.number(),
string: S.string(),
longString: S.string(),
boolean: S.boolean(),
deeplyNested: S.object({
foo: S.string(),
num: S.number(),
bool: S.boolean(),
}),
});

return data => {
struct.parseOrThrow(data);

return true;
};
});

createCase('rescript-struct', 'assertStrict', () => {
const struct = S.object({
number: S.number(),
negNumber: S.number(),
maxNumber: S.number(),
string: S.string(),
longString: S.string(),
boolean: S.boolean(),
deeplyNested: S.object({
foo: S.string(),
num: S.number(),
bool: S.boolean(),
}).strict(),
}).strict();

return data => {
struct.parseOrThrow(data);

return true;
};
});
33 changes: 33 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"purify-ts": "1.3.0",
"r-assign": "1.6.0",
"reflect-metadata": "0.1.13",
"rescript": "10.1.0",
"rescript-struct": "3.0.0",
"rulr": "8.7.6",
"runtypes": "6.6.0",
"serve": "12.0.1",
Expand Down
1 change: 1 addition & 0 deletions test/benchmarks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import '../cases/ok-computer';
import '../cases/parse-dont-validate';
import '../cases/purify-ts';
import '../cases/r-assign';
import '../cases/rescript-struct';
import '../cases/rulr';
import '../cases/runtypes';
import '../cases/sapphire-shapeshift';
Expand Down

0 comments on commit 38cdb38

Please sign in to comment.