Barcode Generation
This commit is contained in:
1 parent
aa6c93f3f6
commit
79ec11e25c
224 files changed
+22473
-94
No files matched your search
+18
@@ -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
@@ -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
File diff suppressed because it is too large.
Load diff
+80
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,359 @@
|
||||
<!DOCTYPE html><html><head><title>Coverage</title><meta charset="utf-8"><script>
|
||||
|
||||
headings = [];
|
||||
|
||||
onload = function(){
|
||||
headings = document.querySelectorAll('h2');
|
||||
};
|
||||
|
||||
onscroll = function(e){
|
||||
var heading = find(window.scrollY);
|
||||
if (!heading) return;
|
||||
var links = document.querySelectorAll('#menu a')
|
||||
, link;
|
||||
|
||||
for (var i = 0, len = links.length; i < len; ++i) {
|
||||
link = links[i];
|
||||
link.className = link.getAttribute('href') == '#' + heading.id
|
||||
? 'active'
|
||||
: '';
|
||||
}
|
||||
};
|
||||
|
||||
function find(y) {
|
||||
var i = headings.length
|
||||
, heading;
|
||||
|
||||
while (i--) {
|
||||
heading = headings[i];
|
||||
if (y >= heading.offsetTop) {
|
||||
return heading;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
|
||||
body {
|
||||
font: 14px/1.6 "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
margin: 0;
|
||||
color: #2C2C2C;
|
||||
border-top: 2px solid #ddd;
|
||||
}
|
||||
|
||||
#coverage {
|
||||
padding: 60px 400px 60px 60px;
|
||||
}
|
||||
|
||||
h1 a {
|
||||
color: inherit;
|
||||
font-weight: inherit;
|
||||
}
|
||||
|
||||
h1 a:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.onload h1 {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
h2 {
|
||||
width: 80%;
|
||||
margin-top: 80px;
|
||||
margin-bottom: 0;
|
||||
font-weight: 100;
|
||||
letter-spacing: 1px;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #8A6343;
|
||||
font-weight: bold;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
ul {
|
||||
margin-top: 20px;
|
||||
padding: 0 15px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
ul li {
|
||||
float: left;
|
||||
width: 40%;
|
||||
margin-top: 5px;
|
||||
margin-right: 60px;
|
||||
list-style: none;
|
||||
border-bottom: 1px solid #eee;
|
||||
padding: 5px 0;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
ul::after {
|
||||
content: '.';
|
||||
height: 0;
|
||||
display: block;
|
||||
visibility: hidden;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
code {
|
||||
font: 12px monaco, monospace;
|
||||
}
|
||||
|
||||
pre {
|
||||
margin: 30px;
|
||||
padding: 30px;
|
||||
border: 1px solid #eee;
|
||||
border-bottom-color: #ddd;
|
||||
-webkit-border-radius: 2px;
|
||||
-moz-border-radius: 2px;
|
||||
border-radius: 2px;
|
||||
-webkit-box-shadow: inset 0 0 10px #eee;
|
||||
-moz-box-shadow: inset 0 0 10px #eee;
|
||||
box-shadow: inset 0 0 10px #eee;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
img {
|
||||
margin: 30px;
|
||||
padding: 1px;
|
||||
-webkit-border-radius: 3px;
|
||||
-moz-border-radius: 3px;
|
||||
border-radius: 3px;
|
||||
-webkit-box-shadow: 0 3px 10px #dedede, 0 1px 5px #888;
|
||||
-moz-box-shadow: 0 3px 10px #dedede, 0 1px 5px #888;
|
||||
box-shadow: 0 3px 10px #dedede, 0 1px 5px #888;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
footer {
|
||||
background: #eee;
|
||||
width: 100%;
|
||||
padding: 50px 0;
|
||||
text-align: right;
|
||||
border-top: 1px solid #ddd;
|
||||
}
|
||||
|
||||
footer span {
|
||||
display: block;
|
||||
margin-right: 30px;
|
||||
color: #888;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
#menu {
|
||||
position: fixed;
|
||||
font-size: 12px;
|
||||
overflow-y: auto;
|
||||
top: 0;
|
||||
right: 0;
|
||||
margin: 0;
|
||||
height: 100%;
|
||||
padding: 15px 0;
|
||||
text-align: right;
|
||||
border-left: 1px solid #eee;
|
||||
max-width: 400px;
|
||||
overflow: auto;
|
||||
white-space: nowrap;
|
||||
|
||||
-moz-box-shadow: 0 0 2px #888
|
||||
, inset 5px 0 20px rgba(0,0,0,.5)
|
||||
, inset 5px 0 3px rgba(0,0,0,.3);
|
||||
-webkit-box-shadow: 0 0 2px #888
|
||||
, inset 5px 0 20px rgba(0,0,0,.5)
|
||||
, inset 5px 0 3px rgba(0,0,0,.3);
|
||||
box-shadow: 0 0 2px #888
|
||||
, inset 5px 0 20px rgba(0,0,0,.5)
|
||||
, inset 5px 0 3px rgba(0,0,0,.3);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGYAAABmCAMAAAAOARRQAAABelBMVEUjJSU6OzshIyM5OjoqKy02NjgsLS01NTYjJCUzNTUgISMlJSc0NTUvMDA6PDwlJyg1NjYoKis2NjYr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92hGI3Z2BdzzZue+REl1Om4DIWD+RrtUTOJLI+S0jHowXXdAxsGLSd40zYNuEUlOGhrwL6c7tcOtUOvpJCP7QBQS19H+GvZn05ewjlVLz+IGKoC9TyfQjLMBNmXCuqqtTdOSukZW48B0HqgSTCBrBnlFvF4CG2Su7yFzqmJFURK3UmTT3ru050r0ptUpMilYnBJWfl2Bv6kPlUuE1kxxpdzui9AubsR2N2boVSu81OulAwBqoSr1LZ0LLYOomyZHmjqnXlP72s8LnDouEJjtodBvdHaG1jMySYO7crWd90MpCRyCG14vb5IE7Arupw/y/RcCm/Tm3zK6zYj8PYNaGldiUfkB/LHWcmf2lVM+mwyU27a0qq2tscrQ/vzBjN26DnntIrOyGizzXK35yKQdYnUABkyN4saz3WD/viF+eCcsXnIajdWYJWaYHRstIis9CS+tqnFGmz2j5uzfr3Z4prqgK4XOT/PyftvjZqIm8lhkfxJ7Ol3CJF1piYBGAG8wtAkLine truncated
|
||||
}
|
||||
|
||||
#menu::after {
|
||||
display: block;
|
||||
content: '';
|
||||
padding-top: 80px;
|
||||
}
|
||||
|
||||
#logo {
|
||||
position: fixed;
|
||||
bottom: 10px;
|
||||
right: 10px;
|
||||
background: rgba(255,255,255,.1);
|
||||
font-size: 11px;
|
||||
display: block;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
line-height: 20px;
|
||||
text-align: center;
|
||||
-webkit-border-radius: 20px;
|
||||
-moz-border-radius: 20px;
|
||||
border-radius: 20px;
|
||||
-webkit-box-shadow: 0 0 3px rgba(0,0,0,.2);
|
||||
-moz-box-shadow: 0 0 3px rgba(0,0,0,.2);
|
||||
box-shadow: 0 0 3px rgba(0,0,0,.2);
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
#menu li a {
|
||||
display: block;
|
||||
color: white;
|
||||
padding: 0 35px 0 25px;
|
||||
-webkit-transition: background 300ms;
|
||||
-moz-transition: background 300ms;
|
||||
}
|
||||
|
||||
#menu li {
|
||||
position: relative;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
#menu a:hover,
|
||||
#menu a.active {
|
||||
text-decoration: none;
|
||||
background: rgba(255,255,255,.1);
|
||||
}
|
||||
|
||||
#menu li:hover .cov {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
#menu li .dirname {
|
||||
opacity: .60;
|
||||
padding-right: 2px;
|
||||
}
|
||||
|
||||
#menu li .basename {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
#menu .cov {
|
||||
background: rgba(0,0,0,.4);
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 8px;
|
||||
font-size: 9px;
|
||||
opacity: .6;
|
||||
text-align: left;
|
||||
width: 17px;
|
||||
-webkit-border-radius: 10px;
|
||||
-moz-border-radius: 10px;
|
||||
border-radius: 10px;
|
||||
padding: 2px 3px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#stats:nth-child(2n) {
|
||||
display: inline-block;
|
||||
margin-top: 15px;
|
||||
border: 1px solid #eee;
|
||||
padding: 10px;
|
||||
-webkit-box-shadow: inset 0 0 2px #eee;
|
||||
-moz-box-shadow: inset 0 0 2px #eee;
|
||||
box-shadow: inset 0 0 2px #eee;
|
||||
-webkit-border-radius: 5px;
|
||||
-moz-border-radius: 5px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
#stats div {
|
||||
float: left;
|
||||
padding: 0 5px;
|
||||
}
|
||||
|
||||
#stats::after {
|
||||
display: block;
|
||||
content: '';
|
||||
clear: both;
|
||||
}
|
||||
|
||||
#stats .sloc::after {
|
||||
content: ' SLOC';
|
||||
color: #b6b6b6;
|
||||
}
|
||||
|
||||
#stats .percentage::after {
|
||||
content: ' coverage';
|
||||
color: #b6b6b6;
|
||||
}
|
||||
|
||||
#stats .hits,
|
||||
#stats .misses {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.high {
|
||||
color: #00d4b4;
|
||||
}
|
||||
.medium {
|
||||
color: #e87d0d;
|
||||
}
|
||||
.low {
|
||||
color: #d4081a;
|
||||
}
|
||||
.terrible {
|
||||
color: #d4081a;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 80%;
|
||||
margin-top: 10px;
|
||||
border-collapse: collapse;
|
||||
border: 1px solid #cbcbcb;
|
||||
color: #363636;
|
||||
-webkit-border-radius: 3px;
|
||||
-moz-border-radius: 3px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
table thead {
|
||||
display: none;
|
||||
}
|
||||
|
||||
table td.line,
|
||||
table td.hits {
|
||||
width: 20px;
|
||||
background: #eaeaea;
|
||||
text-align: center;
|
||||
font-size: 11px;
|
||||
padding: 0 10px;
|
||||
color: #949494;
|
||||
}
|
||||
|
||||
table td.hits {
|
||||
width: 10px;
|
||||
padding: 2px 5px;
|
||||
color: rgba(0,0,0,.2);
|
||||
background: #f0f0f0;
|
||||
}
|
||||
|
||||
tr.miss td.line,
|
||||
tr.miss td.hits {
|
||||
background: #e6c3c7;
|
||||
}
|
||||
|
||||
tr.miss td {
|
||||
background: #f8d5d8;
|
||||
}
|
||||
|
||||
td.source {
|
||||
padding-left: 15px;
|
||||
line-height: 15px;
|
||||
white-space: pre;
|
||||
font: 12px monaco, monospace;
|
||||
}
|
||||
|
||||
code .comment { color: #ddd }
|
||||
code .init { color: #2F6FAD }
|
||||
code .string { color: #5890AD }
|
||||
code .keyword { color: #8A6343 }
|
||||
code .number { color: #2F6FAD }
|
||||
</style>
|
||||
</head><body><div id="coverage"><h1 id="overview">Coverage</h1><div id="menu"><li><a href="#overview">overview</a></li><li><span class="cov high">86</span><a href="#/home/johan/DevZone/JsBarcode/JsBarcode.js"><span class="dirname">/home/johan/DevZone/JsBarcode/</span><span class="basename">JsBarcode.js</span></a></li><li><span class="cov high">100</span><a href="#/home/johan/DevZone/JsBarcode/barcodes/CODE128.js"><span class="dirname">/home/johan/DevZone/JsBarcode/barcodes/</span><span class="basename">CODE128.js</span></a></li><li><span class="cov high">100</span><a href="#/home/johan/DevZone/JsBarcode/barcodes/CODE39.js"><span class="dirname">/home/johan/DevZone/JsBarcode/barcodes/</span><span class="basename">CODE39.js</span></a></li><li><span class="cov high">100</span><a href="#/home/johan/DevZone/JsBarcode/barcodes/EAN_UPC.js"><span class="dirname">/home/johan/DevZone/JsBarcode/barcodes/</span><span class="basename">EAN_UPC.js</span></a></li><li><span class="cov high">100</span><a href="#/home/johan/DevZone/JsBarcode/barcodes/ITF.js"><span class="dirname">/home/johan/DevZone/JsBarcode/barcodes/</span><span class="basename">ITF.js</span></a></li><li><span class="cov high">100</span><a href="#/home/johan/DevZone/JsBarcode/barcodes/ITF14.js"><span class="dirname">/home/johan/DevZone/JsBarcode/barcodes/</span><span class="basename">ITF14.js</span></a></li><li><span class="cov high">100</span><a href="#/home/johan/DevZone/JsBarcode/barcodes/MSI.js"><span class="dirname">/home/johan/DevZone/JsBarcode/barcodes/</span><span class="basename">MSI.js</span></a></li><li><span class="cov high">100</span><a href="#/home/johan/DevZone/JsBarcode/barcodes/pharmacode.js"><span class="dirname">/home/johan/DevZone/JsBarcode/barcodes/</span><span class="basename">pharmacode.js</span></a></li><a id="logo" href="http://mochajs.org/">m</a></div><div id="stats" class="high"><div class="percentage">97%</div><div class="sloc">571</div><div class="hits">554</div><div class="misses">17</div></div><div id="files"><div class="file"><h2 id="/home/johan/DevZone/JsBarcode/JsBarcode.js">/home/johan/DevZone/JsBarcode/JsBarcode.js</h2><div id="stats" class="high"><div class="percentage">86%</div><div class="sloc">130</div><div class="hits">113</div><div class="misses">17</div></div><table id="source"><thead><tr><th>Line</th><th>Hits</th><th>Source</th></tr></thead><tbody><tr class="hit"><td class="line">1</td><td class="hits">1</td><td class="source">(function(){</td></tr><tr><td class="line">2</td><td class="hits"></td><td class="source"> </td></tr><tr><td class="line">3</td><td class="hits"></td><td class="source"> // Main function, calls drawCanvas(...) in the right way</td></tr><tr class="hit"><td class="line">4</td><td class="hits">1</td><td class="source"> var JsBarcode = function(image, content, options){</td></tr><tr><td class="line">5</td><td class="hits"></td><td class="source"> // If the image is a string, query select call again</td></tr><tr class="hit"><td class="line">6</td><td class="hits">21</td><td class="source"> if(typeof image === "string"){</td></tr><tr class="hit"><td class="line">7</td><td class="hits">1</td><td class="source"> image = document.querySelector(image);</td></tr><tr class="miss"><td class="line">8</td><td class="hits">0</td><td class="source"> JsBarcode(image, content, options);</td></tr><tr><td class="line">9</td><td class="hits"></td><td class="source"> }</td></tr><tr><td class="line">10</td><td class="hits"></td><td class="source"> // If image, draw on canvas and set the uri as src</td></tr><tr class="hit"><td class="line">11</td><td class="hits">20</td><td class="source"> else if(typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLImageElement){</td></tr><tr class="miss"><td class="line">12</td><td class="hits">0</td><td class="source"> canvas = document.createElement('canvas');</td></tr><tr class="miss"><td class="line">13</td><td class="hits">0</td><td class="source"> drawCanvas(canvas, content, options);</td></tr><tr class="miss"><td class="line">14</td><td class="hits">0</td><td class="source"> image.setAttribute("src", canvas.toDataURL());</td></tr><tr><td class="line">15</td><td class="hits"></td><td class="source"> }</td></tr><tr><td class="line">16</td><td class="hits"></td><td class="source"> // If canvas, just draw</td></tr><tr class="hit"><td class="line">17</td><td class="hits">20</td><td class="source"> else if(image.getContext){</td></tr><tr class="hit"><td class="line">18</td><td class="hits">19</td><td class="source"> drawCanvas(image, content, options);</td></tr><tr><td class="line">19</td><td class="hits"></td><td class="source"> }</td></tr><tr><td class="line">20</td><td class="hits"></td><td class="source"> else{</td></tr><tr class="hit"><td class="line">21</td><td class="hits">1</td><td class="source"> throw new Error("Not supported type to draw on.");</td></tr><tr><td class="line">22</td><td class="hitLine truncated
|
||||
+109
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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