All files / src/common encoding-ascii.ts

100% Statements 13/13
100% Branches 0/0
100% Functions 2/2
100% Lines 11/11

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 1968x 44x 44x   694x   44x     68x 3x 3x   3x 21x   3x    
export function asciiToBytes(str: string) {
  const byteArray = [];
  for (let i = 0; i < str.length; ++i) {
    // Node's code seems to be doing this and not & 0x7F..
    byteArray.push(str.charCodeAt(i) & 0xff);
  }
  return new Uint8Array(byteArray);
}
 
export function bytesToAscii(buffer: Uint8Array) {
  let ret = '';
  const end = buffer.length;
 
  for (let i = 0; i < end; ++i) {
    ret += String.fromCharCode(buffer[i] & 0x7f);
  }
  return ret;
}