variable-value-validator

Minimal schema validation for TypeScript and JavaScript.

Stale Pure Nim score 23/100 · last commit 2025-05-20 · 1 stars · tests present · no docs generated

Summary

Latest Version Unknown
License Unknown
CI Status Failing
Stars 1
Forks 0
Open Issues 0
Last Commit 2025-05-20
Downloads 0
Last Indexed 2026-08-12 05:10

Installation

nimble install variable-value-validator
choosenim install variable-value-validator
git clone https://gitlab.com/alexandre-fernandez/variable-value-validator

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
variable-value-validator - - - - - - -

README

variable-value-validator

Minimal schema validation for TypeScript and JavaScript.

What is it ?

variable-value-validator is a minimal (standard-schema compliant) schema validation library enabling type-safe code with unsafe data such as serialized data, API responses, and more.

Example

// defining a schema describing the user object :
const userSchema = vvv.object({
    id: vvv.number(),
    name: vvv.string(),
    isActive: vvv.boolean({ optional: true }),
    tags: vvv.array(vvv.string()),
})

// if a TypeScript type is needed it can be inferred from the schema :
type User = SchemaToType<typeof userSchema>

// example unsafe data :
const response = await fetch("api.com/user/1")
const user = await response.json()

if (userSchema.guard(user)) {
    // `user` is now guaranteed to be of type User
}

Installation

# npm
npm install variable-value-validator
# yarn
yarn add variable-value-validator
# pnpm
pnpm add variable-value-validator

Schema creation methods

  • Primitives: vvv.string(), vvv.number(), vvv.boolean(), vvv.undefined(), vvv.null(), vvv.nullish() (null or undefined), vvv.function() and vvv.unknown() (always valid).
  • Objects: vvv.object(shape: Record<string, Schema>), vvv.array(items: Schema[]), record(values: Schema[]), set(values: Schema[]), map(keys: Schema[], values: Schema[]), vvv.instance(constructor: new (...args: any[]) => Object) (class instances).
  • Other: vvv.union(members: Schema[]) ("OR" schema association).

All of the schema creation methods accept an optional options object which can have the following optional properties:

  • optional: Marks the property as optional when used with vvv.object (e.g. vvv.object({ foo: string({ optional: true }) })).
  • predicates: A function or an array of functions to add custom validation (e.g. vvv.number({ predicates: (num) => Number.isInteger(num) })).

Schemas

Every schema has the following methods :

  • guard(value: unknown): A type guard for that schema. If the value is valid in respect to that schema it will return true, else it will return false.
  • errors(value: unknown): An array of issues, a valid value returns an empty array.