UNPKG

auto-form-validator

Version:

A smart, zero-setup form validation library for React with automatic rule detection, i18n support, async validation, and UI integration helpers.

51 lines (49 loc) 1.92 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/utils/asyncValidators.ts var asyncValidators_exports = {}; __export(asyncValidators_exports, { createEmailDomainValidator: () => createEmailDomainValidator, createUsernameAvailableValidator: () => createUsernameAvailableValidator }); module.exports = __toCommonJS(asyncValidators_exports); var createUsernameAvailableValidator = (checkFn, message) => { return async (username) => { if (!username.trim()) return null; try { const isAvailable = await checkFn(username); return isAvailable ? null : message || "Username is already taken"; } catch { return null; } }; }; var createEmailDomainValidator = (allowedDomains, message) => { return async (email) => { if (!email.includes("@")) return null; const domain = email.split("@")[1].toLowerCase(); const isAllowed = allowedDomains.some((d) => d.toLowerCase() === domain); return isAllowed ? null : message || "Email domain is not allowed"; }; }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { createEmailDomainValidator, createUsernameAvailableValidator });