UNPKG

epc-tds-ts

Version:

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

121 lines (120 loc) 5.58 kB
"use strict"; /** * 202-bit Global Individual Asset Identifier (GIAI) * * The Global Individual Asset Identifier EPC scheme is used to assign a unique identity to a specific * asset, such as a forklift or a computer. * * Typical use: Fixed asset * * @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 Giai202 = /** @class */ (function (_super) { __extends(Giai202, _super); function Giai202(hexEpc) { var _this = _super.call(this, Giai202.TOTAL_BITS) || this; if (hexEpc) { _super.prototype.setFromHexString.call(_this, hexEpc); } else { _super.prototype.set.call(_this, Giai202.EPC_HEADER, Epc.EPC_HEADER_OFFSET, Epc.EPC_HEADER_END); } return _this; } Giai202.prototype.clone = function () { return new Giai202().setFromBitArray(this); }; Giai202.prototype.getType = function () { return Type.GIAI202; }; Giai202.prototype.toTagURI = function () { var partition = Giai202.PARTITIONS[this.getPartition()]; return Giai202.TAG_URI_TEMPLATE(this.getFilter(), this.getSegment(partition.a), this.getSegment(partition.b)); }; Giai202.prototype.toIdURI = function () { var partition = Giai202.PARTITIONS[this.getPartition()]; return Giai202.PID_URI_TEMPLATE(this.getSegment(partition.a), this.getSegment(partition.b)); }; Giai202.prototype.toBarcode = function () { return this.getGiai(); }; Giai202.prototype.getTotalBits = function () { return Giai202.TOTAL_BITS; }; Giai202.prototype.getHeader = function () { return Giai202.EPC_HEADER; }; Giai202.prototype.getPartition = function () { return _super.prototype.get.call(this, Giai202.PARTITION_OFFSET, Giai202.PARTITION_END); }; Giai202.prototype.setPartition = function (value) { if (value < 0 || value >= Giai202.PARTITIONS.length) { throw new Error("Value '".concat(value, "' out of range (min: 0, max: ").concat(Giai202.PARTITIONS.length - 1, ")")); } _super.prototype.set.call(this, value, Giai202.PARTITION_OFFSET, Giai202.PARTITION_END); return this; }; Giai202.prototype.getGiai = function () { var partition = Giai202.PARTITIONS[this.getPartition()]; var companyPrefix = _super.prototype.getSegmentString.call(this, partition.a); var asset = _super.prototype.getSegment.call(this, partition.b); return String(companyPrefix) + asset; }; Giai202.prototype.setGiai = function (giai) { var partition = Giai202.PARTITIONS[this.getPartition()]; _super.prototype.setSegment.call(this, giai.substring(0, partition.a.digits), partition.a); var tmp = partition.a.digits + partition.b.digits; _super.prototype.setSegment.call(this, giai.substring(partition.a.digits, tmp), partition.b); return this; }; Giai202.prototype.getCompanyPrefix = function () { return _super.prototype.getSegment.call(this, Giai202.PARTITIONS[this.getPartition()].a); }; Giai202.prototype.setCompanyPrefix = function (value) { _super.prototype.setSegment.call(this, value, Giai202.PARTITIONS[this.getPartition()].a); return this; }; Giai202.prototype.getAssetReference = function () { return _super.prototype.getSegment.call(this, Giai202.PARTITIONS[this.getPartition()].b); }; Giai202.prototype.setAssetReference = function (value) { _super.prototype.setSegment.call(this, value, Giai202.PARTITIONS[this.getPartition()].b); return this; }; Giai202.EPC_HEADER = 0x34; Giai202.TOTAL_BITS = 202; Giai202.PARTITION_OFFSET = 11; Giai202.PARTITION_END = 14; Giai202.TAG_URI_TEMPLATE = function (filter, company, asset) { return "urn:epc:tag:giai-202:".concat(filter, ".").concat(company, ".").concat(asset); }; // F.C.A (Filter, Company, Asset) Giai202.PID_URI_TEMPLATE = function (company, asset) { return "urn:epc:id:giai:".concat(company, ".").concat(asset); }; // C.A (Company, Asset) // Partition table columns: Company prefix, Asset Type Giai202.PARTITIONS = [new Partition(Giai202.PARTITION_END, 40, 12, 148, 13), new Partition(Giai202.PARTITION_END, 37, 11, 151, 14), new Partition(Giai202.PARTITION_END, 34, 10, 154, 15), new Partition(Giai202.PARTITION_END, 30, 9, 158, 16), new Partition(Giai202.PARTITION_END, 27, 8, 161, 17), new Partition(Giai202.PARTITION_END, 24, 7, 164, 18), new Partition(Giai202.PARTITION_END, 20, 6, 168, 19)]; // 6 20 06 168 19 return Giai202; }(Epc)); module.exports = { Giai202: Giai202 };