UNPKG

mikroconf

Version:

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

71 lines (69 loc) 2.23 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/validators.ts var validators_exports = {}; __export(validators_exports, { validators: () => validators }); module.exports = __toCommonJS(validators_exports); var import_node_fs = require("fs"); var validators = { /** * Validates that a file exists. */ fileExists: (path) => { return (0, import_node_fs.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`; }; } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { validators });