@esmj/schema 0.3.4 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -40
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -21,9 +21,9 @@ npm install @esmj/schema
|
|
|
21
21
|
|
|
22
22
|
### Performance Highlights
|
|
23
23
|
|
|
24
|
-
- **Schema Creation**: Create schemas
|
|
25
|
-
- **Parsing**: Parse data with
|
|
26
|
-
- **Error Handling**: Efficiently manage errors
|
|
24
|
+
- **Schema Creation**: Create schemas at up to 4 370 618 ops/s (0.23 μs latency) with @sinclair/typebox, or 736 810 ops/s (1.36 μs latency) with @esmj/schema. Superstruct and @esmj/schema are also among the fastest for schema creation.
|
|
25
|
+
- **Parsing**: Parse data at up to 4 627 714 ops/s (0.22 μs latency) with @zod/mini (note: @zod/mini was observed to consume 200% CPU, while other libraries used only 100% CPU), or 3 142 587 ops/s (0.32 μs latency) with @esmj/schema. ArkType and effect/Schema also show strong parsing throughput.
|
|
26
|
+
- **Error Handling**: Efficiently manage errors at up to 2 428 049 ops/s (0.41 μs latency) with @esmj/schema, or 1 386 616 ops/s (0.72 μs latency) with @zod/mini.
|
|
27
27
|
|
|
28
28
|
These performance metrics make `@esmj/schema` an excellent choice for both frontend and backend applications where speed and efficiency are critical.
|
|
29
29
|
|
|
@@ -31,54 +31,64 @@ These performance metrics make `@esmj/schema` an excellent choice for both front
|
|
|
31
31
|
|
|
32
32
|
When choosing a schema validation library, bundle size can be an important factor, especially for frontend applications where minimizing JavaScript size is critical. Here's how `@esmj/schema` compares to other popular libraries:
|
|
33
33
|
|
|
34
|
-
| Library
|
|
35
|
-
|
|
36
|
-
| `@esmj/schema`
|
|
37
|
-
| Superstruct
|
|
38
|
-
|
|
|
39
|
-
|
|
|
40
|
-
| @
|
|
41
|
-
|
|
|
42
|
-
|
|
|
43
|
-
|
|
|
34
|
+
| Library | Bundle Size (minified + gzipped) |
|
|
35
|
+
|-------------------|---------------------------------|
|
|
36
|
+
| `@esmj/schema` | `~1,2 KB` |
|
|
37
|
+
| Superstruct | ~3.2 KB |
|
|
38
|
+
| @sinclair/typebox | ~11.7 KB |
|
|
39
|
+
| Yup | ~12.2 KB |
|
|
40
|
+
| Zod@3 | ~13 KB |
|
|
41
|
+
| @zod/mini | ~20,5 KB |
|
|
42
|
+
| Joi | ~40,4 KB |
|
|
43
|
+
| Zod@4 | ~40,8 KB |
|
|
44
|
+
| ArkType | ~41,8 KB |
|
|
45
|
+
| Effect/Schema | ~115.5 KB |
|
|
44
46
|
|
|
45
47
|
### Performance Comparison
|
|
46
48
|
|
|
49
|
+
*All benchmarks were measured on Node.js v24.1.0.*
|
|
50
|
+
|
|
47
51
|
#### Schema Creation Performance
|
|
48
52
|
|
|
49
|
-
| Library
|
|
50
|
-
|
|
51
|
-
|
|
|
52
|
-
|
|
|
53
|
-
| @zod/mini
|
|
54
|
-
| Yup
|
|
55
|
-
| Superstruct
|
|
56
|
-
| Joi
|
|
57
|
-
|
|
|
53
|
+
| Library | Throughput average (ops/s) | Latency average (μs) |
|
|
54
|
+
|-------------------|-------------------------------:|-------------------------:|
|
|
55
|
+
| @esmj/schema | 736 810.12 ± 3.03% | 1.36 ± 3.24% |
|
|
56
|
+
| Zod@3 | 112 575.50 ± 0.86% | 8.88 ± 0.87% |
|
|
57
|
+
| @zod/mini | 23 456.07 ± 1.26% | 42.64 ± 1.28% |
|
|
58
|
+
| Yup | 75 051.06 ± 4.38% | 13.36 ± 4.41% |
|
|
59
|
+
| Superstruct | 509 401.06 ± 0.80% | 1.96 ± 0.80% |
|
|
60
|
+
| Joi | 42 455.28 ± 1.27% | 23.56 ± 1.30% |
|
|
61
|
+
| `@sinclair/typebox` | `4 370 618.49 ± 1.23%` | `0.23 ± 1.23%` |
|
|
62
|
+
| ArkType | 16 282.69 ± 4.14% | 61.61 ± 4.38% |
|
|
63
|
+
| effect/Schema | 24 919.15 ± 4.31% | 40.31 ± 4.78% |
|
|
58
64
|
|
|
59
65
|
#### Parsing Performance
|
|
60
66
|
|
|
61
|
-
| Library
|
|
62
|
-
|
|
63
|
-
|
|
|
64
|
-
| zod@3
|
|
65
|
-
|
|
|
66
|
-
| Yup
|
|
67
|
-
| Superstruct
|
|
68
|
-
| Joi
|
|
69
|
-
|
|
|
67
|
+
| Library | Throughput average (ops/s) | Latency average (μs) |
|
|
68
|
+
|-------------------|-------------------------------:|-------------------------:|
|
|
69
|
+
| @esmj/schema | 3 142 587.31 ± 0.97% | 0.32 ± 0.99% |
|
|
70
|
+
| zod@3 | 1 018 777.24 ± 0.64% | 0.98 ± 0.65% |
|
|
71
|
+
| `@zod/mini` | `4 627 714.90 ± 2.23%` | `0.22 ± 2.36%` |
|
|
72
|
+
| Yup | 108 361.49 ± 0.50% | 9.23 ± 0.51% |
|
|
73
|
+
| Superstruct | 252 904.42 ± 2.20% | 3.96 ± 2.44% |
|
|
74
|
+
| Joi | 346 094.49 ± 0.65% | 2.89 ± 0.65% |
|
|
75
|
+
| @sinclair/typebox | 228 711.62 ± 2.03% | 4.38 ± 2.23% |
|
|
76
|
+
| ArkType | 1 677 066.00 ± 0.58% | 0.60 ± 0.59% |
|
|
77
|
+
| effect/Schema | 1 060 056.14 ± 0.61% | 0.94 ± 0.61% |
|
|
70
78
|
|
|
71
79
|
#### Error Handling Performance
|
|
72
80
|
|
|
73
|
-
| Library
|
|
74
|
-
|
|
75
|
-
| `@esmj/schema`
|
|
76
|
-
|
|
|
77
|
-
| @zod/mini
|
|
78
|
-
| Yup
|
|
79
|
-
| Superstruct
|
|
80
|
-
| Joi
|
|
81
|
-
|
|
|
81
|
+
| Library | Throughput average (ops/s) | Latency average (μs) |
|
|
82
|
+
|-------------------|-------------------------------:|-------------------------:|
|
|
83
|
+
| `@esmj/schema` | `2 428 049.34 ± 0.54%` | `0.41 ± 0.53%` |
|
|
84
|
+
| zod@3 | 641 504.22 ± 3.67% | 1.57 ± 4.38% |
|
|
85
|
+
| @zod/mini | 1 386 616.61 ± 0.60% | 0.72 ± 0.60% |
|
|
86
|
+
| Yup | 98 904.30 ± 0.61% | 10.11 ± 0.61% |
|
|
87
|
+
| Superstruct | 122 782.09 ± 1.03% | 8.15 ± 1.03% |
|
|
88
|
+
| Joi | 271 301.11 ± 1.58% | 3.69 ± 1.59% |
|
|
89
|
+
| @sinclair/typebox | 228 734.49 ± 0.55% | 4.37 ± 0.56% |
|
|
90
|
+
| ArkType | 258 685.33 ± 1.23% | 3.87 ± 1.23% |
|
|
91
|
+
| effect/Schema | 165 753.69 ± 0.99% | 6.03 ± 1.00% |
|
|
82
92
|
|
|
83
93
|
**Note:** During the performance tests, `@zod/mini` was observed to consume 200% CPU, while other libraries used only 100% CPU. This may affect the interpretation of the results, especially in multi-threaded environments.
|
|
84
94
|
|
package/package.json
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@esmj/schema",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Tiny extendable package for schema validation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"schema",
|
|
7
7
|
"validation",
|
|
8
8
|
"type",
|
|
9
9
|
"inference",
|
|
10
|
-
"zod"
|
|
10
|
+
"zod",
|
|
11
|
+
"@sinclair/typebox",
|
|
12
|
+
"yup",
|
|
13
|
+
"superstruct",
|
|
14
|
+
"joi",
|
|
15
|
+
"arktype"
|
|
11
16
|
],
|
|
12
17
|
"main": "dist/index",
|
|
13
18
|
"module": "dist/index",
|
|
@@ -22,7 +27,7 @@
|
|
|
22
27
|
"scripts": {
|
|
23
28
|
"lint": "biome check --no-errors-on-unmatched",
|
|
24
29
|
"lint:fix": "npm run lint -- --fix --unsafe",
|
|
25
|
-
"benchmark": "node benchmark/benchmark.ts",
|
|
30
|
+
"benchmark": "node --expose-gc benchmark/benchmark.ts",
|
|
26
31
|
"dev": "node_modules/.bin/tsup --dts --watch --onSuccess 'node ./dist/index.mjs'",
|
|
27
32
|
"test": "node --test --experimental-strip-types",
|
|
28
33
|
"test:watch": "npm run test -- --watch",
|
|
@@ -65,6 +70,7 @@
|
|
|
65
70
|
"@biomejs/biome": "1.9.4",
|
|
66
71
|
"@commitlint/cli": "^19.8.1",
|
|
67
72
|
"@commitlint/config-conventional": "^19.8.1",
|
|
73
|
+
"@sinclair/typebox": "^0.34.38",
|
|
68
74
|
"@typescript-eslint/eslint-plugin": "^8.33.0",
|
|
69
75
|
"@typescript-eslint/parser": "^8.33.0",
|
|
70
76
|
"@zod/mini": "^4.0.0-beta.0",
|
|
@@ -72,6 +78,7 @@
|
|
|
72
78
|
"commitizen": "^4.3.1",
|
|
73
79
|
"conventional-changelog-cli": "^5.0.0",
|
|
74
80
|
"cz-conventional-changelog": "^3.3.0",
|
|
81
|
+
"effect": "^3.17.6",
|
|
75
82
|
"git-cz": "^4.9.0",
|
|
76
83
|
"husky": "^9.1.7",
|
|
77
84
|
"joi": "^17.13.3",
|