diff --git a/package-lock.json b/package-lock.json index b3f2f16..e766055 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,12 +12,15 @@ "@sinclair/typebox": "^0.32.22", "ajv": "^8.12.0", "ajv-formats": "^3.0.1", + "banditypes": "^0.2.5", "fastest-validator": "^1.18.0", "joi": "^17.12.3", "jsvalidator": "^2.0.0", "mschema": "0.5.6", "nope-validator": "^1.0.4", "parambulator": "1.5.2", + "picostruct": "^0.1.2", + "superstruct": "^2.0.2", "typia": "^6.0.3", "valibot": "^0.30.0", "validate.js": "^0.13.1", @@ -155,6 +158,15 @@ "resolved": "https://registry.npmjs.org/array-timsort/-/array-timsort-1.0.3.tgz", "integrity": "sha512-/+3GRL7dDAGEfM6TseQk/U+mi18TU2Ms9I3UlLdUMhz2hbvGNTKdj9xniwXfUqgYhHxRx0+8UnKkvlNwVU+cWQ==" }, + "node_modules/banditypes": { + "version": "0.2.5", + "resolved": "https://registry.npmjs.org/banditypes/-/banditypes-0.2.5.tgz", + "integrity": "sha512-yyfPhzlDEtH2CtqxkUKYO1R4eQ6HGGUsnztSpFgASTD82gZKN50YQQV3wmh+u26YEWAEKVnd3HmCXs7AaD8RgQ==", + "license": "MIT", + "engines": { + "node": "^14 || ^16 || >=18" + } + }, "node_modules/base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", @@ -742,6 +754,12 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.5.0.tgz", "integrity": "sha512-QX5CQiKEsYsnEvcTGDRDcq75WePSnzrptmplm8BIARgWrDmdjg051fpi3FGhDdwGhlv6Q4HZKwNYrUb3cQ8Gtg==" }, + "node_modules/picostruct": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/picostruct/-/picostruct-0.1.2.tgz", + "integrity": "sha512-aVrhbJH9bx7ja0kyOBa+3Oc6ix35fpFvlRSaPriRYRlLigYvsAPtPaETNOFF21VRSsPaQKcbhbsF4SmzuXOSbw==", + "license": "MIT" + }, "node_modules/property-expr": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/property-expr/-/property-expr-2.0.5.tgz", @@ -922,6 +940,15 @@ "node": ">=8" } }, + "node_modules/superstruct": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/superstruct/-/superstruct-2.0.2.tgz", + "integrity": "sha512-uV+TFRZdXsqXTL2pRvujROjdZQ4RAlBUS5BTh9IGm+jTqQntYThciG/qu57Gs69yjnVUSqdxF9YLmSnpupBW9A==", + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", diff --git a/package.json b/package.json index dce2a24..ba4d793 100644 --- a/package.json +++ b/package.json @@ -17,12 +17,15 @@ "@sinclair/typebox": "^0.32.22", "ajv": "^8.12.0", "ajv-formats": "^3.0.1", + "banditypes": "^0.2.5", "fastest-validator": "^1.18.0", "joi": "^17.12.3", "jsvalidator": "^2.0.0", "mschema": "0.5.6", "nope-validator": "^1.0.4", "parambulator": "1.5.2", + "picostruct": "^0.1.2", + "superstruct": "^2.0.2", "typia": "^6.0.3", "valibot": "^0.30.0", "validate.js": "^0.13.1", diff --git a/suites/simple.js b/suites/simple.js index 60c7ed9..be48252 100644 --- a/suites/simple.js +++ b/suites/simple.js @@ -361,5 +361,56 @@ const obj = { }()); +// ---- superstruct ---- +(function () { + const { is, object, string, number, pattern, size, min } = require('superstruct') + + const schema = object({ + name: size(string(), 4, 25), + email: pattern(string(), /^\S+@\S+\.\S+$/), + firstName: string(), + phone: string(), + age: min(number(), 18) + }); + + bench.add("superstruct", () => { + return is(obj, schema); + }); +}()); + +// ---- picostruct ---- +(function () { + const { struct, filter, string, number } = require('picostruct') + + const schema = struct({ + name: filter(string(), x => x.length >= 4 && x.length <= 25), + email: string(/^\S+@\S+\.\S+$/), + firstName: string(), + phone: string(), + age: filter(number(), x => x >= 18) + }); + + bench.add("picostruct", () => { + return schema(obj); + }); +}()); + +// ---- banditypes ---- +(function () { + const { object, string, number, fail } = require('banditypes') + + const schema = object({ + name: string().map(x => (x.length >= 4 && x.length <= 25) ? x : fail()), + email: string().map(x => /^\S+@\S+\.\S+$/.test(x) ? x : fail()), + firstName: string(), + phone: string(), + age: number().map(x => x >= 18 ? x : fail()) + }); + + bench.add("banditypes", () => { + return schema(obj); + }); +}()); + bench.run();