All files / base64/src toBase64.ts

88.88% Statements 8/9
66.66% Branches 2/3
50% Functions 1/2
87.5% Lines 7/8

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 134x 4x   4x   4x     500x 500x 268x    
import {hasBuffer} from './constants';
import {createToBase64} from './createToBase64';
 
const encodeSmall = createToBase64();
 
export const toBase64 = !hasBuffer
  ? (uint8: Uint8Array) => encodeSmall(uint8, uint8.length)
  : (uint8: Uint8Array): string => {
      const length = uint8.length;
      if (length <= 48) return encodeSmall(uint8, length);
      return Buffer.from(uint8).toString('base64');
    };