-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * Tests * Getting close * Tests pass * Implementation almost ready * v0.6.1-0 * All migrated * Tests * v0.6.1-1 * Update stringify * v0.6.1-2 * Add sourcemaps * Cleanup * Docs wip * feat(refinements): Add nextValid and nextNotValid BREAKING CHANGE: `next` was renamed to `nextValid`. * chore: Update deps * docs: Fix link * docs: Update readme with new benchmarks
- Loading branch information
Showing
53 changed files
with
1,371 additions
and
1,064 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,9 @@ | |
`@typeofweb/schema` is a lightweight and extensible library for data validation with full TypeScript support! | ||
|
||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --> | ||
|
||
[![All Contributors](https://img.shields.io/badge/all_contributors-5-orange.svg?style=flat-square)](#contributors-) | ||
|
||
<!-- ALL-CONTRIBUTORS-BADGE:END --> | ||
|
||
[![codecov](https://codecov.io/gh/typeofweb/schema/branch/main/graph/badge.svg?token=6DNCIHEEUO)](https://codecov.io/gh/typeofweb/schema) | ||
|
@@ -51,7 +53,7 @@ const personSchema = object({ | |
name: string(), | ||
age: number(), | ||
email: optional(string()), | ||
}); | ||
})(); | ||
|
||
const mark = { | ||
name: 'Mark', | ||
|
@@ -71,24 +73,24 @@ Early benchmarks show some really promising performance of `@typeofweb/schema` w | |
``` | ||
Platform info: | ||
============== | ||
Darwin 20.2.0 x64 | ||
Node.JS: 14.15.2 | ||
V8: 8.4.371.19-node.17 | ||
Darwin 20.3.0 x64 | ||
Node.JS: 14.16.0 | ||
V8: 8.4.371.19-node.18 | ||
Intel(R) Core(TM) i7-6920HQ CPU @ 2.90GHz × 8 | ||
``` | ||
|
||
| library | relative speed | operations per second | avg. operation time | | ||
| --------------------- | -------------: | --------------------: | ------------------: | | ||
| **@typeofweb/schema** | ref | **(2,812,709 rps)** | **(avg: 0.355μs)** | | ||
| [email protected] | -27.82% | (2,030,076 rps) | (avg: 0.492μs) | | ||
| [email protected] | -79.15% | (586,537 rps) | (avg: 1μs) | | ||
| [email protected] | -83.22% | (471,847 rps) | (avg: 2μs) | | ||
| [email protected] | -91.62% | (235,741 rps) | (avg: 4μs) | | ||
| [email protected] | -94.08% | (166,599 rps) | (avg: 6μs) | | ||
| [email protected] | -95.52% | (125,992 rps) | (avg: 7μs) | | ||
| [email protected] | -97.17% | (79,536 rps) | (avg: 12μs) | | ||
| [email protected] | -97.66% | (65,748 rps) | (avg: 15μs) | | ||
| [email protected] | -99.17% | (23,308 rps) | (avg: 42μs) | | ||
| [email protected] | -99.36% | (18,126 rps) | (avg: 55μs) | | ||
| **@typeofweb/schema** | **ref** | **(1,934,098 rps)** | **(avg: 0.517μs)** | | ||
| [email protected] | -7.21% | (1,794,594 rps) | (avg: 0.557μs) | | ||
| [email protected] | -69.8% | (584,151 rps) | (avg: 1μs) | | ||
| [email protected] | -76.16% | (461,088 rps) | (avg: 2μs) | | ||
| [email protected] | -89.02% | (212,408 rps) | (avg: 4μs) | | ||
| [email protected] | -92.2% | (150,791 rps) | (avg: 6μs) | | ||
| [email protected] | -93.25% | (130,541 rps) | (avg: 7μs) | | ||
| [email protected] | -96.99% | (58,197 rps) | (avg: 17μs) | | ||
| [email protected] | -97.09% | (56,243 rps) | (avg: 17μs) | | ||
| [email protected] | -98.99% | (19,492 rps) | (avg: 51μs) | | ||
| [email protected] | -99.03% | (18,827 rps) | (avg: 53μs) | | ||
|
||
### 👉 [schema.typeofweb.com](https://schema.typeofweb.com/) 👈 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
'use strict'; | ||
exports.__esModule = true; | ||
const src_1 = require('../dist/index.common.js'); | ||
const { object, minStringLength, string, number, validate } = require('../dist/index.common.js'); | ||
function run(i) { | ||
const schema = src_1.object({ | ||
name: src_1.minLength(4)(src_1.string()), | ||
email: src_1.string(), | ||
firstName: src_1.nonEmpty(src_1.string()), | ||
phone: src_1.nonEmpty(src_1.string()), | ||
age: src_1.oneOf([i]), | ||
}); | ||
const validator = src_1.validate(schema); | ||
const schema = object({ | ||
name: minStringLength(4)(string()), | ||
email: string(), | ||
firstName: minStringLength(0)(string()), | ||
phone: string(), | ||
// age: number(), | ||
})(); | ||
const validator = validate(schema); | ||
const obj = { | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
firstName: 'John', | ||
phone: '123-4567', | ||
age: i, | ||
// age: i, | ||
}; | ||
return validator(obj); | ||
} | ||
for (let i = 0; i < 2000000; ++i) { | ||
for (let i = 0; i < 4000000; ++i) { | ||
run(i); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
7b2d7e4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: