Barcode Generation
This commit is contained in:
18
node_modules/jsbarcode/test/browser/canvasTest.html
generated
vendored
Normal file
18
node_modules/jsbarcode/test/browser/canvasTest.html
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en-US">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Test minified version</title>
|
||||
<script src="../../dist/JsBarcode.all.js"></script>
|
||||
|
||||
<script src="tests.js"></script>
|
||||
<script src="canvasTest.js"></script>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="test.css">
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
doTests(document.body);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
30
node_modules/jsbarcode/test/browser/canvasTest.js
generated
vendored
Normal file
30
node_modules/jsbarcode/test/browser/canvasTest.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
var parent;
|
||||
function doTests(p){
|
||||
parent = p;
|
||||
createTests(newTest);
|
||||
}
|
||||
|
||||
function newTest(text, options){
|
||||
var testbox = document.createElement("div");
|
||||
testbox.className = "testbox";
|
||||
|
||||
var format = (typeof options !== "undefined" && options.format) || "auto";
|
||||
|
||||
testbox.innerHTML = '\
|
||||
<b>Format:</b> ' + format + '<br>\
|
||||
<b>Input:</b> ' + text + '<br>\
|
||||
<br>\
|
||||
<img class="barcode"/>';
|
||||
|
||||
try{
|
||||
JsBarcode(testbox.querySelector('.barcode'), text, options);
|
||||
}
|
||||
catch(e){
|
||||
testbox.className = "errorbox";
|
||||
testbox.onclick = function(){
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
parent.appendChild(testbox);
|
||||
}
|
||||
9842
node_modules/jsbarcode/test/browser/help/jquery-2.2.3.js
generated
vendored
Normal file
9842
node_modules/jsbarcode/test/browser/help/jquery-2.2.3.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
80
node_modules/jsbarcode/test/browser/initTest.html
generated
vendored
Normal file
80
node_modules/jsbarcode/test/browser/initTest.html
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en-US">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Test minified version</title>
|
||||
<script src="help/jquery-2.2.3.js"></script>
|
||||
<script src="../../dist/JsBarcode.all.js"></script>
|
||||
<style>
|
||||
@font-face {
|
||||
font-family: "OCRB";
|
||||
src: url("help/OCRB.otf");
|
||||
}
|
||||
|
||||
body{
|
||||
font-family: "OCRB";
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
window.onload = function(){
|
||||
JsBarcode(".barcode").init();
|
||||
|
||||
$(".jqbarcode").JsBarcode().init();
|
||||
|
||||
JsBarcode("#barcode1").init();
|
||||
$("#barcode2").JsBarcode().init();
|
||||
JsBarcode("#barcode3").init();
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<svg class="barcode"
|
||||
jsbarcode-value="123456789010"
|
||||
jsbarcode-format="ean13"
|
||||
jsbarcode-textMargin="0"
|
||||
jsbarcode-lineColor="#e00">
|
||||
</svg>
|
||||
|
||||
<img class="barcode" data-value="Test"/>
|
||||
|
||||
<canvas class="barcode"
|
||||
data-value="HI"
|
||||
data-format="CODE39"
|
||||
data-background="#bff">
|
||||
</canvas>
|
||||
|
||||
<br />
|
||||
|
||||
<svg class="jqbarcode"
|
||||
jsbarcode-value="123456789010"
|
||||
jsbarcode-format="ean13"
|
||||
jsbarcode-textMargin="0"
|
||||
jsbarcode-lineColor="#e00">
|
||||
</svg>
|
||||
|
||||
<img class="jqbarcode" data-value="Test"/>
|
||||
|
||||
<canvas class="jqbarcode"
|
||||
data-value="HI"
|
||||
data-format="CODE39"
|
||||
data-background="#bff">
|
||||
</canvas>
|
||||
|
||||
<br />
|
||||
|
||||
<svg id="barcode1"
|
||||
jsbarcode-value="123456789010"
|
||||
jsbarcode-format="ean13"
|
||||
jsbarcode-textMargin="0"
|
||||
jsbarcode-lineColor="#e00">
|
||||
</svg>
|
||||
|
||||
<img id="barcode2" data-value="Test"/>
|
||||
|
||||
<canvas id="barcode3"
|
||||
data-value="HI"
|
||||
data-format="CODE39"
|
||||
data-background="#bff">
|
||||
</canvas>
|
||||
</body>
|
||||
</html>
|
||||
20
node_modules/jsbarcode/test/browser/jQueryTest.html
generated
vendored
Normal file
20
node_modules/jsbarcode/test/browser/jQueryTest.html
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en-US">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Test minified version</title>
|
||||
<script src="help/jquery-2.2.3.js"></script>
|
||||
|
||||
<script src="../../dist/JsBarcode.all.js"></script>
|
||||
|
||||
<script src="tests.js"></script>
|
||||
<script src="jQueryTest.js"></script>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="test.css">
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
doTests(document.body);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
30
node_modules/jsbarcode/test/browser/jQueryTest.js
generated
vendored
Normal file
30
node_modules/jsbarcode/test/browser/jQueryTest.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
var parent;
|
||||
function doTests(p){
|
||||
parent = p;
|
||||
createTests(newTest);
|
||||
}
|
||||
|
||||
function newTest(text, options){
|
||||
var testbox = document.createElement("div");
|
||||
testbox.className = "testbox";
|
||||
|
||||
var format = (typeof options !== "undefined" && options.format) || "auto";
|
||||
|
||||
testbox.innerHTML = '\
|
||||
<b>Format:</b> ' + format + '<br>\
|
||||
<b>Input:</b> ' + text + '<br>\
|
||||
<br>\
|
||||
<img class="barcode"/>';
|
||||
|
||||
try{
|
||||
$('.barcode', testbox).JsBarcode(text, options);
|
||||
}
|
||||
catch(e){
|
||||
testbox.className = "errorbox";
|
||||
testbox.onclick = function(){
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
parent.appendChild(testbox);
|
||||
}
|
||||
18
node_modules/jsbarcode/test/browser/svgTest.html
generated
vendored
Normal file
18
node_modules/jsbarcode/test/browser/svgTest.html
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en-US">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Test minified version</title>
|
||||
<script src="../../dist/JsBarcode.all.js"></script>
|
||||
|
||||
<script src="tests.js"></script>
|
||||
<script src="svgTest.js"></script>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="test.css">
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
doTests(document.body);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
30
node_modules/jsbarcode/test/browser/svgTest.js
generated
vendored
Normal file
30
node_modules/jsbarcode/test/browser/svgTest.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
var parent;
|
||||
function doTests(p){
|
||||
parent = p;
|
||||
createTests(newTest);
|
||||
}
|
||||
|
||||
function newTest(text, options){
|
||||
var testbox = document.createElement("div");
|
||||
testbox.className = "testbox";
|
||||
|
||||
var format = (typeof options !== "undefined" && options.format) || "auto";
|
||||
|
||||
testbox.innerHTML = '\
|
||||
<b>Format:</b> ' + format + '<br>\
|
||||
<b>Input:</b> ' + text + '<br>\
|
||||
<br>\
|
||||
<svg class="barcode"/>';
|
||||
|
||||
try{
|
||||
JsBarcode(testbox.querySelector('.barcode'), text, options);
|
||||
}
|
||||
catch(e){
|
||||
testbox.className = "errorbox";
|
||||
testbox.onclick = function(){
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
parent.appendChild(testbox);
|
||||
}
|
||||
20
node_modules/jsbarcode/test/browser/test.css
generated
vendored
Normal file
20
node_modules/jsbarcode/test/browser/test.css
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
body{
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.testbox{
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
margin:25px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.errorbox{
|
||||
background: #d00;
|
||||
vertical-align: top;
|
||||
display: inline-block;
|
||||
margin:25px;
|
||||
padding: 25px;
|
||||
width:100px;
|
||||
text-align: center;
|
||||
}
|
||||
45
node_modules/jsbarcode/test/browser/tests.js
generated
vendored
Normal file
45
node_modules/jsbarcode/test/browser/tests.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
function createTests(newTest){
|
||||
newTest("This has a \nnewline", {width: 1});
|
||||
newTest("\tHi\nHI", {width: 1});
|
||||
newTest("Hello", {width: 1, text: "Hi!"});
|
||||
newTest("A little test!", {format: "CODE128", width: 1});
|
||||
newTest("ABCDEFG", {format: "CODE39", width: 1, mod43: true});
|
||||
newTest("A little test", {format: "CODE39", width: 1});
|
||||
newTest("12345", {format: "EAN5", width: 1});
|
||||
newTest("52", {format: "EAN2", width: 1});
|
||||
newTest("423514346455", {format: "UPC", width: 2, textMargin: 0});
|
||||
newTest("423514346455", {format: "UPC", width: 2, textMargin: 0, flat: true});
|
||||
newTest("01245714", {format: "UPCE", width: 2, textMargin: 0});
|
||||
newTest("5901234123457", {format: "EAN13", fontSize: 40, textMargin: 0, lastChar: ">"});
|
||||
newTest("590123412345", {format: "EAN13", width: 2, fontSize: 16});
|
||||
newTest("590123412345", {format: "EAN13", width: 3});
|
||||
newTest("590123412345", {format: "EAN13", flat: true});
|
||||
newTest("96385074", {format: "EAN8", width: 1});
|
||||
newTest("9638507", {format: "EAN8", width: 1});
|
||||
newTest("98765432109213", {format: "ITF14", width: 1});
|
||||
newTest("12345", {format: "pharmacode", width: 1});
|
||||
newTest("133742", {format: "CODE128C", width: 1});
|
||||
newTest("12345674", {format: "MSI", width: 1});
|
||||
newTest("1234567890", {format: "codabar", width: 1});
|
||||
newTest("A1234567890A", {format: "codabar", width: 1});
|
||||
newTest("C1234567890D", {format: "codabar", width: 1});
|
||||
newTest("12345674", {format: "GenericBarcode", width: 1});
|
||||
newTest("Such customize!", {
|
||||
width: 1,
|
||||
height: 50,
|
||||
format: "CODE128",
|
||||
displayValue: true,
|
||||
fontOptions: "bold",
|
||||
font: "cursive",
|
||||
textAlign: "right",
|
||||
textMargin: 20,
|
||||
fontSize: 28,
|
||||
background: "#f00",
|
||||
lineColor: "#0ff",
|
||||
margin: 10,
|
||||
marginTop: 60,
|
||||
marginBottom: 5,
|
||||
marginLeft: 60,
|
||||
marginRight: 30
|
||||
});
|
||||
}
|
||||
359
node_modules/jsbarcode/test/coverage.html
generated
vendored
Normal file
359
node_modules/jsbarcode/test/coverage.html
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
109
node_modules/jsbarcode/test/node/CODE128.test.js
generated
vendored
Normal file
109
node_modules/jsbarcode/test/node/CODE128.test.js
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
var assert = require('assert');
|
||||
var JsBarcode = require('../../bin/JsBarcode.js');
|
||||
var Canvas = require("canvas");
|
||||
|
||||
|
||||
describe('CODE128', function() {
|
||||
it('should be able to include the encoder(s)', function () {
|
||||
CODE128 = JsBarcode.getModule("CODE128");
|
||||
CODE128A = JsBarcode.getModule("CODE128A");
|
||||
CODE128B = JsBarcode.getModule("CODE128B");
|
||||
CODE128C = JsBarcode.getModule("CODE128C");
|
||||
});
|
||||
|
||||
it('should encode CODE128A', function () {
|
||||
var enc = new CODE128A("ABC" + String.fromCharCode(25), {});
|
||||
assert.equal("1101000010010100011000100010110001000100011011011011110100011101101100011101011"
|
||||
, enc.encode().data);
|
||||
});
|
||||
|
||||
it('should encode CODE128B', function () {
|
||||
var enc = new CODE128B("a@B=1", {});
|
||||
assert.equal("110100100001001011000011000110110100010110001110011001010011100110110111001001100011101011"
|
||||
, enc.encode().data);
|
||||
});
|
||||
|
||||
it('should encode CODE128C', function () {
|
||||
var enc = new CODE128C("123456", {});
|
||||
assert.equal("11010011100101100111001000101100011100010110100011011101100011101011"
|
||||
, enc.encode().data);
|
||||
});
|
||||
|
||||
it('should encode CODE128 as GS1-128/EAN-128', function () {
|
||||
var enc = new CODE128C("12345678", { ean128: true });
|
||||
assert.equal("110100111001111010111010110011100100010110001110001011011000010100110010011101100011101011",
|
||||
enc.encode().data);
|
||||
});
|
||||
|
||||
it('should remove unprintable characters', function () {
|
||||
var enc = new CODE128C("A\n\x00B \x04\x10\x1FC", {});
|
||||
assert.equal("AB C", enc.encode().text);
|
||||
});
|
||||
|
||||
it('should encode CODE128 (auto)', function () {
|
||||
var enc = new CODE128("12345Hejsan123456\tA", {});
|
||||
assert.equal("110100111001011001110010001011000101111011101101110010011000101000101100100001000011001010111100100100101100001100001010010111011110101100111001000101100011100010110111010111101000011010010100011000111011110101100011101011",
|
||||
enc.encode().data);
|
||||
|
||||
var enc = new CODE128("Hi\n12345", {});
|
||||
assert.equal("110100100001100010100010000110100111010111101000011001010011100110101110111101110110111010111011000111001100101100011101011"
|
||||
, enc.encode().data);
|
||||
|
||||
var enc = new CODE128("HI\nHi", {});
|
||||
assert.equal("11010000100110001010001100010001010000110010110001010001011110111010000110100110110011001100011101011"
|
||||
, enc.encode().data);
|
||||
|
||||
var enc = new CODE128("HI\n" + String.fromCharCode(201) + "Hi" + String.fromCharCode(202) + "123456" + String.fromCharCode(207), {});
|
||||
assert.equal("1101000010011000101000110001000101000011001010111100010110001010001011110111010000110100111101010001011101111010110011100100010110001110001011011110101110110011100101100011101011"
|
||||
, enc.encode().data);
|
||||
|
||||
var enc = new CODE128(String.fromCharCode(207) + "42184020500", {});
|
||||
assert.equal("110100111001111010111010110111000110011100101100010100011001001110110001011101110101111010011101100101011110001100011101011"
|
||||
, enc.encode().data);
|
||||
|
||||
var enc = new CODE128("Should\nshift", {});
|
||||
assert.equal("1101001000011011101000100110000101000111101010011110010110010100001000010011011110100010100001100101011110010010011000010100001101001011000010010011110100100011010001100011101011"
|
||||
, enc.encode().data);
|
||||
|
||||
var enc = new CODE128("\tHi\nHI", {});
|
||||
assert.equal("1101000010010000110100110001010001111010001010000110100100001100101100010100011000100010111101101101100011101011"
|
||||
, enc.encode().data);
|
||||
|
||||
});
|
||||
|
||||
it('should warn with invalid text', function () {
|
||||
var enc = new CODE128("ABC" + String.fromCharCode(500), {});
|
||||
assert.equal(false, enc.valid(), {});
|
||||
|
||||
var enc = new CODE128A("Abc", {});
|
||||
assert.equal(false, enc.valid());
|
||||
|
||||
var enc = new CODE128B("Abc\t123", {});
|
||||
assert.equal(false, enc.valid());
|
||||
|
||||
var enc = new CODE128C("1234ab56", {});
|
||||
assert.equal(false, enc.valid());
|
||||
|
||||
var enc = new CODE128C("12345", {});
|
||||
assert.equal(false, enc.valid());
|
||||
});
|
||||
|
||||
it('should pass valid text', function () {
|
||||
var enc = new CODE128("ABC" + String.fromCharCode(207), {});
|
||||
assert.equal(true, enc.valid());
|
||||
|
||||
var enc = new CODE128A("ABC\t\n123", {});
|
||||
assert.equal(true, enc.valid());
|
||||
|
||||
var enc = new CODE128B("Abc123" + String.fromCharCode(202), {});
|
||||
assert.equal(true, enc.valid());
|
||||
|
||||
var enc = new CODE128C("123456", {});
|
||||
assert.equal(true, enc.valid());
|
||||
});
|
||||
|
||||
it('should work with text option', function () {
|
||||
var enc = new CODE128("AB12", {text: "THISISTEXT"});
|
||||
assert.equal("THISISTEXT", enc.encode().text);
|
||||
});
|
||||
});
|
||||
37
node_modules/jsbarcode/test/node/CODE39.test.js
generated
vendored
Normal file
37
node_modules/jsbarcode/test/node/CODE39.test.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
var assert = require('assert');
|
||||
var JsBarcode = require('../../bin/JsBarcode.js');
|
||||
var Canvas = require("canvas");
|
||||
|
||||
|
||||
describe('CODE39', function() {
|
||||
it('should be able to include the encoder(s)', function () {
|
||||
CODE39 = JsBarcode.getModule("CODE39");
|
||||
});
|
||||
|
||||
it('should be able to encode normal text', function () {
|
||||
var enc = new CODE39("AB12", {});
|
||||
assert.equal("100010111011101011101010001011101011101000101110111010001010111010111000101011101000101110111010"
|
||||
, enc.encode().data);
|
||||
});
|
||||
|
||||
it('should warn with invalid text', function () {
|
||||
var enc = new CODE39("AB!12", {});
|
||||
assert.equal(false, enc.valid());
|
||||
});
|
||||
|
||||
it('should make lowercase to uppercase', function () {
|
||||
var enc = new CODE39("abc123ABC", {});
|
||||
assert.equal("ABC123ABC", enc.encode().text);
|
||||
});
|
||||
|
||||
it('should calculate correct checksums', function () {
|
||||
var enc = new CODE39("ABCDEFG", {mod43: true});
|
||||
assert.equal("1000101110111010111010100010111010111010001011101110111010001010101011100010111011101011100010101011101110001010101010001110111011101000111010101000101110111010"
|
||||
, enc.encode().data);
|
||||
});
|
||||
|
||||
it('should work with text option', function () {
|
||||
var enc = new CODE39("AB12", {text: "THISISTEXT"});
|
||||
assert.equal("THISISTEXT", enc.encode().text);
|
||||
});
|
||||
});
|
||||
220
node_modules/jsbarcode/test/node/EAN-UPC.test.js
generated
vendored
Normal file
220
node_modules/jsbarcode/test/node/EAN-UPC.test.js
generated
vendored
Normal file
@@ -0,0 +1,220 @@
|
||||
var assert = require('assert');
|
||||
var JsBarcode = require('../../bin/JsBarcode.js');
|
||||
var Canvas = require("canvas");
|
||||
var help = require("./help/help");
|
||||
var clone = help.clone;
|
||||
|
||||
var options = {height: 100, displayValue: true, fontSize: 20, textMargin: 2, width: 2};
|
||||
|
||||
describe('UPC-A', function() {
|
||||
it('should be able to include the encoder(s)', function () {
|
||||
UPC = JsBarcode.getModule("UPC");
|
||||
});
|
||||
|
||||
it('should be able to encode normal text', function () {
|
||||
var enc = new UPC("123456789999", clone(options));
|
||||
assert.equal("10100110010010011011110101000110110001010111101010100010010010001110100111010011101001110100101"
|
||||
, help.fixBin(enc.encode()));
|
||||
});
|
||||
|
||||
it('should warn with invalid text', function () {
|
||||
var enc = new UPC("12345", clone(options));
|
||||
assert.equal(false, enc.valid());
|
||||
});
|
||||
|
||||
it('should auto include the checksum if missing', function () {
|
||||
var enc = new UPC("12345678999", clone(options));
|
||||
assert.equal("123456789999", help.fixText(enc.encode()));
|
||||
});
|
||||
|
||||
it('should work with text option', function () {
|
||||
var enc = new UPC("12345678999", help.merge(options, {text: "THISISTEXT"}));
|
||||
assert.equal("THISISTEXT", help.fixText(enc.encode()));
|
||||
});
|
||||
|
||||
it('should work with flat option', function () {
|
||||
var enc = new UPC("123456789999", help.merge(options, {flat: true}));
|
||||
assert.equal("10100110010010011011110101000110110001010111101010100010010010001110100111010011101001110100101"
|
||||
, enc.encode().data);
|
||||
assert.equal("123456789999", enc.encode().text);
|
||||
});
|
||||
});
|
||||
|
||||
const UPCE_BINARY = "101011001100100110011101011100101110110011001010101";
|
||||
describe('UPC-E', function() {
|
||||
it('should be able to include the encoder(s)', function () {
|
||||
UPCE = JsBarcode.getModule("UPCE");
|
||||
});
|
||||
|
||||
it('should be able to encode 8-digit codes', function () {
|
||||
var enc = new UPCE("01245714", clone(options));
|
||||
assert.equal(UPCE_BINARY, help.fixBin(enc.encode()));
|
||||
});
|
||||
|
||||
it('should be able to encode 6-digit codes by assuming a 0 number system', function () {
|
||||
var enc = new UPCE("124571", clone(options));
|
||||
assert.equal(UPCE_BINARY, help.fixBin(enc.encode()));
|
||||
});
|
||||
|
||||
it('should warn with invalid text', function () {
|
||||
var enc = new UPCE("01245715", clone(options));
|
||||
assert.equal(false, enc.valid());
|
||||
});
|
||||
|
||||
it('should work with text option', function () {
|
||||
var enc = new UPCE("124571", help.merge(options, {text: "SOMETEXT"}));
|
||||
assert.equal("SOMETEXT", help.fixText(enc.encode()));
|
||||
});
|
||||
|
||||
it('should work with flat option', function () {
|
||||
var enc = new UPCE("01245714", help.merge(options, {flat: true}));
|
||||
assert.equal(UPCE_BINARY, enc.encode().data);
|
||||
assert.equal("01245714", enc.encode().text);
|
||||
});
|
||||
});
|
||||
|
||||
describe('EAN', function() {
|
||||
it('should be able to include the encoder(s)', function () {
|
||||
EAN = JsBarcode.getModule("EAN13");
|
||||
});
|
||||
|
||||
it('should be able to encode normal text', function () {
|
||||
var enc = new EAN("5901234123457", clone(options));
|
||||
assert.equal(true, enc.valid());
|
||||
assert.equal("10100010110100111011001100100110111101001110101010110011011011001000010101110010011101000100101"
|
||||
, help.fixBin(enc.encode()));
|
||||
assert.equal("5901234123457", help.fixText(enc.encode()));
|
||||
});
|
||||
|
||||
it('should be able to encode normal text with flat option', function () {
|
||||
var enc = new EAN("5901234123457", help.merge(options, {flat: true}));
|
||||
assert.equal(true, enc.valid());
|
||||
assert.equal("10100010110100111011001100100110111101001110101010110011011011001000010101110010011101000100101"
|
||||
, enc.encode().data);
|
||||
assert.equal("5901234123457", help.fixText(enc.encode()));
|
||||
});
|
||||
|
||||
it('should warn with invalid text', function () {
|
||||
var enc = new EAN("12345", {});
|
||||
assert.equal(false, enc.valid());
|
||||
|
||||
var enc = new EAN("5901234123456 ", {});
|
||||
assert.equal(false, enc.valid());
|
||||
});
|
||||
|
||||
it('should auto include the checksum if missing', function () {
|
||||
var enc = new EAN("590123412345", clone(options));
|
||||
assert.equal("5901234123457", help.fixText(enc.encode()));
|
||||
});
|
||||
|
||||
it('should work with text option', function () {
|
||||
var enc = new EAN("12345678999", help.merge(options, {text: "THISISTEXT"}));
|
||||
assert.equal("THISISTEXT", help.fixText(enc.encode()));
|
||||
});
|
||||
});
|
||||
|
||||
describe('EAN-8', function() {
|
||||
it('should be able to include the encoder(s)', function () {
|
||||
EAN8 = JsBarcode.getModule("EAN8");
|
||||
});
|
||||
|
||||
it('should be able to encode normal text', function () {
|
||||
var enc = new EAN8("96385074", {});
|
||||
assert.equal(true, enc.valid());
|
||||
assert.equal("1010001011010111101111010110111010101001110111001010001001011100101"
|
||||
, help.fixBin(enc.encode()));
|
||||
assert.equal("96385074", help.fixText(enc.encode()));
|
||||
});
|
||||
|
||||
it('should be able to encode normal text with flat option', function () {
|
||||
var enc = new EAN8("96385074", help.merge(options, {flat: true}));
|
||||
assert.equal(true, enc.valid());
|
||||
assert.equal("1010001011010111101111010110111010101001110111001010001001011100101"
|
||||
, enc.encode().data);
|
||||
assert.equal("96385074", help.fixText(enc.encode()));
|
||||
});
|
||||
|
||||
it('should auto include the checksum if missing', function () {
|
||||
var enc = new EAN8("9638507", {});
|
||||
|
||||
assert.equal(true, enc.valid());
|
||||
assert.equal("96385074", help.fixText(enc.encode()));
|
||||
assert.equal("1010001011010111101111010110111010101001110111001010001001011100101"
|
||||
, help.fixBin(enc.encode()));
|
||||
});
|
||||
|
||||
it('should warn with invalid text', function () {
|
||||
var enc = new EAN8("12345", {});
|
||||
assert.equal(false, enc.valid());
|
||||
|
||||
var enc = new EAN8("96385073", {});
|
||||
assert.equal(false, enc.valid());
|
||||
});
|
||||
|
||||
it('should work with text option', function () {
|
||||
var enc = new EAN8("96385074", help.merge(options, {text: "THISISTEXT", flat: true}));
|
||||
assert.equal("THISISTEXT", help.fixText(enc.encode()));
|
||||
});
|
||||
});
|
||||
|
||||
describe('EAN-5', function() {
|
||||
it('should be able to include the encoder(s)', function () {
|
||||
EAN5 = JsBarcode.getModule("EAN5");
|
||||
});
|
||||
|
||||
it('should be able to encode normal text', function () {
|
||||
var enc = new EAN5("54495", {});
|
||||
assert.equal(true, enc.valid());
|
||||
assert.equal("10110110001010100011010011101010001011010111001"
|
||||
, enc.encode().data);
|
||||
|
||||
var enc = new EAN5("12345", {});
|
||||
assert.equal(true, enc.valid());
|
||||
assert.equal("10110110011010010011010100001010100011010110001"
|
||||
, enc.encode().data);
|
||||
});
|
||||
|
||||
it('should warn with invalid text', function () {
|
||||
var enc = new EAN5("1234", {});
|
||||
assert.equal(false, enc.valid());
|
||||
|
||||
var enc = new EAN5("123a5", {});
|
||||
assert.equal(false, enc.valid());
|
||||
});
|
||||
|
||||
it('should work with text option', function () {
|
||||
var enc = new EAN5("12345", help.merge(options, {text: "THISISTEXT"}));
|
||||
assert.equal("THISISTEXT", help.fixText(enc.encode()));
|
||||
});
|
||||
});
|
||||
|
||||
describe('EAN-2', function() {
|
||||
it('should be able to include the encoder(s)', function () {
|
||||
EAN2 = JsBarcode.getModule("EAN2");
|
||||
});
|
||||
|
||||
it('should be able to encode normal text', function () {
|
||||
var enc = new EAN2("53", {});
|
||||
assert.equal(true, enc.valid());
|
||||
assert.equal("10110110001010100001"
|
||||
, enc.encode().data);
|
||||
|
||||
var enc = new EAN2("12", {});
|
||||
assert.equal(true, enc.valid());
|
||||
assert.equal("10110011001010010011"
|
||||
, enc.encode().data);
|
||||
});
|
||||
|
||||
it('should warn with invalid text', function () {
|
||||
var enc = new EAN2("1", {});
|
||||
assert.equal(false, enc.valid());
|
||||
|
||||
var enc = new EAN2("a2", {});
|
||||
assert.equal(false, enc.valid());
|
||||
});
|
||||
|
||||
it('should work with text option', function () {
|
||||
var enc = new EAN2("12", help.merge(options, {text: "THISISTEXT"}));
|
||||
assert.equal("THISISTEXT", help.fixText(enc.encode()));
|
||||
});
|
||||
});
|
||||
68
node_modules/jsbarcode/test/node/ITF-14.test.js
generated
vendored
Normal file
68
node_modules/jsbarcode/test/node/ITF-14.test.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
var assert = require('assert');
|
||||
var JsBarcode = require('../../bin/JsBarcode.js');
|
||||
var Canvas = require("canvas");
|
||||
|
||||
|
||||
describe('ITF-14', function() {
|
||||
it('should be able to include the encoder(s)', function () {
|
||||
ITF14 = JsBarcode.getModule("ITF14");
|
||||
});
|
||||
|
||||
it('should be able to encode normal text', function () {
|
||||
var enc = new ITF14("98765432109213", {});
|
||||
assert.equal("101010001110101110001010100010001110111011101011100010100011101110001010100011101010001000111010111000101110100011100010001010111011101"
|
||||
, enc.encode().data);
|
||||
});
|
||||
|
||||
it('should be able to add checksum if needed', function () {
|
||||
var enc = new ITF14("9876543210921", {});
|
||||
assert.equal("101010001110101110001010100010001110111011101011100010100011101110001010100011101010001000111010111000101110100011100010001010111011101"
|
||||
, enc.encode().data);
|
||||
});
|
||||
|
||||
it('should return text correct', function () {
|
||||
var enc = new ITF14("9876543210921", {});
|
||||
assert.equal("98765432109213", enc.encode().text);
|
||||
|
||||
var enc = new ITF14("98765432109213", {});
|
||||
assert.equal("98765432109213", enc.encode().text);
|
||||
});
|
||||
|
||||
it('should warn with invalid text and not when valid', function () {
|
||||
var enc = new ITF14("987654321092", {});
|
||||
assert.equal(false, enc.valid());
|
||||
|
||||
var enc = new ITF14("98765432109212", {});
|
||||
assert.equal(false, enc.valid());
|
||||
|
||||
var enc = new ITF14("98765432109213", {});
|
||||
assert.equal(true, enc.valid());
|
||||
|
||||
var enc = new ITF14("9876543210921", {});
|
||||
assert.equal(true, enc.valid());
|
||||
|
||||
// Edge cases for check digit of zero
|
||||
var enc = new ITF14("00847280031740", {});
|
||||
assert.equal(true, enc.valid());
|
||||
|
||||
var enc = new ITF14("00847280031900", {});
|
||||
assert.equal(true, enc.valid());
|
||||
|
||||
var enc = new ITF14("00847280032020", {});
|
||||
assert.equal(true, enc.valid());
|
||||
|
||||
var enc = new ITF14("00847280031870", {});
|
||||
assert.equal(true, enc.valid());
|
||||
|
||||
var enc = new ITF14("00847280031450", {});
|
||||
assert.equal(true, enc.valid());
|
||||
|
||||
var enc = new ITF14("00847280031320", {});
|
||||
assert.equal(true, enc.valid());
|
||||
});
|
||||
|
||||
it('should work with text option', function () {
|
||||
var enc = new ITF14("00847280031450", {text: "THISISTEXT"});
|
||||
assert.equal("THISISTEXT", enc.encode().text);
|
||||
});
|
||||
});
|
||||
34
node_modules/jsbarcode/test/node/ITF.test.js
generated
vendored
Normal file
34
node_modules/jsbarcode/test/node/ITF.test.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
var assert = require('assert');
|
||||
var JsBarcode = require('../../bin/JsBarcode.js');
|
||||
var Canvas = require("canvas");
|
||||
|
||||
|
||||
describe('ITF', function() {
|
||||
it('should be able to include the encoder(s)', function () {
|
||||
ITF = JsBarcode.getModule("ITF");
|
||||
});
|
||||
|
||||
it('should be able to encode normal text', function () {
|
||||
var enc = new ITF("123456", {});
|
||||
assert.equal("101011101000101011100011101110100010100011101000111000101011101"
|
||||
, enc.encode().data);
|
||||
});
|
||||
|
||||
it('should return getText correct', function () {
|
||||
var enc = new ITF("123456", {});
|
||||
assert.equal("123456", enc.encode().text);
|
||||
});
|
||||
|
||||
it('should warn with invalid text', function () {
|
||||
var enc = new ITF("12345", {});
|
||||
assert.equal(false, enc.valid());
|
||||
|
||||
var enc = new ITF("1234AB", {});
|
||||
assert.equal(false, enc.valid());
|
||||
});
|
||||
|
||||
it('should work with text option', function () {
|
||||
var enc = new ITF("123456", {text: "THISISTEXT"});
|
||||
assert.equal("THISISTEXT", enc.encode().text);
|
||||
});
|
||||
});
|
||||
132
node_modules/jsbarcode/test/node/JsBarcode.test.js
generated
vendored
Normal file
132
node_modules/jsbarcode/test/node/JsBarcode.test.js
generated
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
var assert = require('assert');
|
||||
var JsBarcode = require('../../bin/JsBarcode.js');
|
||||
var { createCanvas } = require("canvas");
|
||||
|
||||
describe('Encoders', function() {
|
||||
it('should be able to include the encoders needed', function () {
|
||||
CODE128 = JsBarcode.getModule("CODE128");
|
||||
GENERIC = JsBarcode.getModule("GenericBarcode");
|
||||
});
|
||||
});
|
||||
|
||||
describe('node-canvas generation', function() {
|
||||
it('should generate normal canvas', function () {
|
||||
var canvas = createCanvas();
|
||||
JsBarcode(canvas, "Hello");
|
||||
});
|
||||
|
||||
it('checking width', function () {
|
||||
var canvas1 = createCanvas();
|
||||
var canvas2 = createCanvas();
|
||||
|
||||
JsBarcode(canvas1, "Hello", {format: "CODE128"});
|
||||
JsBarcode(canvas2, "Hello", {format: "CODE39"});
|
||||
|
||||
assert.notEqual(canvas1.width, canvas2.width);
|
||||
});
|
||||
|
||||
it('should throws errors when suppose to', function () {
|
||||
var canvas = createCanvas();
|
||||
assert.throws(function(){JsBarcode(canvas, "Hello", {format: "EAN8"});});
|
||||
assert.throws(function(){JsBarcode("Hello", "Hello", {format: "DOESNOTEXIST"});});
|
||||
assert.throws(function(){JsBarcode(123, "Hello", {format: "DOESNOTEXIST"});});
|
||||
});
|
||||
|
||||
it('should use the valid callback correct', function (done) {
|
||||
var canvas = createCanvas();
|
||||
|
||||
JsBarcode(canvas, "Hello", {
|
||||
format: "CODE128",
|
||||
valid: function(valid){
|
||||
if(valid){
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should use false valid callback correct', function (done) {
|
||||
var canvas = createCanvas();
|
||||
|
||||
JsBarcode(canvas, "Hello", {
|
||||
format: "pharmacode",
|
||||
valid: function(valid){
|
||||
if(!valid){
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should create output with same input', function () {
|
||||
var canvas1 = createCanvas();
|
||||
var canvas2 = createCanvas();
|
||||
|
||||
JsBarcode(canvas1, "Hello", {format: "CODE128"});
|
||||
JsBarcode(canvas2, "Hello", {format: "CODE128"});
|
||||
|
||||
assert.equal(canvas1.toDataURL(), canvas2.toDataURL());
|
||||
});
|
||||
|
||||
it('should set background', function () {
|
||||
var canvas = createCanvas();
|
||||
var ctx = canvas.getContext("2d");
|
||||
JsBarcode(canvas, "Hello", {format: "CODE128", background: "#f00"});
|
||||
|
||||
var topLeft = ctx.getImageData(0,0,1,1);
|
||||
assert.equal(255, topLeft.data[0]);
|
||||
assert.equal(0, topLeft.data[1]);
|
||||
assert.equal(0, topLeft.data[2]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Text printing', function() {
|
||||
it('should produce different output when displaying value', function () {
|
||||
var canvas1 = createCanvas();
|
||||
var canvas2 = createCanvas();
|
||||
|
||||
JsBarcode(canvas1, "Hello", {format: "CODE128", displayValue: false});
|
||||
JsBarcode(canvas2, "Hello", {format: "CODE128"});
|
||||
|
||||
assert.notEqual(canvas1.toDataURL(), canvas2.toDataURL());
|
||||
});
|
||||
|
||||
it('should produce different output when having different textAlign', function () {
|
||||
var canvas1 = createCanvas();
|
||||
var canvas2 = createCanvas();
|
||||
var canvas3 = createCanvas();
|
||||
|
||||
JsBarcode(canvas1, "Hello", {format: "CODE128", displayValue: true, textAlign: "center"});
|
||||
JsBarcode(canvas2, "Hello", {format: "CODE128", displayValue: true, textAlign: "left"});
|
||||
JsBarcode(canvas3, "Hello", {format: "CODE128", displayValue: true, textAlign: "right"});
|
||||
|
||||
assert.notEqual(canvas1.toDataURL(), canvas2.toDataURL());
|
||||
assert.notEqual(canvas2.toDataURL(), canvas3.toDataURL());
|
||||
assert.notEqual(canvas1.toDataURL(), canvas3.toDataURL());
|
||||
});
|
||||
|
||||
it('should allow numbers as input', function () {
|
||||
var canvas = createCanvas();
|
||||
|
||||
JsBarcode(canvas, 1234567890128, {format: "EAN13"});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Extended Arrays', function() {
|
||||
it('should work with extended arrays', function () {
|
||||
Array.prototype.test = function(){};
|
||||
Array.prototype._test = "test";
|
||||
|
||||
var canvas = createCanvas();
|
||||
JsBarcode(canvas, "Hello");
|
||||
JsBarcode(canvas, "HI", {format: "CODE39"});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Generic barcode', function() {
|
||||
it('should not fail generic barcode', function () {
|
||||
var enc = new GENERIC("1234", {});
|
||||
assert.equal(enc.valid(), true);
|
||||
assert.equal(enc.encode().text, "1234");
|
||||
});
|
||||
});
|
||||
77
node_modules/jsbarcode/test/node/MSI.test.js
generated
vendored
Normal file
77
node_modules/jsbarcode/test/node/MSI.test.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
var assert = require('assert');
|
||||
var JsBarcode = require('../../bin/JsBarcode.js');
|
||||
var Canvas = require("canvas");
|
||||
|
||||
|
||||
describe('MSI', function() {
|
||||
it('should be able to include the encoder(s)', function () {
|
||||
MSI = JsBarcode.getModule("MSI");
|
||||
MSI10 = JsBarcode.getModule("MSI10");
|
||||
MSI11 = JsBarcode.getModule("MSI11");
|
||||
MSI1010 = JsBarcode.getModule("MSI1010");
|
||||
MSI1110 = JsBarcode.getModule("MSI1110");
|
||||
});
|
||||
|
||||
it('should be able to encode normal text', function () {
|
||||
var enc = new MSI10("1234567", {});
|
||||
assert.equal(true, enc.valid());
|
||||
assert.equal("12345674", enc.encode().text);
|
||||
assert.equal("1101001001001101001001101001001001101101001101001001001101001101001101101001001101101101001101001001001"
|
||||
, enc.encode().data);
|
||||
|
||||
var enc = new MSI("12345674", {});
|
||||
assert.equal("1101001001001101001001101001001001101101001101001001001101001101001101101001001101101101001101001001001"
|
||||
, enc.encode().data);
|
||||
|
||||
var enc = new MSI10("17345", {});
|
||||
assert.equal(true, enc.valid());
|
||||
assert.equal("173450", enc.encode().text);
|
||||
|
||||
var enc = new MSI10("1234", {});
|
||||
assert.equal(true, enc.valid());
|
||||
assert.equal("12344", enc.encode().text);
|
||||
});
|
||||
|
||||
it('should encode MSI11', function () {
|
||||
var enc = new MSI11("123456", {});
|
||||
assert.equal("1234560", enc.encode().text);
|
||||
|
||||
var enc = new MSI11("12345678", {});
|
||||
assert.equal("123456785", enc.encode().text);
|
||||
|
||||
var enc = new MSI11("1234567891011", {});
|
||||
assert.equal("12345678910115", enc.encode().text);
|
||||
|
||||
var enc = new MSI11("1134567", {});
|
||||
assert.equal("11345670", enc.encode().text);
|
||||
});
|
||||
|
||||
it('should encode MSI1010', function () {
|
||||
var enc = new MSI1010("1234567", {});
|
||||
assert.equal("123456741", enc.encode().text);
|
||||
|
||||
var enc = new MSI1010("1337", {});
|
||||
assert.equal("133751", enc.encode().text);
|
||||
});
|
||||
|
||||
it('should encode MSI1110', function () {
|
||||
var enc = new MSI1110("12345678", {});
|
||||
assert.equal("1234567855", enc.encode().text);
|
||||
|
||||
var enc = new MSI1110("1337", {});
|
||||
assert.equal("133744", enc.encode().text);
|
||||
});
|
||||
|
||||
it('should warn with invalid text', function () {
|
||||
var enc = new MSI("12345ABC", {});
|
||||
assert.equal(false, enc.valid());
|
||||
|
||||
var enc = new MSI("12345AB675", {});
|
||||
assert.equal(false, enc.valid());
|
||||
});
|
||||
|
||||
it('should work with text option', function () {
|
||||
var enc = new MSI("12345674", {text: "THISISTEXT"});
|
||||
assert.equal("THISISTEXT", enc.encode().text);
|
||||
});
|
||||
});
|
||||
41
node_modules/jsbarcode/test/node/Object-Render.test.js
generated
vendored
Normal file
41
node_modules/jsbarcode/test/node/Object-Render.test.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
var assert = require('assert');
|
||||
var JsBarcode = require('../../bin/JsBarcode.js');
|
||||
var Canvas = require("canvas");
|
||||
|
||||
describe('Object', function() {
|
||||
it('should handle default options', function () {
|
||||
var data = {};
|
||||
JsBarcode(data, '12345678');
|
||||
assert.equal(typeof data.encodings, 'object');
|
||||
});
|
||||
|
||||
it('should catch null', function() {
|
||||
assert.throws(
|
||||
() => {
|
||||
JsBarcode(null, '12345678');
|
||||
},
|
||||
/InvalidElementException/
|
||||
);
|
||||
});
|
||||
|
||||
it('should ignore dom elements', function() {
|
||||
var fakeElement = {
|
||||
nodeName: 'Some Dom Element'
|
||||
}
|
||||
assert.throws(
|
||||
() => {
|
||||
JsBarcode(fakeElement, '2345678');
|
||||
},
|
||||
/InvalidElementException/
|
||||
);
|
||||
});
|
||||
|
||||
it('should work for different types', function () {
|
||||
var data = {};
|
||||
JsBarcode(data, '550000000000', {
|
||||
format: 'upc'
|
||||
});
|
||||
assert.equal(data.encodings.length, 7);
|
||||
assert.ok(data.encodings.every((val) => val.options.format === 'upc'));
|
||||
});
|
||||
});
|
||||
73
node_modules/jsbarcode/test/node/codabar.test.js
generated
vendored
Normal file
73
node_modules/jsbarcode/test/node/codabar.test.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
var assert = require('assert');
|
||||
var JsBarcode = require('../../bin/JsBarcode.js');
|
||||
var Canvas = require("canvas");
|
||||
|
||||
describe('Codabar', function() {
|
||||
it('should be able to include the encoder(s)', function () {
|
||||
Codabar = JsBarcode.getModule("codabar");
|
||||
});
|
||||
|
||||
it('should encode a string with start and stop characters', function() {
|
||||
var enc = new Codabar("A12345B", {});
|
||||
assert.equal("10110010010101011001010100101101100101010101101001011010100101001001011"
|
||||
, enc.encode().data);
|
||||
});
|
||||
|
||||
it('should add start and stop characters to a string without them', function() {
|
||||
var enc = new Codabar("12345", {});
|
||||
// should encode to "A12345A"
|
||||
assert.equal("10110010010101011001010100101101100101010101101001011010100101011001001"
|
||||
, enc.encode().data);
|
||||
});
|
||||
|
||||
it('should return text string without start/stop characters', function() {
|
||||
var enc = new Codabar("A12345B", {});
|
||||
assert.equal("12345", enc.encode().text)
|
||||
});
|
||||
|
||||
it('should warn with invalid start/stop characters', function () {
|
||||
var enc = new Codabar("X12345Y", {});
|
||||
assert.equal(false, enc.valid());
|
||||
});
|
||||
|
||||
it('should warn with only a start character', function () {
|
||||
var enc = new Codabar("A12345", {});
|
||||
assert.equal(false, enc.valid());
|
||||
});
|
||||
|
||||
it('should warn with only an invalid start character', function () {
|
||||
var enc = new Codabar("X12345", {});
|
||||
assert.equal(false, enc.valid());
|
||||
});
|
||||
|
||||
it('should warn with only a stop character', function () {
|
||||
var enc = new Codabar("12345A", {});
|
||||
assert.equal(false, enc.valid());
|
||||
});
|
||||
|
||||
it('should warn with only an invalid stop character', function () {
|
||||
var enc = new Codabar("12345X", {});
|
||||
assert.equal(false, enc.valid());
|
||||
});
|
||||
|
||||
it('should warn with only start and stop characters', function() {
|
||||
var enc = new Codabar("AA", {})
|
||||
assert.equal(false, enc.valid());
|
||||
});
|
||||
|
||||
it('should warn with an empty string', function() {
|
||||
var enc = new Codabar("", {})
|
||||
assert.equal(false, enc.valid());
|
||||
});
|
||||
|
||||
it('should warn with invalid input', function () {
|
||||
var enc = new Codabar("A1234OOPS56A", {});
|
||||
assert.equal(false, enc.valid());
|
||||
});
|
||||
|
||||
it('should work with text option', function () {
|
||||
var enc = new Codabar("A1234OOPS56A", {text: "THISISATEXT"});
|
||||
assert.equal("THISISATEXT", enc.encode().text);
|
||||
});
|
||||
|
||||
});
|
||||
72
node_modules/jsbarcode/test/node/help/help.js
generated
vendored
Normal file
72
node_modules/jsbarcode/test/node/help/help.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
module.exports.toBin = mergeToBin;
|
||||
module.exports.stripZero = stripZero;
|
||||
module.exports.fixText = mergeToText;
|
||||
module.exports.merge = merge;
|
||||
module.exports.clone = clone;
|
||||
|
||||
module.exports.fixBin = function(a){
|
||||
return stripZero(mergeToBin(a));
|
||||
}
|
||||
|
||||
function mergeToText(encodeData){
|
||||
if(Array.isArray(encodeData)){
|
||||
var ret = "";
|
||||
for(var i = 0; i < encodeData.length; i++){
|
||||
ret += mergeToText(encodeData[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
else{
|
||||
return encodeData.text || "";
|
||||
}
|
||||
}
|
||||
|
||||
function mergeToBin(encodeData){
|
||||
if(Array.isArray(encodeData)){
|
||||
var ret = "";
|
||||
for(var i = 0; i < encodeData.length; i++){
|
||||
ret += toBin(encodeData[i].data);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
else{
|
||||
return toBin(encodeData);
|
||||
}
|
||||
}
|
||||
|
||||
function toBin(res){
|
||||
var ret = "";
|
||||
for(var i=0;i<res.length;i++){
|
||||
if(res[i] > 0){
|
||||
ret += "1";
|
||||
}
|
||||
else{
|
||||
ret += "0";
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function stripZero(string){
|
||||
return string.match(/^0*(.+?)0*$/)[1];
|
||||
}
|
||||
|
||||
function merge(old, replaceObj) {
|
||||
var newMerge = {};
|
||||
var k;
|
||||
for (k in old) {
|
||||
if (old.hasOwnProperty(k)) {
|
||||
newMerge[k] = old[k];
|
||||
}
|
||||
}
|
||||
for (k in replaceObj) {
|
||||
if(replaceObj.hasOwnProperty(k) && typeof replaceObj[k] !== "undefined"){
|
||||
newMerge[k] = replaceObj[k];
|
||||
}
|
||||
}
|
||||
return newMerge;
|
||||
}
|
||||
|
||||
function clone(obj){
|
||||
return merge({}, obj)
|
||||
}
|
||||
20
node_modules/jsbarcode/test/node/nodesvg.test.js
generated
vendored
Normal file
20
node_modules/jsbarcode/test/node/nodesvg.test.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
var assert = require('assert');
|
||||
var JsBarcode = require('../../bin/JsBarcode.js');
|
||||
var xmldom = require('xmldom');
|
||||
var DOMImplementation = xmldom.DOMImplementation;
|
||||
var XMLSerializer = xmldom.XMLSerializer;
|
||||
var xmlSerializer = new XMLSerializer();
|
||||
var document = new DOMImplementation().createDocument('http://www.w3.org/1999/xhtml', 'html', null);
|
||||
|
||||
describe('SVG', function() {
|
||||
it('should work with external SVG implementation', function () {
|
||||
var svgNode = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
||||
|
||||
JsBarcode(svgNode, 'test', {
|
||||
xmlDocument: document
|
||||
});
|
||||
|
||||
var xml = xmlSerializer.serializeToString(svgNode);
|
||||
assert(xml.length > 200);
|
||||
});
|
||||
});
|
||||
37
node_modules/jsbarcode/test/node/pharmacode.test.js
generated
vendored
Normal file
37
node_modules/jsbarcode/test/node/pharmacode.test.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
var assert = require('assert');
|
||||
var JsBarcode = require('../../bin/JsBarcode.js');
|
||||
var Canvas = require("canvas");
|
||||
|
||||
describe('Pharmacode', function() {
|
||||
it('should be able to include the encoder(s)', function () {
|
||||
Pharmacode = JsBarcode.getModule("pharmacode");
|
||||
});
|
||||
|
||||
it('should be able to encode normal text', function () {
|
||||
var enc = new Pharmacode("1234", {});
|
||||
assert.equal("10010011100111001001110010010011100111"
|
||||
, enc.encode().data);
|
||||
|
||||
var enc = new Pharmacode("4567", {});
|
||||
assert.equal("10010010011100111001110010011100111001001001"
|
||||
, enc.encode().data);
|
||||
|
||||
var enc = new Pharmacode("12", {});
|
||||
assert.equal("11100100111", enc.encode().data);
|
||||
});
|
||||
|
||||
it('should return getText correct', function () {
|
||||
var enc = new Pharmacode("1234", {});
|
||||
assert.equal("1234", enc.encode().text);
|
||||
});
|
||||
|
||||
it('should warn with invalid text', function () {
|
||||
var enc = new Pharmacode("12345678", {});
|
||||
assert.equal(false, enc.valid());
|
||||
});
|
||||
|
||||
it('should work with text option', function () {
|
||||
var enc = new Pharmacode("12345678", {text: "THISISTEXT"});
|
||||
assert.equal("THISISTEXT", enc.encode().text);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user