UNPKG

@mantine/form

Version:

Mantine form management library

28 lines (27 loc) 983 B
"use client"; //#region packages/@mantine/form/src/validators/is-url/is-url.ts function isUrl(optionsOrError, error) { let _options = {}; let _error; if (optionsOrError !== null && optionsOrError !== void 0 && typeof optionsOrError === "object" && !Array.isArray(optionsOrError) && ("protocols" in optionsOrError || "allowLocalhost" in optionsOrError)) { _options = optionsOrError; _error = error || true; } else _error = optionsOrError || true; const protocols = _options.protocols ?? ["http", "https"]; const allowLocalhost = _options.allowLocalhost ?? false; return (value) => { if (typeof value !== "string") return _error; try { const url = new URL(value); const protocol = url.protocol.replace(":", ""); if (!protocols.includes(protocol)) return _error; if (!allowLocalhost && url.hostname === "localhost") return _error; return null; } catch { return _error; } }; } //#endregion exports.isUrl = isUrl; //# sourceMappingURL=is-url.cjs.map