All files / src/modes byte.mode.js

100% Statements 25/25
100% Branches 3/3
100% Functions 2/2
100% Lines 25/25

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 261x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 6x 6x 1x 1x 1x 1x 1x 1x 10x 10x 110x 110x 10x  
import { MODE_8BIT_BYTE } from './mode-bits.constants.js'
import { textToBytes } from '../utils/text-decode-encode.util.js'
 
/**
 * Create QR code byte mode object
 * @param {string} data - data of mode object
 * @returns {import('./mode-bits.constants.js').ModeObject} created mode object
 */
export const Qr8BitByte = (data) => Object.freeze({
  data,
  mode: MODE_8BIT_BYTE,
  length: data.length,
  write: writeDataToBitBuffer.bind(null, textToBytes(data)),
})
 
/**
 * Writes byte data to bit buffer that will be used to generate the QR code
 * @param {Uint8Array} data - Qr8BitByte mode object data byte array
 * @param {import("./../utils/qr-bit-buffer.js").QrBitBuffer} buffer - target bit buffer
 */
function writeDataToBitBuffer (data, buffer) {
  for (const byte of data) {
    buffer.put(byte, 8)
  }
}