All files / source/Caffeine.SourceMap Base64.js

100% Statements 24/24
100% Branches 12/12
100% Functions 11/11
100% Lines 24/24

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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91  4x 4x 4x                         4x               256x   43x     38x     45x       43x         29x   43x 43x                     45x 45x 45x 45x     39x     13x 13x                             6x 6x 6x 29x   6x          
"use strict";
let Caf = require("caffeine-script-runtime");
Caf.defMod(module, () => {
  return (() => {
    let vlqBaseShift,
      vlqBase,
      vlqBaseMask,
      vlqContinuationBit,
      intToCharMap,
      charMapToInt,
      getBase64char,
      toVlqSigned,
      fromVlqSigned,
      encodeVlq,
      readVlq,
      readVlqSequence;
    return {
      vlqBaseShift: (vlqBaseShift = 5),
      vlqBase: (vlqBase = 1 << vlqBaseShift),
      vlqBaseMask: (vlqBaseMask = vlqBase - 1),
      vlqContinuationBit: (vlqContinuationBit = vlqBase),
      intToCharMap: (intToCharMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(
        ""
      )),
      charMapToInt: (charMapToInt = Caf.object(intToCharMap, (v, k) => k)),
      getBase64char: (getBase64char = function(number) {
        return intToCharMap[number];
      }),
      toVlqSigned: (toVlqSigned = function(value) {
        return value < 0 ? (-value << 1) + 1 : value << 1;
      }),
      fromVlqSigned: (fromVlqSigned = function(value) {
        return value & 1 ? 0 - (value >> 1) : value >> 1;
      }),
      encodeVlq: (encodeVlq = function(value) {
        let encoded, vlq;
        return value === 0
          ? "A"
          : ((encoded = ""),
            (vlq = toVlqSigned(value)),
            (() => {
              while (vlq > 0) {
                let digit;
                digit = vlq & vlqBaseMask;
                encoded += getBase64char(
                  0 < (vlq >>>= vlqBaseShift)
                    ? digit | vlqContinuationBit
                    : digit
                );
              }
            })(),
            encoded);
      }),
      readVlq: (readVlq = function(string, resultObject = { index: 0 }) {
        let index, number, shiftAmount, read;
        ({ index } = resultObject);
        number = 0;
        shiftAmount = 0;
        return charMapToInt[string[index]] != null
          ? ((read = null),
            (() => {
              while (
                vlqContinuationBit & (read = charMapToInt[string[index++]])
              ) {
                number += (read & vlqBaseMask) << shiftAmount;
                shiftAmount += vlqBaseShift;
              }
            })(),
            (resultObject.index = index),
            (resultObject.value = fromVlqSigned(
              number + (read << shiftAmount)
            )),
            resultObject)
          : undefined;
      }),
      readVlqSequence: (readVlqSequence = function(
        string,
        resultObject = { index: 0 }
      ) {
        let out, result;
        out = [];
        result = null;
        while ((result = readVlq(string, resultObject))) {
          out.push(result.value);
        }
        return out;
      })
    };
  })();
});