All files / metadata/src/utilities/metadataProvider dicomSplit.ts

0% Statements 0/1
0% Branches 0/5
0% Functions 0/1
0% Lines 0/1

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                                           
/**
 * Converts a value into an array by splitting on backslashes when needed.
 * Use for DICOM multi-valued attributes (e.g. value representations that are
 * backslash-separated). When a source supplies a single string with backslashes
 * instead of separate values (non-conforming to the DICOM standard), this
 * normalizes it to an array of strings to match the standard representation.
 *
 * - If `value` is already an array, it is returned unchanged.
 * - If `value` is a string, it is split on '\\' and the resulting array is returned.
 * - Otherwise `value` is returned as-is.
 *
 * @param value - A string (possibly with '\\'), an array, or another value.
 * @returns An array of strings when given a backslash-separated string, otherwise the original value or array.
 */
export function dicomSplit(value) {
  return (
    (Array.isArray(value) && value) ||
    (typeof value === 'string' && value.split('\\')) ||
    value
  );
}