All files / metadata/src/utilities imageIdToURI.ts

90% Statements 9/10
83.33% Branches 5/6
100% Functions 1/1
90% Lines 9/10

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 25 26 27 28 29 30 31128x                 34886x       34886x   34886x 376x     34510x         34510x 13969x     20541x    
const schemePrefixPattern = /^[a-zA-Z]+:/;
 
/**
 * Removes the data loader scheme from the imageId
 *
 * @param imageId - Image ID
 * @returns imageId without the data loader scheme, or empty string if imageId is falsy
 */
export default function imageIdToURI(imageId: string): string {
  Iif (!imageId) {
    return '';
  }
 
  const firstPrefixMatch = imageId.match(schemePrefixPattern);
 
  if (!firstPrefixMatch) {
    return imageId;
  }
 
  const remainder = imageId.substring(firstPrefixMatch[0].length);
 
  // Only strip one scheme if another scheme-like prefix remains.
  // Example: wadouri:derived:uuid -> derived:uuid
  // Example: derived:uuid -> derived:uuid
  if (!schemePrefixPattern.test(remainder)) {
    return imageId;
  }
 
  return remainder;
}