@sandsoftwaresolutions/validation
v0.1.0
Published
Composable, dependency-free validation helpers.
Downloads
169
Maintainers
Readme
@sandsoftwaresolutions/validation
Tiny, composable form and API-input validators with no runtime dependencies.
Install
npm install @sandsoftwaresolutions/validationUsage
import { email, minLength, required, validate } from "@sandsoftwaresolutions/validation";
const result = validate(form.password, [required, minLength(12)]);
if (!result.valid) showError(result.message);
validate(form.email, [required, email]);API
required(value, message?)rejectsnull,undefined, and empty/whitespace-only strings.email(value, message?)performs a lightweight email-address check.minLength(minimum, message?)creates a string validator.validate(value, validators)runs validators in order and returns the first failure.
Every result is either { valid: true } or { valid: false, message }, which makes it easy to use in forms and HTTP handlers. Validate and normalize security-sensitive input on the server as well.
