Skip to content

Comparison With Other Libraries

What sets PureParse apart from other validation libraries is the freedom it gives to the user to choose between type inference and explicit type declarations.

For a more detailed comparison, see the overview.

Performance Benchmarks

PureParse is benchmarked against other validation libraries; see https://moltar.github.io/typescript-runtime-type-benchmarks/.

Here are some results as measured on October, 2024:

  • Chip: Apple M1 Pro
  • Memory: 16 GB

IMPORTANT

The benchmark measures a very specific use case: the performance of parsing/validating a small object with required properties, one of which is another object:

IMPORTANT

Not all parsers in the tables below have the same feature set, so the benchmarks are not entirely comparable.

Loose Assertion

Loose assertion means that the function checks if the object conforms to the schema, and does not invalidate data that contains unknown properties. This corresponds to PureParse's guard functions:

FunctionMops/sRelative to PureParse
PureParse*75.5100%
PureParse5.77.5%
Zod1.121.4%
io-ts3.54.7%
Ajv*4965%
Yup*84120%
Typia**101136%

* Just-in-time (JIT) compilation
** Ahead-of-time compilation

Safe Parsing

Safe parsing means that a copy of the parsed data is returned, which contains only those properties that were declared. This protects against prototype pollution, and corresponds to PureParse's parsers.

FunctionMops/sRelative to PureParse
PureParse*28.4100%
PureParse4.15.5%
Zod1.133.9%
io-ts
Ajv*†
Yup*81.4286%
Typia**57.7203%

* Just-in-time (JIT) compilation
** Ahead-of-time compilation
†No benchmark data available—the operation might not be supported by the library

Size Comparison

LibraryMinified + Zipped
PureParse5 kB
Zod21 kB
Joi236 kB
Ajv32 kB
Yup60 kB
Typia*

*Typia is a compiler

NOTE

Even though other libraries might be much larger, the final contribution to the bundle size will depend on whether the library is tree-shakeable, how tree-shakeable it is, and how many features of the library are used in the application.

Zod

In Zod, it is not possible to annotate the schemas with a type alias—you are instead supposed to derive your types from the schemas, which has the drawback that it couples your type aliases to Zod.

Zod is more difficult to extend with custom validation logic. (In PureParse, you just implement a function of the Parse<?> or Guard<?> type.)

Joi

In Joi, you can annotate the schemas with a type alias, but it does not validate the schema completely. As such, there is no real type safety.

Joi cannot infer the type from a schema.

Ajv

Ajv is a JSON validator and conforms to the JSON Schema specification. However, the JSON schema syntax is verbose, does not interoperate well with TypeScript, and does not lend itself well to customization of validation logic.

Yup

Yup cannot correctly infer the type from schemas—you can infer something, but it is not 100% correct.

Yup does allow asynchronous validation.

Typia

Typia is a compiler that generates validation logic based on type aliases. The resulting code is fast, and the boilerplate is minimal, but customization happens in a non-standard comments and so-called type-tags—also non-standard. In PureParse, this happens in regular JavaScript code.

When working with immutable data structures, PureParse can outperform Typia thanks to memoization.

Typia does not have error messages.