Vitesse
Links
what | where |
---|---|
documentation | http://christkv.github.io/vitesse/ |
api-doc | http://christkv.github.io/vitesse/api/ |
source | https://github.com/christkv/vitesse |
Description
Vitesse is a high speed object validation framework. It's meant as a target for developers to build validation frameworks or DSL (Domain specific languages) while being able to leverage close to hand-coded performance.
- Joi test x 139,410 ops/sec ±1.86% (85 runs sampled)
- Compiler test optimized x 2,555,137 ops/sec ±1.50% (93 runs sampled)
- Closure compiler test x 2,745,918 ops/sec ±0.86% (83 runs sampled)
- Manual vitesse test x 2,588,368 ops/sec ±0.83% (92 runs sampled)
The goal of this module is to allow you to avoid the cost of interpreting a set of validation rules by ahead of time compile it (AOT) using eval, allowing you to get close to the performance of manually writing validation code.
With Vitesse as your target you can define whatever DSL you want and have Vitesse optimize it for maximum performance
It's easy to write your own custom DSL. Below is a simple example of a possible custom validation DSL using ES6.
"use strict" var v = StringNode = vStringNode ObjectNode = vObjectNode IntegerNode = vIntegerNode NumberNode = vNumberNode ArrayNode = vArrayNode VitesseCompiler = vCompiler; { } static { return ; } static { return ; } static { return ; } { } { options = options || {}; optionsoptimizer = true; // Get the compiler return ; } { thisobject = null null typeCheck:true; } { forvar name in fields thisobject; return this; } { thisobject; return this; } { thisobject = null null typeCheck:true } { thisobject; return this; } { thisobject = null null typeCheck:true } { thisobject; return this; } moduleexports = Validator: Validator Compiler: Compiler
This simple custom DSL let's you create validations of the following style.
var validator = Validator object ; var compiler = ;var validator = compiler;assert;
Available Nodes
Object Node
The object node defines that validations for an object.
var objectNode = null null typeCheck:true
The following methods are available