Skip to content

Commit

Permalink
Merge pull request #1163 from ryoppippi/feature/add-unknownutil
Browse files Browse the repository at this point in the history
add unknownutil
  • Loading branch information
hoeck authored Oct 10, 2023
2 parents 5367026 + 855fd08 commit 61ed7a7
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* [ts-utils](https://github.com/ai-labs-team/ts-utils)
* [typia](https://github.com/samchon/typia)
* [@typeofweb/schema](https://github.com/typeofweb/schema)
* [unknownutil](https://github.com/lambdalisue/deno-unknownutil)
* [valibot](https://github.com/fabian-hiller/valibot)
* [valita](https://github.com/badrap/valita)
* [Vality](https://github.com/jeengbe/vality)
Expand Down
1 change: 1 addition & 0 deletions cases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const cases = [
'tson',
'typeofweb-schema',
'typia',
'unknownutil',
'valibot',
'valita',
'vality',
Expand Down
63 changes: 63 additions & 0 deletions cases/unknownutil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { is, ensure, assert } from 'unknownutil';
import { createCase } from '../benchmarks';

const dataTypeLoose = is.ObjectOf({
number: is.Number,
negNumber: is.Number,
maxNumber: is.Number,
string: is.String,
longString: is.String,
boolean: is.Boolean,
deeplyNested: is.ObjectOf({
foo: is.String,
num: is.Number,
bool: is.Boolean,
}),
});

const dataTypeStrict = is.ObjectOf(
{
number: is.Number,
negNumber: is.Number,
maxNumber: is.Number,
string: is.String,
longString: is.String,
boolean: is.Boolean,
deeplyNested: is.ObjectOf(
{
foo: is.String,
num: is.Number,
bool: is.Boolean,
},
{ strict: true }
),
},
{ strict: true }
);

// TODO: unklike other validators, unknownutil does not remove extra properties
// createCase('unknownutil', 'parseSafe', () => {
// return data => {
// return ensure(data, dataTypeLoose);
// };
// });

createCase('unknownutil', 'parseStrict', () => {
return data => {
return ensure(data, dataTypeStrict);
};
});

createCase('unknownutil', 'assertStrict', () => {
return data => {
assert(data, dataTypeStrict);
return true;
};
});

createCase('unknownutil', 'assertLoose', () => {
return data => {
assert(data, dataTypeLoose);
return true;
};
});
11 changes: 11 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"ts-runtime-checks": "0.4.0",
"typescript": "5.1.6",
"typia": "5.0.4",
"unknownutil": "3.9.0",
"valibot": "0.15.0",
"vality": "6.3.3",
"vega": "5.25.0",
Expand Down
1 change: 1 addition & 0 deletions test/benchmarks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import '../cases/ts-utils';
import '../cases/tson';
import '../cases/typeofweb-schema';
import '../cases/typia';
import '../cases/unknownutil';
import '../cases/valibot';
import '../cases/valita';
import '../cases/vality';
Expand Down

0 comments on commit 61ed7a7

Please sign in to comment.