UNPKG

epc-tds-ts

Version:

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

113 lines (112 loc) 4.74 kB
"use strict"; /** * 96-bit Serialised Global Trade Item Number (SGTIN) * * The General Identifier EPC scheme is independent of any specifications or identity scheme outside * the EPCglobal Tag Data Standard. * * Typical use: Unspecified * * @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 Gid96 = /** @class */ (function (_super) { __extends(Gid96, _super); function Gid96(hexEpc) { var _this = _super.call(this, Gid96.TOTAL_BITS) || this; if (hexEpc) { _super.prototype.setFromHexString.call(_this, hexEpc); } else { _super.prototype.set.call(_this, Gid96.EPC_HEADER, Epc.EPC_HEADER_OFFSET, Epc.EPC_HEADER_END); } return _this; } Gid96.prototype.getFilter = function () { throw new Error('Unsupported method.'); }; Gid96.prototype.setFilter = function () { throw new Error('Unsupported method.'); }; Gid96.prototype.clone = function () { return new Gid96().setFromBitArray(this); }; Gid96.prototype.getType = function () { return Type.GID96; }; Gid96.prototype.toTagURI = function () { return Gid96.TAG_URI_TEMPLATE(this.getManager(), this.getClass(), this.getSerial()); }; Gid96.prototype.toIdURI = function () { return Gid96.PID_URI_TEMPLATE(this.getManager(), this.getClass(), this.getSerial()); }; Gid96.prototype.getTotalBits = function () { return Gid96.TOTAL_BITS; }; Gid96.prototype.getHeader = function () { return Gid96.EPC_HEADER; }; Gid96.prototype.getManager = function () { return _super.prototype.get.call(this, Gid96.MANAGER_OFFSET, Gid96.MANAGER_END); }; Gid96.prototype.setManager = function (value) { if (value > Gid96.MAX_MANAGER) throw new Error("Value '".concat(value, "' out of range (min: 0, max: ").concat(Gid96.MAX_MANAGER, ")")); _super.prototype.set.call(this, value, Gid96.MANAGER_OFFSET, Gid96.MANAGER_END); return this; }; Gid96.prototype.getClass = function () { return _super.prototype.get.call(this, Gid96.CLASS_OFFSET, Gid96.CLASS_END); }; Gid96.prototype.setClass = function (value) { if (value > Gid96.MAX_CLASS) throw new Error("Value '".concat(value, "' out of range (min: 0, max: ").concat(Gid96.MAX_CLASS, ")")); _super.prototype.set.call(this, value, Gid96.CLASS_OFFSET, Gid96.CLASS_END); return this; }; Gid96.prototype.getSerial = function () { return _super.prototype.get.call(this, Gid96.SERIAL_OFFSET, Gid96.SERIAL_END); }; Gid96.prototype.setSerial = function (value) { if (value > Gid96.MAX_SERIAL) throw new Error("Value '".concat(value, "' out of range (min: 0, max: ").concat(Gid96.MAX_SERIAL, ")")); _super.prototype.set.call(this, value, Gid96.SERIAL_OFFSET, Gid96.SERIAL_END); return this; }; Gid96.EPC_HEADER = 0x35; Gid96.TOTAL_BITS = 96; Gid96.MANAGER_OFFSET = 8; Gid96.MANAGER_END = 36; Gid96.MANAGER_BITS = 28; Gid96.MAX_MANAGER = Utils.getMaxValue(Gid96.MANAGER_BITS); Gid96.CLASS_OFFSET = 36; Gid96.CLASS_END = 60; Gid96.CLASS_BITS = 24; Gid96.MAX_CLASS = Utils.getMaxValue(Gid96.CLASS_BITS); Gid96.SERIAL_OFFSET = 60; Gid96.SERIAL_END = Gid96.TOTAL_BITS; Gid96.SERIAL_BITS = 36; Gid96.MAX_SERIAL = Utils.getMaxValue(Gid96.SERIAL_BITS); Gid96.TAG_URI_TEMPLATE = function (manager, clazz, serial) { return "urn:epc:tag:gid-96:".concat(manager, ".").concat(clazz, ".").concat(serial); }; // M.C.S (Manager, Class, Serial) Gid96.PID_URI_TEMPLATE = function (manager, clazz, serial) { return "urn:epc:id:gid:".concat(manager, ".").concat(clazz, ".").concat(serial); }; // M.C.S (Manager, Class, Serial) return Gid96; }(Epc)); module.exports = { Gid96: Gid96 };