All files / src/utils qr-util.js

87.8% Statements 36/41
100% Branches 4/4
66.66% Functions 2/3
87.8% Lines 36/41

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 421x 1x 1x 1x 576x 576x 576x 6357x 6357x 6357x 576x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 72x 72x 108x 108x 72x 1x 1x 1x 1x 1x 1x 1x           1x  
/**
 * Get BCH code digit
 * @param {number} data - numeric data
 */
function getBCHDigit (data) {
  let digit = 0
  while (data !== 0) {
    digit += 1
    data >>>= 1
  }
  return digit
};
 
const G15 = 0b000010100110111
const G18 = 0b001111100100101
const G15_MASK = 0b101010000010010
 
/**
 * Get type info using Reed–Solomon error correction with Bose–Chaudhuri–Hocquenghem codes (BCH codes)
 * @param {number} data - masked error Correction Level info
 * @returns {number} bits of BHC code of type info
 */
export function getBCHTypeInfo (data) {
  let d = data << 10
  while (getBCHDigit(d) - getBCHDigit(G15) >= 0) {
    d ^= (G15 << (getBCHDigit(d) - getBCHDigit(G15)))
  }
  return ((data << 10) | d) ^ G15_MASK
};
 
/**
 * @param {number} data - QR code version
 * @returns {number} bits of BHC code of QR code version
 */
export function getBCHTypeNumber (data) {
  let d = data << 12
  while (getBCHDigit(d) - getBCHDigit(G18) >= 0) {
    d ^= (G18 << (getBCHDigit(d) - getBCHDigit(G18)))
  }
  return (data << 12) | d
};