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! ❤️
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)hasKeysOf()hasRequiredKeys()isArray()isArrayOf()isBoolean()isDate()isEnum()isInRange()isLength()isMaxLength()isMinLength()isMinMaxLength()isNegative()isNonNegative()isNonPositive()isNullish()isNumber()isObject()isObjectOf()isPositive()isRegExp()isString()isTypedArray()isU8Array()isUndefined()matchesRegexp()
ALPHA - bleeding edge / work-in-progress
Search or submit any issues for this package
yarn add @thi.ng/validateESM import:
import * as val from "@thi.ng/validate";Browser ESM import:
<script type="module" src="https://esm.run/@thi.ng/validate"></script>For Node.js REPL:
const val = await import("@thi.ng/validate");Package sizes (brotli'd, pre-treeshake): ESM: 1.19 KB
Note: @thi.ng/api is in most cases a type-only import (not used at runtime)
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
}© 2026 Karsten Schmidt // Apache License 2.0