All files / packages/core/src/utilities getVolumeId.ts

100% Statements 5/5
100% Branches 4/4
100% Functions 1/1
100% Lines 5/5

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              1x 24x 24x       24x 24x    
/**
 * Retrieves the volume ID from a target ID. Target Id is not only
 * volumeId but might include other information, but it starts with volumeId.
 *
 * @param targetId - The target ID from which to extract the volume ID.
 * @returns The volume ID extracted from the target ID.
 */
export const getVolumeId = (targetId: string) => {
  const prefix = 'volumeId:';
  const str = targetId.includes(prefix)
    ? targetId.substring(prefix.length)
    : targetId;
 
  const index = str.indexOf('?');
  return index === -1 ? str : str.substring(0, index);
};