All files / src xml_utils.ts

100% Statements 27/27
100% Branches 13/13
100% Functions 3/3
100% Lines 27/27

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 282946x 2946x 1873x 2946x 642x 1073x 431x 431x 2946x 1x 176x 176x 3x 3x 173x 173x 173x 173x 173x 173x 173x 1x 1x 8x 8x 8x 8x  
export function xmlToArray(data: any): any[] {
  if (data === undefined) {
    return [];
  } else if (Array.isArray(data)) {
    return data;
  } else {
    return [data];
  }
}
 
export function unescape(str: unknown): string {
  if (typeof str !== "string") {
    return "";
  }
  let result = str.replace(/&/g, "&");
  result = result.replace(/>/g, ">");
  result = result.replace(/&lt;/g, "<");
  result = result.replace(/&quot;/g, "\"");
  result = result.replace(/&apos;/g, "'");
  return result;
}
 
/** the integer value of an XML field, undefined if empty or not a number */
export function toNumber(value: string | undefined): number | undefined {
  const parsed = parseInt(value ?? "", 10);
  return isNaN(parsed) ? undefined : parsed;
}