TypeScript
Extensibility through classes

by Benny Neugebauer

class ValidationUtil {
  public static PATTERN = {
    UUID_V4: '[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}',
  };

  static isUUIDv4(candidate: string): boolean {
    const uuidv4Regex = new RegExp(`^${ValidationUtil.PATTERN.UUID_V4}$`, 'i');
    return uuidv4Regex.test(candidate);
  }
}

export {ValidationUtil}

export const PATTERN = {
  UUID_V4: '[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}',
};

export function isUUIDv4(candidate: string): boolean {
  const uuidv4Regex = new RegExp(`^${PATTERN.UUID_V4}$`, 'i');
  return uuidv4Regex.test(candidate);
}