Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

@thi.ng/validate

npm version npm downloads Mastodon Follow

Note

This is one of 215 standalone projects, maintained as part of the @thi.ng/umbrella ecosystem and anti-framework.

🚀 Please help me to work full-time on these projects by sponsoring me. Thank you! ❤️

About

Functional, composable, fully extensible, predicate-based value validation with customizable error messages.

Based on ideas from older thi.ng/validate-x Clojure/ClojureScript library...

Basic usage:

import * as v from "@thi.ng/validate";

// build validation function to check if a value is...
const check = v.validator(
  // a plain object
  v.isObject(),
  // and its keys are matching given validation criteria:
  v.hasKeysOf({
    // number in [0,1000] range
    id: [v.isNumber(), v.isInRange(1, 1000)],
    // optional title string (i.e. nullish values allowed)
    title: v.optional(v.isString()),
    // enum type
    type: v.isEnum(["file", "url", "record"])
  })
);

try {

  check({ id: 123, title: "abc", type: "file" });
  // true

  // validation will fail:
  check({ id: 999, type: "foo" });

} catch(e) {
  console.warn(e);
}

// validation error: required value to be one of: file, url, record (key: type)

Built-in validators

Combinators

Status

ALPHA - bleeding edge / work-in-progress

Search or submit any issues for this package

Installation

yarn add @thi.ng/validate

ESM import:

import * as val from "@thi.ng/validate";

Browser ESM import:

<script type="module" src="https://esm.run/@thi.ng/validate"></script>

JSDelivr documentation

For Node.js REPL:

const val = await import("@thi.ng/validate");

Package sizes (brotli'd, pre-treeshake): ESM: 1.19 KB

Dependencies

Note: @thi.ng/api is in most cases a type-only import (not used at runtime)

API

Generated API docs

Authors

If this project contributes to an academic publication, please cite it as:

@misc{thing-validate,
  title = "@thi.ng/validate",
  author = "Karsten Schmidt",
  note = "https://thi.ng/validate",
  year = 2026
}

License

© 2026 Karsten Schmidt // Apache License 2.0