Skip to content

Commit

Permalink
Release v3.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lindell committed May 9, 2016
1 parent 3838d6a commit b39e9e8
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 35 deletions.
53 changes: 37 additions & 16 deletions bin/browser/JsBarcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -1471,37 +1471,45 @@
// https://en.wikipedia.org/wiki/Code_39#Encoding

var CODE39 = function () {
function CODE39(string) {
function CODE39(string, options) {
_classCallCheck(this, CODE39);

this.string = string.toUpperCase();

// Enable mod43 checksum?
this.mod43Enabled = options.mod43 || false;

// All characters. The position in the array is the (checksum) value
this.characters = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "-", ".", " ", "$", "/", "+", "%", "*"];

// The decimal representation of the characters, is converted to the
// corresponding binary with the getEncoding function
this.encodings = {
"0": 20957, "1": 29783, "2": 23639, "3": 30485,
"4": 20951, "5": 29813, "6": 23669, "7": 20855,
"8": 29789, "9": 23645, "A": 29975, "B": 23831,
"C": 30533, "D": 22295, "E": 30149, "F": 24005,
"G": 21623, "H": 29981, "I": 23837, "J": 22301,
"K": 30023, "L": 23879, "M": 30545, "N": 22343,
"O": 30161, "P": 24017, "Q": 21959, "R": 30065,
"S": 23921, "T": 22385, "U": 29015, "V": 18263,
"W": 29141, "X": 17879, "Y": 29045, "Z": 18293,
"-": 17783, ".": 29021, " ": 18269, "$": 17477,
"/": 17489, "+": 17681, "%": 20753, "*": 35770
};
this.encodings = [20957, 29783, 23639, 30485, 20951, 29813, 23669, 20855, 29789, 23645, 29975, 23831, 30533, 22295, 30149, 24005, 21623, 29981, 23837, 22301, 30023, 23879, 30545, 22343, 30161, 24017, 21959, 30065, 23921, 22385, 29015, 18263, 29141, 17879, 29045, 18293, 17783, 29021, 18269, 17477, 17489, 17681, 20753, 35770];
}

// Get the binary representation of a character by converting the encodings
// from decimal to binary


CODE39.prototype.getEncoding = function getEncoding(character) {
return this.encodings[character].toString(2);
return this.getBinary(this.characterValue(character));
};

CODE39.prototype.getBinary = function getBinary(characterValue) {
return this.encodings[characterValue].toString(2);
};

CODE39.prototype.getCharacter = function getCharacter(characterValue) {
return this.characters[characterValue];
};

CODE39.prototype.characterValue = function characterValue(character) {
return this.characters.indexOf(character);
};

CODE39.prototype.encode = function encode() {
var string = this.string;

// First character is always a *
var result = this.getEncoding("*");

Expand All @@ -1510,12 +1518,25 @@
result += this.getEncoding(this.string[i]) + "0";
}

// Calculate mod43 checksum if enabled
if (this.mod43Enabled) {
var checksum = 0;
for (var i = 0; i < this.string.length; i++) {
checksum += this.characterValue(this.string[i]);
}

checksum = checksum % 43;

result += this.getBinary(checksum) + "0";
string += this.getCharacter(checksum);
}

// Last character is always a *
result += this.getEncoding("*");

return {
data: result,
text: this.string
text: string
};
};

Expand Down
2 changes: 1 addition & 1 deletion bin/browser/JsBarcode.min.js

Large diffs are not rendered by default.

53 changes: 37 additions & 16 deletions bin/node/barcodes/CODE39/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,45 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
// https://en.wikipedia.org/wiki/Code_39#Encoding

var CODE39 = function () {
function CODE39(string) {
function CODE39(string, options) {
_classCallCheck(this, CODE39);

this.string = string.toUpperCase();

// Enable mod43 checksum?
this.mod43Enabled = options.mod43 || false;

// All characters. The position in the array is the (checksum) value
this.characters = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "-", ".", " ", "$", "/", "+", "%", "*"];

// The decimal representation of the characters, is converted to the
// corresponding binary with the getEncoding function
this.encodings = {
"0": 20957, "1": 29783, "2": 23639, "3": 30485,
"4": 20951, "5": 29813, "6": 23669, "7": 20855,
"8": 29789, "9": 23645, "A": 29975, "B": 23831,
"C": 30533, "D": 22295, "E": 30149, "F": 24005,
"G": 21623, "H": 29981, "I": 23837, "J": 22301,
"K": 30023, "L": 23879, "M": 30545, "N": 22343,
"O": 30161, "P": 24017, "Q": 21959, "R": 30065,
"S": 23921, "T": 22385, "U": 29015, "V": 18263,
"W": 29141, "X": 17879, "Y": 29045, "Z": 18293,
"-": 17783, ".": 29021, " ": 18269, "$": 17477,
"/": 17489, "+": 17681, "%": 20753, "*": 35770
};
this.encodings = [20957, 29783, 23639, 30485, 20951, 29813, 23669, 20855, 29789, 23645, 29975, 23831, 30533, 22295, 30149, 24005, 21623, 29981, 23837, 22301, 30023, 23879, 30545, 22343, 30161, 24017, 21959, 30065, 23921, 22385, 29015, 18263, 29141, 17879, 29045, 18293, 17783, 29021, 18269, 17477, 17489, 17681, 20753, 35770];
}

// Get the binary representation of a character by converting the encodings
// from decimal to binary


CODE39.prototype.getEncoding = function getEncoding(character) {
return this.encodings[character].toString(2);
return this.getBinary(this.characterValue(character));
};

CODE39.prototype.getBinary = function getBinary(characterValue) {
return this.encodings[characterValue].toString(2);
};

CODE39.prototype.getCharacter = function getCharacter(characterValue) {
return this.characters[characterValue];
};

CODE39.prototype.characterValue = function characterValue(character) {
return this.characters.indexOf(character);
};

CODE39.prototype.encode = function encode() {
var string = this.string;

// First character is always a *
var result = this.getEncoding("*");

Expand All @@ -49,12 +57,25 @@ var CODE39 = function () {
result += this.getEncoding(this.string[i]) + "0";
}

// Calculate mod43 checksum if enabled
if (this.mod43Enabled) {
var checksum = 0;
for (var i = 0; i < this.string.length; i++) {
checksum += this.characterValue(this.string[i]);
}

checksum = checksum % 43;

result += this.getBinary(checksum) + "0";
string += this.getCharacter(checksum);
}

// Last character is always a *
result += this.getEncoding("*");

return {
data: result,
text: this.string
text: string
};
};

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "JsBarcode",
"main": "bin/browser/JsBarcode.js",
"version": "3.2.0",
"version": "3.2.1",
"homepage": "https://github.com/lindell/JsBarcode",
"authors": [
"Johan Lindell <[email protected]>"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsbarcode",
"version": "3.2.0",
"version": "3.2.1",
"description": "JsBarcode is a simple and powerfull way to create different types of 1d barcodes.",
"main": "./bin/node/JsBarcode.js",
"directories": {
Expand Down

0 comments on commit b39e9e8

Please sign in to comment.