All files / dicomImageLoader/src/imageLoader/wadors/metaData getValue.ts

87.5% Statements 7/8
90% Branches 9/10
100% Functions 1/1
87.5% Lines 7/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 25 26 27 28 29 30 31 32 33                              1073303x 1073303x 113376x     959927x 376x     959551x       959551x        
import type { WADORSMetaDataElement } from '../../../types';
 
/**
 * Returns the raw value
 *
 * @param element - The javascript object for the specified element in the metadata
 * @param [index] - the index of the value in a multi-valued element, default is 0
 * @param [defaultValue] - The default value to return if the element does not exist
 * @returns {*}
 */
function getValue<ReturnType = unknown>(
  element: WADORSMetaDataElement,
  index?: number,
  defaultValue?: ReturnType
): ReturnType {
  index = index || 0;
  if (!element) {
    return defaultValue;
  }
  // Value is not present if the attribute has a zero length value
  if (!element.Value) {
    return defaultValue;
  }
  // make sure we have the specified index
  Iif (Array.isArray(element.Value) && element.Value.length <= index) {
    return defaultValue;
  }
 
  return element.Value[index] as ReturnType;
}
 
export default getValue;