All files / buffers/src/utf8/decodeUtf8 v15.ts

100% Statements 7/7
50% Branches 5/10
100% Functions 1/1
100% Lines 7/7

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 171x   1x 1x 1x   1x 5x 5x                
import v10 from './v10';
 
const hasBuffer = typeof Buffer !== 'undefined';
const utf8Slice = hasBuffer ? Buffer.prototype.utf8Slice : null;
const from = hasBuffer ? Buffer.from : null;
 
export default (buf: Uint8Array, start: number, length: number): string => {
  const end = start + length;
  return length > 8
    ? utf8Slice
      ? utf8Slice.call(buf, start, end)
      : from
        ? from(buf).subarray(start, end).toString('utf8')
        : v10(buf, start, length)
    : v10(buf, start, length);
};