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

0% Statements 0/10
0% Branches 0/10
0% Functions 0/1
0% Lines 0/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 31 32                                                               
import { ScalingParameters } from '../types';
 
/**
 * If the scalar data is a Uint8Array, return 'Uint8Array'. If the scalar data is a
 * Float32Array, return 'Float32Array'. If the scalar data is a Int16Array, return
 * 'Int16Array'. If the scalar data is a Uint16Array, return 'Uint16Array'. If the
 * scalar data is none of the above, throw an error.
 * @param {ScalingParameters} scalingParameters - {
 * @param {any} [scalarData] - The data to be converted.
 * @returns The data type of the scalar data.
 */
export default function getScalarDataType(
  scalingParameters: ScalingParameters,
  scalarData?: any
): string {
  let type;
 
  if (scalarData && scalarData instanceof Uint8Array) {
    type = 'Uint8Array';
  } else if (scalarData instanceof Float32Array) {
    type = 'Float32Array';
  } else if (scalarData instanceof Int16Array) {
    type = 'Int16Array';
  } else if (scalarData instanceof Uint16Array) {
    type = 'Uint16Array';
  } else {
    throw new Error('Unsupported array type');
  }
 
  return type;
}