<commit_before>var Utils = require('./utils')

var BLOCK_CHAR = {
  WW: ' ',
  WB: '▄',
  BB: '█',
  BW: '▀'
}

function getBlockChar (top, bottom) {
  if (top && bottom) return BLOCK_CHAR.BB
  if (top && !bottom) return BLOCK_CHAR.BW
  if (!top && bottom) return BLOCK_CHAR.WB
  return BLOCK_CHAR.WW
}

exports.render = function (qrData, options, cb) {
  var size = qrData.modules.size
  var data = qrData.modules.data

  var opts = Utils.getOptions(options)

  var output = ''
  var hMargin = Array(size + (opts.margin * 2) + 1).join(BLOCK_CHAR.WW)
  hMargin = Array((opts.margin / 2) + 1).join(hMargin + '\n')

  var vMargin = Array(opts.margin + 1).join(BLOCK_CHAR.WW)

  output += hMargin
  for (var i = 0; i < size; i += 2) {
    output += vMargin
    for (var j = 0; j < size; j++) {
      var topModule = data[i * size + j]
      var bottomModule = data[(i + 1) * size + j]

      output += getBlockChar(topModule, bottomModule)
    }

    output += vMargin + '\n'
  }

  output += hMargin.slice(0, -1)

  if (typeof cb === 'function') {
    cb(null, output)
  }

  return output
}

exports.renderToFile = function renderToFile (path, qrData, options, cb) {
  if (typeof cb === 'undefined') {
    cb = options<commit_msg>feat: inverting colors on utf8 rendered codes<commit_after>var Utils = require('./utils')

var BLOCK_CHAR = {
  WW: ' ',
  WB: '▄',
  BB: '█',
  BW: '▀'
}

var INVERTED_BLOCK_CHAR = {
  BB: ' ',
  BW: '▄',
  WW: '█',
  WB: '▀'
}

function getBlockChar (top, bottom, blocks) {
  if (top && bottom) return blocks.BB
  if (top && !bottom) return blocks.BW
  if (!top && bottom) return blocks.WB
  return blocks.WW
}

exports.render = function (qrData, options, cb) {
  var opts = Utils.getOptions(options)
  var blocks = BLOCK_CHAR
  if (opts.color.dark.hex === '#ffffff' || opts.color.light.hex === '#000000') {
    blocks = INVERTED_BLOCK_CHAR
  }

  var size = qrData.modules.size
  var data = qrData.modules.data

  var output = ''
  var hMargin = Array(size + (opts.margin * 2) + 1).join(blocks.WW)
  hMargin = Array((opts.margin / 2) + 1).join(hMargin + '\n')

  var vMargin = Array(opts.margin + 1).join(blocks.WW)

  output += hMargin
  for (var i = 0; i < size; i += 2) {
    output += vMargin
    for (var j = 0; j < size; j++) {
      var topModule = data[i * size + j]
      var bottomModule = data[(i + 1) * size + j]

      output += getBlockChar(topModule, bottomModule, blocks)
    }

    output += vMargin + '\n'
  }

  output += hMargin.slice(0, -1)

  if (typeof cb === 'function') {
    cb(null, output)
  }

  return output
}

exports.renderToFile = function renderToFile (path, qrData, options, cb) {
  if (typeof cb === 'undefined') {
    cb = options
{'fraction_non_alphanumeric': 0.1637037037037037, 'fraction_numerical': 0.01074074074074074, 'mean_word_length': 2.9546120058565153, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7446094', 'n_tokens_mistral': 1038, 'n_tokens_neox': 994, 'n_words': 274}