初始提交
This commit is contained in:
151
components/Jnpf/Barcode/tki-barcode/barcodes/EAN_UPC/EAN.js
Normal file
151
components/Jnpf/Barcode/tki-barcode/barcodes/EAN_UPC/EAN.js
Normal file
@@ -0,0 +1,151 @@
|
||||
'use strict';
|
||||
|
||||
var _createClass = function() {
|
||||
function defineProperties(target, props) {
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var descriptor = props[i];
|
||||
descriptor.enumerable = descriptor.enumerable || false;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
Object.defineProperty(target, descriptor.key, descriptor);
|
||||
}
|
||||
}
|
||||
return function(Constructor, protoProps, staticProps) {
|
||||
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
};
|
||||
}();
|
||||
|
||||
import _constants from './constants'
|
||||
|
||||
import _encoder2 from './encoder'
|
||||
|
||||
import _Barcode3 from '../Barcode.js'
|
||||
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
|
||||
function _possibleConstructorReturn(self, call) {
|
||||
if (!self) {
|
||||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
||||
}
|
||||
return call && (typeof call === "object" || typeof call === "function") ? call : self;
|
||||
}
|
||||
|
||||
function _inherits(subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
}
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
value: subClass,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ =
|
||||
superClass;
|
||||
}
|
||||
|
||||
// Base class for EAN8 & EAN13
|
||||
var EAN = function(_Barcode) {
|
||||
_inherits(EAN, _Barcode);
|
||||
|
||||
function EAN(data, options) {
|
||||
_classCallCheck(this, EAN);
|
||||
|
||||
// Make sure the font is not bigger than the space between the guard bars
|
||||
var _this = _possibleConstructorReturn(this, (EAN.__proto__ || Object.getPrototypeOf(EAN)).call(this, data,
|
||||
options));
|
||||
|
||||
_this.fontSize = !options.flat && options.fontSize > options.width * 10 ? options.width * 10 : options
|
||||
.fontSize;
|
||||
|
||||
// Make the guard bars go down half the way of the text
|
||||
_this.guardHeight = options.height + _this.fontSize / 2 + options.textMargin;
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(EAN, [{
|
||||
key: 'encode',
|
||||
value: function encode() {
|
||||
return this.options.flat ? this.encodeFlat() : this.encodeGuarded();
|
||||
}
|
||||
}, {
|
||||
key: 'leftText',
|
||||
value: function leftText(from, to) {
|
||||
return this.text.substr(from, to);
|
||||
}
|
||||
}, {
|
||||
key: 'leftEncode',
|
||||
value: function leftEncode(data, structure) {
|
||||
return (0, _encoder2)(data, structure);
|
||||
}
|
||||
}, {
|
||||
key: 'rightText',
|
||||
value: function rightText(from, to) {
|
||||
return this.text.substr(from, to);
|
||||
}
|
||||
}, {
|
||||
key: 'rightEncode',
|
||||
value: function rightEncode(data, structure) {
|
||||
return (0, _encoder2)(data, structure);
|
||||
}
|
||||
}, {
|
||||
key: 'encodeGuarded',
|
||||
value: function encodeGuarded() {
|
||||
var textOptions = {
|
||||
fontSize: this.fontSize
|
||||
};
|
||||
var guardOptions = {
|
||||
height: this.guardHeight
|
||||
};
|
||||
|
||||
return [{
|
||||
data: _constants.SIDE_BIN,
|
||||
options: guardOptions
|
||||
}, {
|
||||
data: this.leftEncode(),
|
||||
text: this.leftText(),
|
||||
options: textOptions
|
||||
}, {
|
||||
data: _constants.MIDDLE_BIN,
|
||||
options: guardOptions
|
||||
}, {
|
||||
data: this.rightEncode(),
|
||||
text: this.rightText(),
|
||||
options: textOptions
|
||||
}, {
|
||||
data: _constants.SIDE_BIN,
|
||||
options: guardOptions
|
||||
}];
|
||||
}
|
||||
}, {
|
||||
key: 'encodeFlat',
|
||||
value: function encodeFlat() {
|
||||
var data = [_constants.SIDE_BIN, this.leftEncode(), _constants.MIDDLE_BIN, this
|
||||
.rightEncode(), _constants.SIDE_BIN
|
||||
];
|
||||
|
||||
return {
|
||||
data: data.join(''),
|
||||
text: this.text
|
||||
};
|
||||
}
|
||||
}]);
|
||||
|
||||
return EAN;
|
||||
}(_Barcode3);
|
||||
|
||||
export default EAN;
|
||||
186
components/Jnpf/Barcode/tki-barcode/barcodes/EAN_UPC/EAN13.js
Normal file
186
components/Jnpf/Barcode/tki-barcode/barcodes/EAN_UPC/EAN13.js
Normal file
@@ -0,0 +1,186 @@
|
||||
'use strict';
|
||||
|
||||
|
||||
var _createClass = function() {
|
||||
function defineProperties(target, props) {
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var descriptor = props[i];
|
||||
descriptor.enumerable = descriptor.enumerable || false;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
Object.defineProperty(target, descriptor.key, descriptor);
|
||||
}
|
||||
}
|
||||
return function(Constructor, protoProps, staticProps) {
|
||||
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
};
|
||||
}();
|
||||
|
||||
var _get = function get(object, property, receiver) {
|
||||
if (object === null) object = Function.prototype;
|
||||
var desc = Object.getOwnPropertyDescriptor(object, property);
|
||||
if (desc === undefined) {
|
||||
var parent = Object.getPrototypeOf(object);
|
||||
if (parent === null) {
|
||||
return undefined;
|
||||
} else {
|
||||
return get(parent, property, receiver);
|
||||
}
|
||||
} else if ("value" in desc) {
|
||||
return desc.value;
|
||||
} else {
|
||||
var getter = desc.get;
|
||||
if (getter === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
return getter.call(receiver);
|
||||
}
|
||||
};
|
||||
|
||||
import _constants from './constants'
|
||||
|
||||
import _EAN3 from './EAN'
|
||||
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
|
||||
function _possibleConstructorReturn(self, call) {
|
||||
if (!self) {
|
||||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
||||
}
|
||||
return call && (typeof call === "object" || typeof call === "function") ? call : self;
|
||||
}
|
||||
|
||||
function _inherits(subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
}
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
value: subClass,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ =
|
||||
superClass;
|
||||
} // Encoding documentation:
|
||||
// https://en.wikipedia.org/wiki/International_Article_Number_(EAN)#Binary_encoding_of_data_digits_into_EAN-13_barcode
|
||||
|
||||
// Calculate the checksum digit
|
||||
// https://en.wikipedia.org/wiki/International_Article_Number_(EAN)#Calculation_of_checksum_digit
|
||||
var checksum = function checksum(number) {
|
||||
var res = number.substr(0, 12).split('').map(function(n) {
|
||||
return +n;
|
||||
}).reduce(function(sum, a, idx) {
|
||||
return idx % 2 ? sum + a * 3 : sum + a;
|
||||
}, 0);
|
||||
|
||||
return (10 - res % 10) % 10;
|
||||
};
|
||||
|
||||
var EAN13 = function(_EAN) {
|
||||
_inherits(EAN13, _EAN);
|
||||
|
||||
function EAN13(data, options) {
|
||||
_classCallCheck(this, EAN13);
|
||||
|
||||
// Add checksum if it does not exist
|
||||
if (data.search(/^[0-9]{12}$/) !== -1) {
|
||||
data += checksum(data);
|
||||
}
|
||||
|
||||
// Adds a last character to the end of the barcode
|
||||
var _this = _possibleConstructorReturn(this, (EAN13.__proto__ || Object.getPrototypeOf(EAN13)).call(this,
|
||||
data, options));
|
||||
|
||||
_this.lastChar = options.lastChar;
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(EAN13, [{
|
||||
key: 'valid',
|
||||
value: function valid() {
|
||||
return this.data.search(/^[0-9]{13}$/) !== -1 && +this.data[12] === checksum(this.data);
|
||||
}
|
||||
}, {
|
||||
key: 'leftText',
|
||||
value: function leftText() {
|
||||
return _get(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype),
|
||||
'leftText', this).call(this, 1, 6);
|
||||
}
|
||||
}, {
|
||||
key: 'leftEncode',
|
||||
value: function leftEncode() {
|
||||
var data = this.data.substr(1, 6);
|
||||
var structure = _constants.EAN13_STRUCTURE[this.data[0]];
|
||||
return _get(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype),
|
||||
'leftEncode', this).call(this, data, structure);
|
||||
}
|
||||
}, {
|
||||
key: 'rightText',
|
||||
value: function rightText() {
|
||||
return _get(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype),
|
||||
'rightText', this).call(this, 7, 6);
|
||||
}
|
||||
}, {
|
||||
key: 'rightEncode',
|
||||
value: function rightEncode() {
|
||||
var data = this.data.substr(7, 6);
|
||||
return _get(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype),
|
||||
'rightEncode', this).call(this, data, 'RRRRRR');
|
||||
}
|
||||
|
||||
// The "standard" way of printing EAN13 barcodes with guard bars
|
||||
|
||||
}, {
|
||||
key: 'encodeGuarded',
|
||||
value: function encodeGuarded() {
|
||||
var data = _get(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype),
|
||||
'encodeGuarded', this).call(this);
|
||||
|
||||
// Extend data with left digit & last character
|
||||
if (this.options.displayValue) {
|
||||
data.unshift({
|
||||
data: '000000000000',
|
||||
text: this.text.substr(0, 1),
|
||||
options: {
|
||||
textAlign: 'left',
|
||||
fontSize: this.fontSize
|
||||
}
|
||||
});
|
||||
|
||||
if (this.options.lastChar) {
|
||||
data.push({
|
||||
data: '00'
|
||||
});
|
||||
data.push({
|
||||
data: '00000',
|
||||
text: this.options.lastChar,
|
||||
options: {
|
||||
fontSize: this.fontSize
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}]);
|
||||
|
||||
return EAN13;
|
||||
}(_EAN3);
|
||||
|
||||
export default EAN13;
|
||||
93
components/Jnpf/Barcode/tki-barcode/barcodes/EAN_UPC/EAN2.js
Normal file
93
components/Jnpf/Barcode/tki-barcode/barcodes/EAN_UPC/EAN2.js
Normal file
@@ -0,0 +1,93 @@
|
||||
'use strict';
|
||||
|
||||
var _createClass = function() {
|
||||
function defineProperties(target, props) {
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var descriptor = props[i];
|
||||
descriptor.enumerable = descriptor.enumerable || false;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
Object.defineProperty(target, descriptor.key, descriptor);
|
||||
}
|
||||
}
|
||||
return function(Constructor, protoProps, staticProps) {
|
||||
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
};
|
||||
}();
|
||||
|
||||
import _constants from './constants'
|
||||
|
||||
import _encoder2 from './encoder'
|
||||
|
||||
import _Barcode3 from '../Barcode.js'
|
||||
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
|
||||
function _possibleConstructorReturn(self, call) {
|
||||
if (!self) {
|
||||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
||||
}
|
||||
return call && (typeof call === "object" || typeof call === "function") ? call : self;
|
||||
}
|
||||
|
||||
function _inherits(subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
}
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
value: subClass,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ =
|
||||
superClass;
|
||||
} // Encoding documentation:
|
||||
// https://en.wikipedia.org/wiki/EAN_2#Encoding
|
||||
|
||||
var EAN2 = function(_Barcode) {
|
||||
_inherits(EAN2, _Barcode);
|
||||
|
||||
function EAN2(data, options) {
|
||||
_classCallCheck(this, EAN2);
|
||||
|
||||
return _possibleConstructorReturn(this, (EAN2.__proto__ || Object.getPrototypeOf(EAN2)).call(this, data,
|
||||
options));
|
||||
}
|
||||
|
||||
_createClass(EAN2, [{
|
||||
key: 'valid',
|
||||
value: function valid() {
|
||||
return this.data.search(/^[0-9]{2}$/) !== -1;
|
||||
}
|
||||
}, {
|
||||
key: 'encode',
|
||||
value: function encode() {
|
||||
// Choose the structure based on the number mod 4
|
||||
var structure = _constants.EAN2_STRUCTURE[parseInt(this.data) % 4];
|
||||
return {
|
||||
// Start bits + Encode the two digits with 01 in between
|
||||
data: '1011' + (0, _encoder2)(this.data, structure, '01'),
|
||||
text: this.text
|
||||
};
|
||||
}
|
||||
}]);
|
||||
|
||||
return EAN2;
|
||||
}(_Barcode3);
|
||||
|
||||
export default EAN2;
|
||||
100
components/Jnpf/Barcode/tki-barcode/barcodes/EAN_UPC/EAN5.js
Normal file
100
components/Jnpf/Barcode/tki-barcode/barcodes/EAN_UPC/EAN5.js
Normal file
@@ -0,0 +1,100 @@
|
||||
'use strict';
|
||||
|
||||
var _createClass = function() {
|
||||
function defineProperties(target, props) {
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var descriptor = props[i];
|
||||
descriptor.enumerable = descriptor.enumerable || false;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
Object.defineProperty(target, descriptor.key, descriptor);
|
||||
}
|
||||
}
|
||||
return function(Constructor, protoProps, staticProps) {
|
||||
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
};
|
||||
}();
|
||||
|
||||
import _constants from './constants'
|
||||
|
||||
import _encoder2 from './encoder'
|
||||
|
||||
import _Barcode3 from '../Barcode.js'
|
||||
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
|
||||
function _possibleConstructorReturn(self, call) {
|
||||
if (!self) {
|
||||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
||||
}
|
||||
return call && (typeof call === "object" || typeof call === "function") ? call : self;
|
||||
}
|
||||
|
||||
function _inherits(subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
}
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
value: subClass,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ =
|
||||
superClass;
|
||||
} // Encoding documentation:
|
||||
// https://en.wikipedia.org/wiki/EAN_5#Encoding
|
||||
|
||||
var checksum = function checksum(data) {
|
||||
var result = data.split('').map(function(n) {
|
||||
return +n;
|
||||
}).reduce(function(sum, a, idx) {
|
||||
return idx % 2 ? sum + a * 9 : sum + a * 3;
|
||||
}, 0);
|
||||
return result % 10;
|
||||
};
|
||||
|
||||
var EAN5 = function(_Barcode) {
|
||||
_inherits(EAN5, _Barcode);
|
||||
|
||||
function EAN5(data, options) {
|
||||
_classCallCheck(this, EAN5);
|
||||
|
||||
return _possibleConstructorReturn(this, (EAN5.__proto__ || Object.getPrototypeOf(EAN5)).call(this, data,
|
||||
options));
|
||||
}
|
||||
|
||||
_createClass(EAN5, [{
|
||||
key: 'valid',
|
||||
value: function valid() {
|
||||
return this.data.search(/^[0-9]{5}$/) !== -1;
|
||||
}
|
||||
}, {
|
||||
key: 'encode',
|
||||
value: function encode() {
|
||||
var structure = _constants.EAN5_STRUCTURE[checksum(this.data)];
|
||||
return {
|
||||
data: '1011' + (0, _encoder2)(this.data, structure, '01'),
|
||||
text: this.text
|
||||
};
|
||||
}
|
||||
}]);
|
||||
|
||||
return EAN5;
|
||||
}(_Barcode3);
|
||||
|
||||
export default EAN5;
|
||||
142
components/Jnpf/Barcode/tki-barcode/barcodes/EAN_UPC/EAN8.js
Normal file
142
components/Jnpf/Barcode/tki-barcode/barcodes/EAN_UPC/EAN8.js
Normal file
@@ -0,0 +1,142 @@
|
||||
'use strict';
|
||||
|
||||
|
||||
var _createClass = function() {
|
||||
function defineProperties(target, props) {
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var descriptor = props[i];
|
||||
descriptor.enumerable = descriptor.enumerable || false;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
Object.defineProperty(target, descriptor.key, descriptor);
|
||||
}
|
||||
}
|
||||
return function(Constructor, protoProps, staticProps) {
|
||||
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
};
|
||||
}();
|
||||
|
||||
var _get = function get(object, property, receiver) {
|
||||
if (object === null) object = Function.prototype;
|
||||
var desc = Object.getOwnPropertyDescriptor(object, property);
|
||||
if (desc === undefined) {
|
||||
var parent = Object.getPrototypeOf(object);
|
||||
if (parent === null) {
|
||||
return undefined;
|
||||
} else {
|
||||
return get(parent, property, receiver);
|
||||
}
|
||||
} else if ("value" in desc) {
|
||||
return desc.value;
|
||||
} else {
|
||||
var getter = desc.get;
|
||||
if (getter === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
return getter.call(receiver);
|
||||
}
|
||||
};
|
||||
|
||||
import _EAN3 from './EAN'
|
||||
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
|
||||
function _possibleConstructorReturn(self, call) {
|
||||
if (!self) {
|
||||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
||||
}
|
||||
return call && (typeof call === "object" || typeof call === "function") ? call : self;
|
||||
}
|
||||
|
||||
function _inherits(subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
}
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
value: subClass,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ =
|
||||
superClass;
|
||||
} // Encoding documentation:
|
||||
// http://www.barcodeisland.com/ean8.phtml
|
||||
|
||||
// Calculate the checksum digit
|
||||
var checksum = function checksum(number) {
|
||||
var res = number.substr(0, 7).split('').map(function(n) {
|
||||
return +n;
|
||||
}).reduce(function(sum, a, idx) {
|
||||
return idx % 2 ? sum + a : sum + a * 3;
|
||||
}, 0);
|
||||
|
||||
return (10 - res % 10) % 10;
|
||||
};
|
||||
|
||||
var EAN8 = function(_EAN) {
|
||||
_inherits(EAN8, _EAN);
|
||||
|
||||
function EAN8(data, options) {
|
||||
_classCallCheck(this, EAN8);
|
||||
|
||||
// Add checksum if it does not exist
|
||||
if (data.search(/^[0-9]{7}$/) !== -1) {
|
||||
data += checksum(data);
|
||||
}
|
||||
|
||||
return _possibleConstructorReturn(this, (EAN8.__proto__ || Object.getPrototypeOf(EAN8)).call(this, data,
|
||||
options));
|
||||
}
|
||||
|
||||
_createClass(EAN8, [{
|
||||
key: 'valid',
|
||||
value: function valid() {
|
||||
return this.data.search(/^[0-9]{8}$/) !== -1 && +this.data[7] === checksum(this.data);
|
||||
}
|
||||
}, {
|
||||
key: 'leftText',
|
||||
value: function leftText() {
|
||||
return _get(EAN8.prototype.__proto__ || Object.getPrototypeOf(EAN8.prototype),
|
||||
'leftText', this).call(this, 0, 4);
|
||||
}
|
||||
}, {
|
||||
key: 'leftEncode',
|
||||
value: function leftEncode() {
|
||||
var data = this.data.substr(0, 4);
|
||||
return _get(EAN8.prototype.__proto__ || Object.getPrototypeOf(EAN8.prototype),
|
||||
'leftEncode', this).call(this, data, 'LLLL');
|
||||
}
|
||||
}, {
|
||||
key: 'rightText',
|
||||
value: function rightText() {
|
||||
return _get(EAN8.prototype.__proto__ || Object.getPrototypeOf(EAN8.prototype),
|
||||
'rightText', this).call(this, 4, 4);
|
||||
}
|
||||
}, {
|
||||
key: 'rightEncode',
|
||||
value: function rightEncode() {
|
||||
var data = this.data.substr(4, 4);
|
||||
return _get(EAN8.prototype.__proto__ || Object.getPrototypeOf(EAN8.prototype),
|
||||
'rightEncode', this).call(this, data, 'RRRR');
|
||||
}
|
||||
}]);
|
||||
|
||||
return EAN8;
|
||||
}(_EAN3);
|
||||
|
||||
export default EAN8;
|
||||
210
components/Jnpf/Barcode/tki-barcode/barcodes/EAN_UPC/UPC.js
Normal file
210
components/Jnpf/Barcode/tki-barcode/barcodes/EAN_UPC/UPC.js
Normal file
@@ -0,0 +1,210 @@
|
||||
"use strict";
|
||||
|
||||
var _createClass = function() {
|
||||
function defineProperties(target, props) {
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var descriptor = props[i];
|
||||
descriptor.enumerable = descriptor.enumerable || false;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
Object.defineProperty(target, descriptor.key, descriptor);
|
||||
}
|
||||
}
|
||||
return function(Constructor, protoProps, staticProps) {
|
||||
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
};
|
||||
}();
|
||||
|
||||
import _encoder2 from './encoder'
|
||||
|
||||
import _Barcode3 from '../Barcode.js'
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
|
||||
function _possibleConstructorReturn(self, call) {
|
||||
if (!self) {
|
||||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
||||
}
|
||||
return call && (typeof call === "object" || typeof call === "function") ? call : self;
|
||||
}
|
||||
|
||||
function _inherits(subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
}
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
value: subClass,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ =
|
||||
superClass;
|
||||
} // Encoding documentation:
|
||||
// https://en.wikipedia.org/wiki/Universal_Product_Code#Encoding
|
||||
|
||||
var UPC = function(_Barcode) {
|
||||
|
||||
|
||||
function UPC(data, options) {
|
||||
_classCallCheck(this, UPC);
|
||||
|
||||
// Add checksum if it does not exist
|
||||
if (data.search(/^[0-9]{11}$/) !== -1) {
|
||||
data += checksum(data);
|
||||
}
|
||||
|
||||
var _this = _possibleConstructorReturn(this, (UPC.__proto__ || Object.getPrototypeOf(UPC)).call(this, data,
|
||||
options));
|
||||
|
||||
_this.displayValue = options.displayValue;
|
||||
|
||||
// Make sure the font is not bigger than the space between the guard bars
|
||||
if (options.fontSize > options.width * 10) {
|
||||
_this.fontSize = options.width * 10;
|
||||
} else {
|
||||
_this.fontSize = options.fontSize;
|
||||
}
|
||||
|
||||
// Make the guard bars go down half the way of the text
|
||||
_this.guardHeight = options.height + _this.fontSize / 2 + options.textMargin;
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(UPC, [{
|
||||
key: "valid",
|
||||
value: function valid() {
|
||||
return this.data.search(/^[0-9]{12}$/) !== -1 && this.data[11] == checksum(this.data);
|
||||
}
|
||||
}, {
|
||||
key: "encode",
|
||||
value: function encode() {
|
||||
if (this.options.flat) {
|
||||
return this.flatEncoding();
|
||||
} else {
|
||||
return this.guardedEncoding();
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "flatEncoding",
|
||||
value: function flatEncoding() {
|
||||
var result = "";
|
||||
|
||||
result += "101";
|
||||
result += (0, _encoder2)(this.data.substr(0, 6), "LLLLLL");
|
||||
result += "01010";
|
||||
result += (0, _encoder2)(this.data.substr(6, 6), "RRRRRR");
|
||||
result += "101";
|
||||
|
||||
return {
|
||||
data: result,
|
||||
text: this.text
|
||||
};
|
||||
}
|
||||
}, {
|
||||
key: "guardedEncoding",
|
||||
value: function guardedEncoding() {
|
||||
var result = [];
|
||||
|
||||
// Add the first digit
|
||||
if (this.displayValue) {
|
||||
result.push({
|
||||
data: "00000000",
|
||||
text: this.text.substr(0, 1),
|
||||
options: {
|
||||
textAlign: "left",
|
||||
fontSize: this.fontSize
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Add the guard bars
|
||||
result.push({
|
||||
data: "101" + (0, _encoder2)(this.data[0], "L"),
|
||||
options: {
|
||||
height: this.guardHeight
|
||||
}
|
||||
});
|
||||
|
||||
// Add the left side
|
||||
result.push({
|
||||
data: (0, _encoder2)(this.data.substr(1, 5), "LLLLL"),
|
||||
text: this.text.substr(1, 5),
|
||||
options: {
|
||||
fontSize: this.fontSize
|
||||
}
|
||||
});
|
||||
|
||||
// Add the middle bits
|
||||
result.push({
|
||||
data: "01010",
|
||||
options: {
|
||||
height: this.guardHeight
|
||||
}
|
||||
});
|
||||
|
||||
// Add the right side
|
||||
result.push({
|
||||
data: (0, _encoder2)(this.data.substr(6, 5), "RRRRR"),
|
||||
text: this.text.substr(6, 5),
|
||||
options: {
|
||||
fontSize: this.fontSize
|
||||
}
|
||||
});
|
||||
|
||||
// Add the end bits
|
||||
result.push({
|
||||
data: (0, _encoder2)(this.data[11], "R") + "101",
|
||||
options: {
|
||||
height: this.guardHeight
|
||||
}
|
||||
});
|
||||
|
||||
// Add the last digit
|
||||
if (this.displayValue) {
|
||||
result.push({
|
||||
data: "00000000",
|
||||
text: this.text.substr(11, 1),
|
||||
options: {
|
||||
textAlign: "right",
|
||||
fontSize: this.fontSize
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}]);
|
||||
|
||||
return UPC;
|
||||
}(_Barcode3);
|
||||
|
||||
// Calulate the checksum digit
|
||||
// https://en.wikipedia.org/wiki/International_Article_Number_(EAN)#Calculation_of_checksum_digit
|
||||
|
||||
|
||||
function checksum(number) {
|
||||
var result = 0;
|
||||
|
||||
var i;
|
||||
for (i = 1; i < 11; i += 2) {
|
||||
result += parseInt(number[i]);
|
||||
}
|
||||
for (i = 0; i < 11; i += 2) {
|
||||
result += parseInt(number[i]) * 3;
|
||||
}
|
||||
|
||||
return (10 - result % 10) % 10;
|
||||
}
|
||||
export default {
|
||||
UPC,
|
||||
checksum
|
||||
};
|
||||
245
components/Jnpf/Barcode/tki-barcode/barcodes/EAN_UPC/UPCE.js
Normal file
245
components/Jnpf/Barcode/tki-barcode/barcodes/EAN_UPC/UPCE.js
Normal file
@@ -0,0 +1,245 @@
|
||||
'use strict';
|
||||
|
||||
var _createClass = function() {
|
||||
function defineProperties(target, props) {
|
||||
for (var i = 0; i < props.length; i++) {
|
||||
var descriptor = props[i];
|
||||
descriptor.enumerable = descriptor.enumerable || false;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
Object.defineProperty(target, descriptor.key, descriptor);
|
||||
}
|
||||
}
|
||||
return function(Constructor, protoProps, staticProps) {
|
||||
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
};
|
||||
}();
|
||||
|
||||
import _encoder2 from './encoder'
|
||||
|
||||
import _Barcode3 from '../Barcode.js'
|
||||
|
||||
import _UPC from './UPC.js'
|
||||
|
||||
function _interopRequireDefault(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
|
||||
function _possibleConstructorReturn(self, call) {
|
||||
if (!self) {
|
||||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
||||
}
|
||||
return call && (typeof call === "object" || typeof call === "function") ? call : self;
|
||||
}
|
||||
|
||||
function _inherits(subClass, superClass) {
|
||||
if (typeof superClass !== "function" && superClass !== null) {
|
||||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||
}
|
||||
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||
constructor: {
|
||||
value: subClass,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
});
|
||||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ =
|
||||
superClass;
|
||||
} // Encoding documentation:
|
||||
// https://en.wikipedia.org/wiki/Universal_Product_Code#Encoding
|
||||
//
|
||||
// UPC-E documentation:
|
||||
// https://en.wikipedia.org/wiki/Universal_Product_Code#UPC-E
|
||||
|
||||
var EXPANSIONS = ["XX00000XXX", "XX10000XXX", "XX20000XXX", "XXX00000XX", "XXXX00000X", "XXXXX00005", "XXXXX00006",
|
||||
"XXXXX00007", "XXXXX00008", "XXXXX00009"
|
||||
];
|
||||
|
||||
var PARITIES = [
|
||||
["EEEOOO", "OOOEEE"],
|
||||
["EEOEOO", "OOEOEE"],
|
||||
["EEOOEO", "OOEEOE"],
|
||||
["EEOOOE", "OOEEEO"],
|
||||
["EOEEOO", "OEOOEE"],
|
||||
["EOOEEO", "OEEOOE"],
|
||||
["EOOOEE", "OEEEOO"],
|
||||
["EOEOEO", "OEOEOE"],
|
||||
["EOEOOE", "OEOEEO"],
|
||||
["EOOEOE", "OEEOEO"]
|
||||
];
|
||||
|
||||
var UPCE = function(_Barcode) {
|
||||
_inherits(UPCE, _Barcode);
|
||||
|
||||
function UPCE(data, options) {
|
||||
_classCallCheck(this, UPCE);
|
||||
|
||||
var _this = _possibleConstructorReturn(this, (UPCE.__proto__ || Object.getPrototypeOf(UPCE)).call(this,
|
||||
data, options));
|
||||
// Code may be 6 or 8 digits;
|
||||
// A 7 digit code is ambiguous as to whether the extra digit
|
||||
// is a UPC-A check or number system digit.
|
||||
|
||||
|
||||
_this.isValid = false;
|
||||
if (data.search(/^[0-9]{6}$/) !== -1) {
|
||||
_this.middleDigits = data;
|
||||
_this.upcA = expandToUPCA(data, "0");
|
||||
_this.text = options.text || '' + _this.upcA[0] + data + _this.upcA[_this.upcA.length - 1];
|
||||
_this.isValid = true;
|
||||
} else if (data.search(/^[01][0-9]{7}$/) !== -1) {
|
||||
_this.middleDigits = data.substring(1, data.length - 1);
|
||||
_this.upcA = expandToUPCA(_this.middleDigits, data[0]);
|
||||
|
||||
if (_this.upcA[_this.upcA.length - 1] === data[data.length - 1]) {
|
||||
_this.isValid = true;
|
||||
} else {
|
||||
// checksum mismatch
|
||||
return _possibleConstructorReturn(_this);
|
||||
}
|
||||
} else {
|
||||
return _possibleConstructorReturn(_this);
|
||||
}
|
||||
|
||||
_this.displayValue = options.displayValue;
|
||||
|
||||
// Make sure the font is not bigger than the space between the guard bars
|
||||
if (options.fontSize > options.width * 10) {
|
||||
_this.fontSize = options.width * 10;
|
||||
} else {
|
||||
_this.fontSize = options.fontSize;
|
||||
}
|
||||
|
||||
// Make the guard bars go down half the way of the text
|
||||
_this.guardHeight = options.height + _this.fontSize / 2 + options.textMargin;
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(UPCE, [{
|
||||
key: 'valid',
|
||||
value: function valid() {
|
||||
return this.isValid;
|
||||
}
|
||||
}, {
|
||||
key: 'encode',
|
||||
value: function encode() {
|
||||
if (this.options.flat) {
|
||||
return this.flatEncoding();
|
||||
} else {
|
||||
return this.guardedEncoding();
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'flatEncoding',
|
||||
value: function flatEncoding() {
|
||||
var result = "";
|
||||
|
||||
result += "101";
|
||||
result += this.encodeMiddleDigits();
|
||||
result += "010101";
|
||||
|
||||
return {
|
||||
data: result,
|
||||
text: this.text
|
||||
};
|
||||
}
|
||||
}, {
|
||||
key: 'guardedEncoding',
|
||||
value: function guardedEncoding() {
|
||||
var result = [];
|
||||
|
||||
// Add the UPC-A number system digit beneath the quiet zone
|
||||
if (this.displayValue) {
|
||||
result.push({
|
||||
data: "00000000",
|
||||
text: this.text[0],
|
||||
options: {
|
||||
textAlign: "left",
|
||||
fontSize: this.fontSize
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Add the guard bars
|
||||
result.push({
|
||||
data: "101",
|
||||
options: {
|
||||
height: this.guardHeight
|
||||
}
|
||||
});
|
||||
|
||||
// Add the 6 UPC-E digits
|
||||
result.push({
|
||||
data: this.encodeMiddleDigits(),
|
||||
text: this.text.substring(1, 7),
|
||||
options: {
|
||||
fontSize: this.fontSize
|
||||
}
|
||||
});
|
||||
|
||||
// Add the end bits
|
||||
result.push({
|
||||
data: "010101",
|
||||
options: {
|
||||
height: this.guardHeight
|
||||
}
|
||||
});
|
||||
|
||||
// Add the UPC-A check digit beneath the quiet zone
|
||||
if (this.displayValue) {
|
||||
result.push({
|
||||
data: "00000000",
|
||||
text: this.text[7],
|
||||
options: {
|
||||
textAlign: "right",
|
||||
fontSize: this.fontSize
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}, {
|
||||
key: 'encodeMiddleDigits',
|
||||
value: function encodeMiddleDigits() {
|
||||
var numberSystem = this.upcA[0];
|
||||
var checkDigit = this.upcA[this.upcA.length - 1];
|
||||
var parity = PARITIES[parseInt(checkDigit)][parseInt(numberSystem)];
|
||||
return (0, _encoder2)(this.middleDigits, parity);
|
||||
}
|
||||
}]);
|
||||
|
||||
return UPCE;
|
||||
}(_Barcode3);
|
||||
|
||||
function expandToUPCA(middleDigits, numberSystem) {
|
||||
var lastUpcE = parseInt(middleDigits[middleDigits.length - 1]);
|
||||
var expansion = EXPANSIONS[lastUpcE];
|
||||
|
||||
var result = "";
|
||||
var digitIndex = 0;
|
||||
for (var i = 0; i < expansion.length; i++) {
|
||||
var c = expansion[i];
|
||||
if (c === 'X') {
|
||||
result += middleDigits[digitIndex++];
|
||||
} else {
|
||||
result += c;
|
||||
}
|
||||
}
|
||||
|
||||
result = '' + numberSystem + result;
|
||||
return '' + result + (0, _UPC.checksum)(result);
|
||||
}
|
||||
|
||||
export default UPCE;
|
||||
@@ -0,0 +1,48 @@
|
||||
'use strict';
|
||||
|
||||
// Standard start end and middle bits
|
||||
var SIDE_BIN = '101';
|
||||
var MIDDLE_BIN = '01010';
|
||||
|
||||
var BINARIES = {
|
||||
'L': [ // The L (left) type of encoding
|
||||
'0001101', '0011001', '0010011', '0111101', '0100011', '0110001', '0101111', '0111011', '0110111',
|
||||
'0001011'
|
||||
],
|
||||
'G': [ // The G type of encoding
|
||||
'0100111', '0110011', '0011011', '0100001', '0011101', '0111001', '0000101', '0010001', '0001001',
|
||||
'0010111'
|
||||
],
|
||||
'R': [ // The R (right) type of encoding
|
||||
'1110010', '1100110', '1101100', '1000010', '1011100', '1001110', '1010000', '1000100', '1001000',
|
||||
'1110100'
|
||||
],
|
||||
'O': [ // The O (odd) encoding for UPC-E
|
||||
'0001101', '0011001', '0010011', '0111101', '0100011', '0110001', '0101111', '0111011', '0110111',
|
||||
'0001011'
|
||||
],
|
||||
'E': [ // The E (even) encoding for UPC-E
|
||||
'0100111', '0110011', '0011011', '0100001', '0011101', '0111001', '0000101', '0010001', '0001001',
|
||||
'0010111'
|
||||
]
|
||||
};
|
||||
|
||||
// Define the EAN-2 structure
|
||||
var EAN2_STRUCTURE = ['LL', 'LG', 'GL', 'GG'];
|
||||
|
||||
// Define the EAN-5 structure
|
||||
var EAN5_STRUCTURE = ['GGLLL', 'GLGLL', 'GLLGL', 'GLLLG', 'LGGLL', 'LLGGL', 'LLLGG', 'LGLGL', 'LGLLG', 'LLGLG'];
|
||||
|
||||
// Define the EAN-13 structure
|
||||
var EAN13_STRUCTURE = ['LLLLLL', 'LLGLGG', 'LLGGLG', 'LLGGGL', 'LGLLGG', 'LGGLLG', 'LGGGLL', 'LGLGLG', 'LGLGGL',
|
||||
'LGGLGL'
|
||||
];
|
||||
|
||||
export default {
|
||||
SIDE_BIN,
|
||||
MIDDLE_BIN,
|
||||
BINARIES,
|
||||
EAN2_STRUCTURE,
|
||||
EAN5_STRUCTURE,
|
||||
EAN13_STRUCTURE
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
import _constants from './constants'
|
||||
|
||||
// Encode data string
|
||||
var encode = function encode(data, structure, separator) {
|
||||
var encoded = data.split('').map(function(val, idx) {
|
||||
return _constants.BINARIES[structure[idx]];
|
||||
}).map(function(val, idx) {
|
||||
return val ? val[data[idx]] : '';
|
||||
});
|
||||
|
||||
if (separator) {
|
||||
var last = data.length - 1;
|
||||
encoded = encoded.map(function(val, idx) {
|
||||
return idx < last ? val + separator : val;
|
||||
});
|
||||
}
|
||||
|
||||
return encoded.join('');
|
||||
};
|
||||
|
||||
export default encode
|
||||
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
import EAN13 from './EAN13'
|
||||
|
||||
import EAN8 from './EAN8.js'
|
||||
|
||||
import EAN5 from './EAN5.js'
|
||||
|
||||
import EAN2 from './EAN2.js'
|
||||
|
||||
import UPC from './UPC.js'
|
||||
|
||||
import UPCE from './UPCE.js'
|
||||
|
||||
export default {
|
||||
EAN13,
|
||||
EAN8,
|
||||
EAN5,
|
||||
EAN2,
|
||||
UPC: UPC.UPC,
|
||||
UPCE
|
||||
}
|
||||
Reference in New Issue
Block a user