0.1.1 • Published 2 years ago

objvl v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

objvl

objvl is a super fast object validator for javascript and typescript! It does not implement JSON schema validation, so if you're specifically looking for a validator which validates JSON Schema, I recommend using ajv. If you just want to validate an object, whether it's coming from a HTTP request or somewhere else, objvl is the right tool for the job!

Check out the guide here!

Example

import { Builders } from "objvl";

// The builder pattern is optional
const validator = Builders.schema({
    name: Builders.string()
        .max(52)
        .err("maxLen", () => "\"name\" property cannot exceed 52 characters."),
    
    age: Builders.number()
        .integer()
        .min(13)
        .err("min", () => "\"age\" property must be above 13.")
});

const [obj, errors] = validator({
    name: "GoogleFeud",
    age: 10
});

// errors: ["\"name\" property cannot exceed 52 characters."]

Features

  • Unlike most other validators, objvl lets you define custom errors, which you receive right after calling the validation function. The errors could be anything - error codes you use later on, objects, or strings!
  • Objvl is 90% faster than joi and 70% faster than ajv.
  • Well tested and secure.

Benchmarks

Ajv version used: 8.9.0
Joi version used: 17.6.0

Compilation Validation

0.1.1

2 years ago

0.1.0

2 years ago