UNPKG

epc-tds-ts

Version:

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

121 lines (120 loc) 5.52 kB
"use strict"; /** * 96-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 Giai96 = /** @class */ (function (_super) { __extends(Giai96, _super); function Giai96(hexEpc) { var _this = _super.call(this, Giai96.TOTAL_BITS) || this; if (hexEpc) { _super.prototype.setFromHexString.call(_this, hexEpc); } else { _super.prototype.set.call(_this, Giai96.EPC_HEADER, Epc.EPC_HEADER_OFFSET, Epc.EPC_HEADER_END); } return _this; } Giai96.prototype.clone = function () { return new Giai96().setFromBitArray(this); }; Giai96.prototype.getType = function () { return Type.GIAI96; }; Giai96.prototype.toTagURI = function () { var partition = Giai96.PARTITIONS[this.getPartition()]; return Giai96.TAG_URI_TEMPLATE(this.getFilter(), this.getSegmentString(partition.a), this.getSegment(partition.b)); }; Giai96.prototype.toIdURI = function () { var partition = Giai96.PARTITIONS[this.getPartition()]; return Giai96.PID_URI_TEMPLATE(this.getSegmentString(partition.a), this.getSegment(partition.b)); }; Giai96.prototype.toBarcode = function () { return this.getGiai(); }; Giai96.prototype.getTotalBits = function () { return Giai96.TOTAL_BITS; }; Giai96.prototype.getHeader = function () { return Giai96.EPC_HEADER; }; Giai96.prototype.getPartition = function () { return _super.prototype.get.call(this, Giai96.PARTITION_OFFSET, Giai96.PARTITION_END); }; Giai96.prototype.setPartition = function (value) { if (value < 0 || value >= Giai96.PARTITIONS.length) { throw new Error("Value '".concat(value, "' out of range (min: 0, max: ").concat(Giai96.PARTITIONS.length - 1, ")")); } _super.prototype.set.call(this, value, Giai96.PARTITION_OFFSET, Giai96.PARTITION_END); return this; }; Giai96.prototype.getGiai = function () { var partition = Giai96.PARTITIONS[this.getPartition()]; var companyPrefix = _super.prototype.getSegmentString.call(this, partition.a); var asset = _super.prototype.getSegment.call(this, partition.b); return companyPrefix + asset; }; Giai96.prototype.setGiai = function (giai) { var partition = Giai96.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; }; Giai96.prototype.getCompanyPrefix = function () { return _super.prototype.getSegment.call(this, Giai96.PARTITIONS[this.getPartition()].a); }; Giai96.prototype.setCompanyPrefix = function (value) { _super.prototype.setSegment.call(this, value, Giai96.PARTITIONS[this.getPartition()].a); return this; }; Giai96.prototype.getAssetReference = function () { return _super.prototype.getSegment.call(this, Giai96.PARTITIONS[this.getPartition()].b); }; Giai96.prototype.setAssetReference = function (value) { _super.prototype.setSegment.call(this, value, Giai96.PARTITIONS[this.getPartition()].b); return this; }; Giai96.EPC_HEADER = 0x52; Giai96.TOTAL_BITS = 96; Giai96.PARTITION_OFFSET = 11; Giai96.PARTITION_END = 14; Giai96.TAG_URI_TEMPLATE = function (filter, company, asset) { return "urn:epc:tag:giai-96:".concat(filter, ".").concat(company, ".").concat(asset); }; // F.C.A (Filter, Company, Asset) Giai96.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 Giai96.PARTITIONS = [new Partition(Giai96.PARTITION_END, 40, 12, 42, 13), new Partition(Giai96.PARTITION_END, 37, 11, 45, 14), new Partition(Giai96.PARTITION_END, 34, 10, 48, 15), new Partition(Giai96.PARTITION_END, 30, 9, 52, 16), new Partition(Giai96.PARTITION_END, 27, 8, 55, 17), new Partition(Giai96.PARTITION_END, 24, 7, 58, 18), new Partition(Giai96.PARTITION_END, 20, 6, 62, 19)]; // 6 20 06 62 19 return Giai96; }(Epc)); module.exports = { Giai96: Giai96 };