UNPKG

pagamio-frontend-commons-lib

Version:

Pagamio library for Frontend reusable components like the form engine and table container

19 lines (18 loc) 772 B
/** * Checks if a URL segment is an identifier (UUID, numeric ID, or long slug). * @param segment - The URL path segment to check * @returns True if the segment matches any of these patterns: * - UUID format (e.g., '123e4567-e89b-12d3-a456-426614174000') * - Numeric ID (e.g., '123') * - Alphanumeric slug 10 characters or longer (e.g., '3mr8JlGwX6xLozbR1Zx') */ export const isUUIDorID = (segment) => { const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; const idPattern = /^\d+$/; const slugPattern = /^[A-Za-z0-9_-]+$/; if (uuidPattern.test(segment)) return true; if (idPattern.test(segment)) return true; return slugPattern.test(segment) && segment.length >= 10; // Changed to >= 20 };