UNPKG

mikroconf

Version:

A flexible, zero-dependency, type-safe configuration manager that just makes sense.

47 lines (45 loc) 1.19 kB
// src/validators.ts import { existsSync } from "node:fs"; var validators = { /** * Validates that a file exists. */ fileExists: (path) => { return existsSync(path) || `File not found: ${path}`; }, /** * @description Validates that a value is within a range. */ range: (min, max) => { return (value) => { return value >= min && value <= max || `Value must be between ${min} and ${max}`; }; }, /** * @description Validates that a string matches a regex pattern. */ pattern: (regex, message) => { return (value) => { return regex.test(value) || message || `Value must match pattern ${regex}`; }; }, /** * @description Validates that a value is one of a set of allowed values. */ oneOf: (allowedValues, message) => { return (value) => { return allowedValues.includes(value) || message || `Value must be one of: ${allowedValues.join(", ")}`; }; }, /** * @description Validates that a string has minimum length. */ minLength: (min) => { return (value) => { return value.length >= min || `Value must be at least ${min} characters long`; }; } }; export { validators };