UNPKG

epc-tds-ts

Version:

EPC Tag Data Standard encoding and decoding library, written in javascript for Node.js

129 lines (128 loc) 6.08 kB
"use strict"; /** * 96-bit Global Location Number With or Without Extension (SGLN) * * The SGLN EPC scheme is used to assign a unique identity to a physical location, such as a specific * building or a specific unit of shelving within a warehouse. * * Typical use: Location * * @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 Sgln96 = require('./sgln96').Sgln96; var Sgln195 = /** @class */ (function (_super) { __extends(Sgln195, _super); function Sgln195(hexEpc) { var _this = _super.call(this, Sgln195.TOTAL_BITS) || this; if (hexEpc) { _super.prototype.setFromHexString.call(_this, hexEpc); } else { _super.prototype.set.call(_this, Sgln195.EPC_HEADER, Epc.EPC_HEADER_OFFSET, Epc.EPC_HEADER_END); } return _this; } Sgln195.prototype.clone = function () { return new Sgln195().setFromBitArray(this); }; Sgln195.prototype.getType = function () { return Type.SGLN195; }; Sgln195.prototype.toTagURI = function () { var partition = Sgln96.PARTITIONS[this.getPartition()]; return Sgln195.TAG_URI_TEMPLATE(this.getFilter(), this.getSegmentString(partition.a), this.getSegmentString(partition.b), this.getExtension()); }; Sgln195.prototype.toIdURI = function () { var partition = Sgln96.PARTITIONS[this.getPartition()]; return Sgln195.PID_URI_TEMPLATE(this.getSegmentString(partition.a), this.getSegmentString(partition.b), this.getExtension()); }; Sgln195.prototype.toBarcode = function () { return this.getGln(); }; Sgln195.prototype.getTotalBits = function () { return Sgln195.TOTAL_BITS; }; Sgln195.prototype.getHeader = function () { return Sgln195.EPC_HEADER; }; Sgln195.prototype.getPartition = function () { return _super.prototype.get.call(this, Sgln195.PARTITION_OFFSET, Sgln195.PARTITION_END); }; Sgln195.prototype.setPartition = function (value) { if (value < 0 || value >= Sgln96.PARTITIONS.length) { throw new Error("Value '".concat(value, "' out of range (min: 0, max: ").concat(Sgln96.PARTITIONS.length - 1, ")")); } _super.prototype.set.call(this, value, Sgln195.PARTITION_OFFSET, Sgln195.PARTITION_END); return this; }; Sgln195.prototype.getGln = function () { var partition = Sgln96.PARTITIONS[this.getPartition()]; var result = this.getSegmentString(partition.a) + this.getSegmentString(partition.b); return result + Utils.computeCheckDigit(result); }; Sgln195.prototype.setGln = function (gln) { var partition = Sgln96.PARTITIONS[this.getPartition()]; _super.prototype.setSegment.call(this, gln.substring(0, partition.a.digits), partition.a); _super.prototype.setSegment.call(this, Number(gln.substring(partition.a.digits, partition.a.digits + partition.b.digits)), partition.b); return this; }; Sgln195.prototype.getCompany = function () { return _super.prototype.getSegment.call(this, Sgln96.PARTITIONS[this.getPartition()].a); }; Sgln195.prototype.setCompany = function (value) { _super.prototype.setSegment.call(this, value, Sgln96.PARTITIONS[this.getPartition()].a); return this; }; Sgln195.prototype.getLocation = function () { return _super.prototype.getSegment.call(this, Sgln96.PARTITIONS[this.getPartition()].b); }; Sgln195.prototype.setLocation = function (value) { _super.prototype.setSegment.call(this, value, Sgln96.PARTITIONS[this.getPartition()].b); return this; }; Sgln195.prototype.getExtension = function () { return _super.prototype.getString.call(this, Sgln195.SERIAL_OFFSET, Sgln195.SERIAL_END, Sgln195.CHAR_BITS); }; /** * All values permitted by GS1 General Specifications (up to 20 alphanumeric characters) * @param value */ Sgln195.prototype.setExtension = function (value) { if (!value || value.length > Sgln195.MAX_SERIAL_LEN) throw new Error("Value '".concat(value, "' length out of range (max length: ").concat(Sgln195.MAX_SERIAL_LEN, ")")); _super.prototype.setString.call(this, value, Sgln195.SERIAL_OFFSET, Sgln195.SERIAL_END, Sgln195.CHAR_BITS); return this; }; Sgln195.EPC_HEADER = 0x39; Sgln195.TOTAL_BITS = 195; Sgln195.PARTITION_OFFSET = 11; Sgln195.PARTITION_END = 14; Sgln195.EXTENSION_OFFSET = 55; Sgln195.EXTENSION_END = Sgln195.TOTAL_BITS; Sgln195.EXTENSION_BITS = 140; Sgln195.CHAR_BITS = (Sgln195.SERIAL_END - Sgln195.SERIAL_OFFSET) / Sgln195.MAX_SERIAL_LEN; // 7 Sgln195.MAX_SERIAL_LEN = 16; Sgln195.TAG_URI_TEMPLATE = function (filter, company, location, extension) { return "urn:epc:tag:sgln-195:".concat(filter, ".").concat(company, ".").concat(location, ".").concat(extension); }; // F.C.L.E (Filter, Company, Location, Extension) Sgln195.PID_URI_TEMPLATE = function (company, location, extension) { return "urn:epc:id:sgln:".concat(company, ".").concat(location, ".").concat(extension); }; // C.L.E (Company, Location, Extension) return Sgln195; }(Epc)); module.exports = { Sgln195: Sgln195 };