
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
ex-validator
Advanced tools
A lightweight and flexible TypeScript validation library for validating strings, numbers, booleans, arrays, objects, dates, tuples, URLs, emails, and custom rules. Supports required and optional fields, min/max constraints, enums, custom checks, and chain
npm i ex-validator
import { ex, reqStr, optNum, reqEmail, optURL } from "ex-validator";
const { ex, reqStr, optNum, reqEmail, optURL } = require("ex-validator");
import { reqStr, reqNum, reqBool } from "ex-validator";
const nameValidation = reqStr("Luna", "Name is required", 3, 50);
console.log(nameValidation);
// { valid: true, errors: [] }
const ageValidation = reqNum(15, "Age is required", 18, 99);
console.log(ageValidation);
// { valid: false, errors: ["Must be at least 18"] }
import { ex } from "ex-validator";
const validation = ex("hello")
.required()
.type("string")
.min(3)
.max(10)
.run();
console.log(validation);
// { valid: true, errors: [] }
ex(value).required("Field is required").run();
ex([1, 2, 3]).type("tuple").run();
ex(new Date()).type("date").run();
ex(value).type("array", "Must be an array").run();
ex("hello").min(3).max(10).run();
ex([1, 2]).between(1, 5).run();
ex(42).between(10, 50).run();
ex("blue").enum(["red", "green", "blue"]).run();
ex(10).custom((val) => val % 2 === 0, "Must be even").run();
const result = ex(value).required().type("string").run();
console.log(result.valid, result.errors);
// min and max parameters are optional : reqStr(value, msg, min, max)
reqStr("hello", "Name is required", 3, 20);
reqEmail("test@example.com", "Invalid email address");
reqURL("https://example.com", "Invalid URL");
optStr("optional value", "Invalid string", 2, 10);
optEmail("test@example.com", "Invalid email address");
optURL("https://example.com", "Invalid URL");
reqTuple([1, "two"], "Invalid tuple").run();
reqTuple([1, 2]).custom(
(val) => Array.isArray(val) && val.length === 2 && typeof val[0] === "number",
"Tuple must have a number and a string"
).run();
reqDate(new Date(), "Invalid date").run();
optDate(undefined, "Invalid date").run();
reqURL("https://example.com", "Invalid URL").run();
optURL("ftp://example.com", "Invalid URL").run();
reqEmail("test@example.com").run();
optEmail("invalid-email").run();
import { ex } from "ex-validator";
const result = ex("hello123")
.custom((val) => /^[a-z]+$/.test(val as string), "Only lowercase letters allowed")
.run();
console.log(result);
// { valid: false, errors: ["Only lowercase letters allowed"] }
ex("abc")
.required()
.type("string")
.min(2)
.max(10)
.custom((val) => val.includes("a"), "Must contain 'a'")
.run();
interface ValidationResult {
valid: boolean;
errors: string[];
}
FAQs
A lightweight and flexible TypeScript validation library for validating strings, numbers, booleans, arrays, objects, dates, tuples, URLs, emails, and custom rules. Supports required and optional fields, min/max constraints, enums, custom checks, and chain
We found that ex-validator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.