All files / src/shared/lib/helpers fonts.ts

73.91% Statements 17/23
66.67% Branches 10/15
50% Functions 2/4
70% Lines 14/20

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 34 35 36 37 38 398x                       8x       42x 42x   8x         42x 337x 337x 337x 5x   337x 19x   318x     42x    
export const encodeChar = (
  char: string,
  mapping?: Record<string, number>
): number => {
  let code = char.charCodeAt(0);
  const mappedCode = mapping?.[char.charAt(0)];
  Iif (mappedCode) {
    code = mappedCode;
  }
  return code;
};
 
export const encodeString = (
  inStr: string,
  mapping?: Record<string, number>
) => {
  let output = "";
  const nlStr = inStr
    .replace(/\\([0-9][0-9][0-9])/g, (a, b) =>
      String.fromCharCode(parseInt(b, 8))
    )
    .replace(/\\x([0-9A-Fa-f]+)/g, (a, b) =>
      String.fromCharCode(parseInt(b, 16))
    );
  for (let i = 0; i < nlStr.length; i++) {
    let code = nlStr.charCodeAt(i);
    const mappedCode = mapping?.[nlStr.charAt(i)];
    if (mappedCode) {
      code = mappedCode;
    }
    if (code < 32 || code > 127 || code === 34) {
      output += "\\" + (code & 0xff).toString(8).padStart(3, "0");
    } else {
      output += String.fromCharCode(code);
    }
  }
  return output;
};