Remove EAN 2 and 5 as they are not supported by the loyalty cards app

master
Eric de Boer 2024-06-21 09:34:28 +02:00
parent 5f18f47d8a
commit 39af2474d2
5 changed files with 0 additions and 149 deletions

View File

@ -1,55 +0,0 @@
// Encoding documentation:
// https://en.wikipedia.org/wiki/EAN_2#Encoding
/*
* JS source adapted from https://github.com/lindell/JsBarcode
*
* The MIT License (MIT)
*
* Copyright (c) 2016 Johan Lindell (johan@lindell.me)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
const constants = require("cards.constants.js");
const encode = require("cards.encode.js");
const Barcode = require("cards.Barcode.js");
class EAN2 extends Barcode {
constructor(data, options) {
super(data, options);
}
valid() {
return /^[0-9][0-9]$/.test(this.data);
}
encode(){
// Choose the structure based on the number mod 4
const structure = constants.EAN2_STRUCTURE[parseInt(this.data) % 4];
return {
// Start bits + Encode the two digits with 01 in between
data: '1011' + encode(this.data, structure, '01'),
text: this.text
};
}
}
module.exports = EAN2;

View File

@ -1,65 +0,0 @@
// Encoding documentation:
// https://en.wikipedia.org/wiki/EAN_5#Encoding
/*
* JS source adapted from https://github.com/lindell/JsBarcode
*
* The MIT License (MIT)
*
* Copyright (c) 2016 Johan Lindell (johan@lindell.me)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
const constants = require("cards.constants.js");
const encode = require("cards.encode.js");
const Barcode = require("cards.Barcode.js");
const checksum = (data) => {
const result = data
.split('')
.map(n => +n)
.reduce((sum, a, idx) => {
return idx % 2
? sum + a * 9
: sum + a * 3;
}, 0);
return result % 10;
};
class EAN5 extends Barcode {
constructor(data, options) {
super(data, options);
}
valid() {
return /^[0-9][0-9][0-9][0-9][0-9]$/.test(this.data);
}
encode() {
const structure = constants.EAN5_STRUCTURE[checksum(this.data)];
return {
data: '1011' + encode(this.data, structure, '01'),
text: this.text
};
}
}
module.exports = EAN5;

View File

@ -133,24 +133,6 @@ function showCode(card) {
printLinearCode(code.encode().data); printLinearCode(code.encode().data);
break; break;
} }
case "EAN_2": {
g.setFont("Vector:20");
g.setFontAlign(0,1).setColor(BLACK);
g.drawString(card.value, g.getWidth()/2, g.getHeight());
const EAN2 = require("cards.EAN2.js");
let code = new EAN2(card.value, {});
printLinearCode(code.encode().data);
break;
}
case "EAN_5": {
g.setFont("Vector:20");
g.setFontAlign(0,1).setColor(BLACK);
g.drawString(card.value, g.getWidth()/2, g.getHeight());
const EAN5 = require("cards.EAN5.js");
let code = new EAN5(card.value, {});
printLinearCode(code.encode().data);
break;
}
case "EAN_8": { case "EAN_8": {
g.setFont("Vector:20"); g.setFont("Vector:20");
g.setFontAlign(0,1).setColor(BLACK); g.setFontAlign(0,1).setColor(BLACK);

View File

@ -52,15 +52,6 @@ module.exports = {
] ]
}, },
// Define the EAN-2 structure
EAN2_STRUCTURE : ['LL', 'LG', 'GL', 'GG'],
// Define the EAN-5 structure
EAN5_STRUCTURE : [
'GGLLL', 'GLGLL', 'GLLGL', 'GLLLG', 'LGGLL',
'LLGGL', 'LLLGG', 'LGLGL', 'LGLLG', 'LLGLG'
],
// Define the EAN-13 structure // Define the EAN-13 structure
EAN13_STRUCTURE : [ EAN13_STRUCTURE : [
'LLLLLL', 'LLGLGG', 'LLGGLG', 'LLGGGL', 'LGLLGG', 'LLLLLL', 'LLGLGG', 'LLGGLG', 'LLGGGL', 'LGLLGG',

View File

@ -18,8 +18,6 @@
{"name":"cards.code39.js","url":"code39.js"}, {"name":"cards.code39.js","url":"code39.js"},
{"name":"cards.constants.js","url":"constants.js"}, {"name":"cards.constants.js","url":"constants.js"},
{"name":"cards.EAN.js","url":"EAN.js"}, {"name":"cards.EAN.js","url":"EAN.js"},
{"name":"cards.EAN2.js","url":"EAN2.js"},
{"name":"cards.EAN5.js","url":"EAN5.js"},
{"name":"cards.EAN8.js","url":"EAN8.js"}, {"name":"cards.EAN8.js","url":"EAN8.js"},
{"name":"cards.EAN13.js","url":"EAN13.js"}, {"name":"cards.EAN13.js","url":"EAN13.js"},
{"name":"cards.UPC.js","url":"UPC.js"}, {"name":"cards.UPC.js","url":"UPC.js"},