Skip to main content
Glama
input_validations.ts1.16 kB
import { ref, Ref, computed } from "vue"; import * as _ from "lodash-es"; export const VALID_USERNAME_REGEX = /^[a-z0-9._-]+$/i; export type ValidatorArray = Array<{ id: string; check: (v: string) => boolean; message: string; }>; export type ErrorsArray = Array<{ id: string; message: string }>; export const useValidations = ( alwaysValidate: Ref<boolean>, onSetDirty: () => void, onError: (inError: boolean) => void, ) => { const dirty = ref(false); const inError = ref(false); const setDirty = () => { dirty.value = true; onSetDirty(); }; const reallyDirty = computed(() => alwaysValidate.value ? true : dirty.value, ); const setInError = (errors: ErrorsArray) => { let nextInError = false; if (errors.length === 1) { if (_.find(errors, (e) => e.id === "required")) { if (dirty.value) { nextInError = true; } } else { nextInError = true; } } else if (errors.length > 1) { nextInError = true; } inError.value = nextInError; onError(inError.value); }; return { inError, reallyDirty, setDirty, setInError, }; };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/systeminit/si'

If you have feedback or need assistance with the MCP directory API, please join our Discord server