epc-tds-ts
Version:
EPC Tag Data Standard encoding and decoding library, written in javascript for Node.js
123 lines (122 loc) • 5.82 kB
JavaScript
"use strict";
/**
* 96-bit Serial Shipping Container Code (SSCC)
*
* The Serial Shipping Container Code EPC scheme is used to assign a unique identity to a logistics
* handling unit, such as the aggregate contents of a shipping container or a pallet load.
*
* Typical use: Pallet load or other logistics unit load
*
* @author Sergio S.
*
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var Utils = require('../utils/utils');
var Epc = require('../epc').Epc;
var Type = require('../type').Type;
var Partition = require('../partition').Partition;
var Sscc96 = /** @class */ (function (_super) {
__extends(Sscc96, _super);
function Sscc96(hexEpc) {
var _this = _super.call(this, Sscc96.TOTAL_BITS) || this;
if (hexEpc) {
_super.prototype.setFromHexString.call(_this, hexEpc);
}
else {
_super.prototype.set.call(_this, Sscc96.EPC_HEADER, Epc.EPC_HEADER_OFFSET, Epc.EPC_HEADER_END);
}
return _this;
}
Sscc96.prototype.clone = function () {
return new Sscc96().setFromBitArray(this);
};
Sscc96.prototype.getType = function () {
return Type.SSCC96;
};
Sscc96.prototype.toTagURI = function () {
var partition = Sscc96.PARTITIONS[this.getPartition()];
return Sscc96.TAG_URI_TEMPLATE(this.getFilter(), this.getSegmentString(partition.a), this.getSegmentString(partition.b));
};
Sscc96.prototype.toIdURI = function () {
var partition = Sscc96.PARTITIONS[this.getPartition()];
return Sscc96.PID_URI_TEMPLATE(this.getSegmentString(partition.a), this.getSegmentString(partition.b));
};
Sscc96.prototype.toBarcode = function () {
return this.getSscc();
};
Sscc96.prototype.getTotalBits = function () {
return Sscc96.TOTAL_BITS;
};
Sscc96.prototype.getHeader = function () {
return Sscc96.EPC_HEADER;
};
Sscc96.prototype.getPartition = function () {
return _super.prototype.get.call(this, Sscc96.PARTITION_OFFSET, Sscc96.PARTITION_END);
};
Sscc96.prototype.setPartition = function (value) {
if (value < 0 || value >= Sscc96.PARTITIONS.length) {
throw new Error("Value '".concat(value, "' out of range (min: 0, max: ").concat(Sscc96.PARTITIONS.length - 1, ")"));
}
_super.prototype.set.call(this, value, Sscc96.PARTITION_OFFSET, Sscc96.PARTITION_END);
return this;
};
Sscc96.prototype.getSscc = function () {
var partition = Sscc96.PARTITIONS[this.getPartition()];
var item = _super.prototype.getSegmentString.call(this, partition.b);
var result = item.substring(0, 1) + _super.prototype.getSegmentString.call(this, partition.a) + item.substring(1);
return result + Utils.computeCheckDigit(result);
};
Sscc96.prototype.setSscc = function (gtin) {
var partition = Sscc96.PARTITIONS[this.getPartition()];
_super.prototype.setSegment.call(this, gtin.substring(1, partition.a.digits + 1), partition.a);
_super.prototype.setSegment.call(this, Number(gtin.charAt(0) + gtin.substring(partition.a.digits + 1, partition.a.digits + partition.b.digits)), partition.b);
return this;
};
Sscc96.prototype.getCompanyPrefix = function () {
return _super.prototype.getSegment.call(this, Sscc96.PARTITIONS[this.getPartition()].a);
};
Sscc96.prototype.setCompanyPrefix = function (value) {
_super.prototype.setSegment.call(this, value, Sscc96.PARTITIONS[this.getPartition()].a);
return this;
};
Sscc96.prototype.getSerialReference = function () {
return _super.prototype.getSegment.call(this, Sscc96.PARTITIONS[this.getPartition()].b);
};
Sscc96.prototype.setSerialReference = function (value) {
_super.prototype.setSegment.call(this, value, Sscc96.PARTITIONS[this.getPartition()].b);
return this;
};
Sscc96.prototype.getMaxSerialReference = function () {
return Sscc96.PARTITIONS[this.getPartition()].b.maxValue;
};
Sscc96.EPC_HEADER = 0x31;
Sscc96.TOTAL_BITS = 96;
Sscc96.PARTITION_OFFSET = 11;
Sscc96.PARTITION_END = 14;
Sscc96.TAG_URI_TEMPLATE = function (filter, company, serial) { return "urn:epc:tag:sscc-96:".concat(filter, ".").concat(company, ".").concat(serial); }; // F.C.S (Filter, Company, Serial)
Sscc96.PID_URI_TEMPLATE = function (company, serial) { return "urn:epc:id:sscc:".concat(company, ".").concat(serial); }; // C.S (Company, Serial)
// Partition table columns: Company prefix, Serial Reference
Sscc96.PARTITIONS = [new Partition(Sscc96.PARTITION_END, 40, 12, 18, 5),
new Partition(Sscc96.PARTITION_END, 37, 11, 21, 6),
new Partition(Sscc96.PARTITION_END, 34, 10, 24, 7),
new Partition(Sscc96.PARTITION_END, 30, 9, 28, 8),
new Partition(Sscc96.PARTITION_END, 27, 8, 31, 9),
new Partition(Sscc96.PARTITION_END, 24, 7, 34, 10),
new Partition(Sscc96.PARTITION_END, 20, 6, 38, 11)]; // 6 20 06 38 11
return Sscc96;
}(Epc));
module.exports = { Sscc96: Sscc96 };