All files / kernel-ui/src utils.ts

88.88% Statements 8/9
100% Branches 2/2
50% Functions 1/2
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24                  15x 2x     13x 13x 13x   1x       1x 1x  
import { makeCounter } from '@metamask/kernel-utils';
 
/**
 * Validates a bundle URL.
 *
 * @param url - The bundle URL to validate
 * @returns Whether the URL is a valid bundle URL
 */
export function isValidBundleUrl(url?: string): boolean {
  if (!url) {
    return false;
  }
 
  try {
    const parsedUrl = new URL(url);
    return parsedUrl.pathname.trim().toLowerCase().endsWith('.bundle');
  } catch {
    return false;
  }
}
 
const idCounter = makeCounter();
export const nextMessageId = (): string => `ui:${idCounter()}`;