Skip to content

Commit

Permalink
Merge pull request #29 from adelmojnr/master
Browse files Browse the repository at this point in the history
Alterando variáveis de var para const e let no arquivo barcode.js
  • Loading branch information
lucianopf authored Jun 27, 2019
2 parents 8a5e558 + 09c35bc commit 4866b81
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions lib/barcode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
exports.binaryRepresentationForBarcodeData = function (barcodeData) {
var digits = {
const digits = {
0: '00110',
1: '10001',
2: '01001',
Expand All @@ -12,17 +12,17 @@ exports.binaryRepresentationForBarcodeData = function (barcodeData) {
9: '01010'
}

if (barcodeData.length % 2 != 0) {
if (barcodeData.length % 2 !== 0) {
barcodeData = '0' + barcodeData
}

var binaryDigits = '0000'
let binaryDigits = '0000'
// Start of barcode
for (var i = 0; i < barcodeData.length; i += 2) {
var digit1 = digits[parseInt(barcodeData[i])]
var digit2 = digits[parseInt(barcodeData[i + 1])]
for (let i = 0; i < barcodeData.length; i += 2) {
const digit1 = digits[parseInt(barcodeData[i])]
const digit2 = digits[parseInt(barcodeData[i + 1])]

for (var j = 0; j < digit1.length; j++) {
for (let j = 0; j < digit1.length; j++) {
binaryDigits += digit1[j] + digit2[j]
}
}
Expand All @@ -35,9 +35,9 @@ exports.binaryRepresentationForBarcodeData = function (barcodeData) {

// Convert a value to a little endian hexadecimal value
exports._getLittleEndianHex = function (value) {
var result = []
const result = []

for (var bytes = 4; bytes > 0; bytes--) {
for (let bytes = 4; bytes > 0; bytes--) {
result.push(String.fromCharCode(value & 0xff))
value >>= 0x8
}
Expand All @@ -46,7 +46,7 @@ exports._getLittleEndianHex = function (value) {
}

exports._bmpHeader = function (width, height) {
var numFileBytes = exports._getLittleEndianHex(width * height)
const numFileBytes = exports._getLittleEndianHex(width * height)
width = exports._getLittleEndianHex(width)
height = exports._getLittleEndianHex(height)

Expand All @@ -69,25 +69,25 @@ exports._bmpHeader = function (width, height) {
}

exports.bmpLineForBarcodeData = function (barcodeData) {
var binaryRepresentation = exports.binaryRepresentationForBarcodeData(barcodeData)
const binaryRepresentation = exports.binaryRepresentationForBarcodeData(barcodeData)

var bmpData = []
var black = true
var offset = 0
let bmpData = []
let black = true
let offset = 0

for (var i = 0; i < binaryRepresentation.length; i++) {
var digit = binaryRepresentation[i]
var color = black ? String.fromCharCode(0, 0, 0, 0) : String.fromCharCode(255, 255, 255, 0)
var pixelsToDraw = (digit == '0') ? 1 : 3
for (let i = 0; i < binaryRepresentation.length; i++) {
const digit = binaryRepresentation[i]
const color = black ? String.fromCharCode(0, 0, 0, 0) : String.fromCharCode(255, 255, 255, 0)
let pixelsToDraw = (digit === '0') ? 1 : 3

for (var j = 0; j < pixelsToDraw; j++) {
for (let j = 0; j < pixelsToDraw; j++) {
bmpData[offset++] = color
}

black = !black
}

var bmpHeader = exports._bmpHeader(offset - 1, 1)
var bmpBuffer = new Buffer(bmpHeader + bmpData.join(''), 'binary')
const bmpHeader = exports._bmpHeader(offset - 1, 1)
const bmpBuffer = new Buffer(bmpHeader + bmpData.join(''), 'binary')
return bmpBuffer.toString('base64')
}

0 comments on commit 4866b81

Please sign in to comment.